void main(){ //CHAR letA[]="A"; //CHAR letB[]="B"; //CHAR letC[]="C"; //CHAR espera[]="teste"; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); glcd_init(ON); //inicializa o display glcd_fillScreen(0); //limpa display inteiro //glcd_text57(34, 55, letA, 1, 1); //glcd_rect(46,53,60,63,1,1); //glcd_text57(48, 55, letB, 1, 0); while(TRUE){ glcd_imagem(1); delay_ms(3000); glcd_fillScreen(0); //limpa display inteiro glcd_imagem(2); delay_ms(3000); glcd_fillScreen(0); //limpa display inteiro } }
int main(void) { m_clockdivide(0); setup_pins(); if ( RF_debug) {setupUSB();} setup_timer_1(); setup_timer_3(); m_bus_init(); m_rf_open(chan,RX_add,p_length); int timer_3_cnt = 0; //sei(); set_motors(0,0); while (1){ if (check(TIFR3,OCF3A)){ set(TIFR3, OCF3A); timer_3_cnt++; if ( timer_3_cnt % 10 ==0 ) { timer_3_cnt=0; m_green(TOGGLE); } if ( timer_3_cnt == 1000){ timer_3_cnt=0;} } if(new){ switch ( receive_buffer[11] ) { case Single_Joy: single_joystick(); break; case Double_Joy: double_joystick(); break; case Tank_Mode: tank_driving(); break; case Mario_Kart: Mario_Drive(); break; default : set_motors(0,0); m_green(2); } if(RF_debug){ debug_rf(); } } } }
//============================================================================= void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0xFF);//7F set_tris_b(0xFF); //FF set_tris_c(0x94);//94 set_tris_d(0xFF); //02 set_tris_e(0xF0); //f0 set_tris_f(0xFF);//ff set_tris_g(0xFC); //04 output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); }
int main(void) { m_disableJTAG(); m_clockdivide(2); setup_pins(); if (debug_fire|| RF_debug) {setupUSB();} setup_timer_1(); setup_timer_3(); m_bus_init(); m_rf_open(chan,RX_add,p_length); int timer_3_cnt = 0; //sei(); set_motors(0,0); while (1){ if (check(TIFR3,OCF3A)){ set(TIFR3, OCF3A); timer_3_cnt++; if(fired){ since_fired++; if (debug_fire){ m_usb_tx_string(" its been\t"); m_usb_tx_int(since_fired); m_usb_tx_string(" milisec\n\r"); } } if (since_fired>10){ clear(PORTF,5); since_fired=0; fired = false; if (debug_fire){m_usb_tx_string(" its been 100 sec\n\r");} } if ( fire && check(PINB,3)){ fire=false; fired=true; since_fired=0; if (debug_fire){m_usb_tx_string(" portb 3 is high\n\r");} } // m_rf_open(chan,RX_add,p_length); m_green(TOGGLE); m_rf_init(); if ( timer_3_cnt == 10){ m_red(2); timer_3_cnt=0; m_rf_open(chan,RX_add,p_length); } } if(new){ turretDrive(); if(RF_debug){ debug_rf(); } if ((receive_buffer[0] == 1 || receive_buffer[1]==1) && !fire){FIRE();} } //TODO fill in timer code for the firing mechanism } }
/*======================= configuracon de dispositivos =======================*/ void setup_devices(){ //int myerror = 0; /*========================= configuracion del USB =========================*/ myerror = COM_init(); /*========================= configuracion del MMA7455 =====================*/ //myerror += MEMORIA_init_hw(); //myerror += MEMORIA_init(); /*========================= conversor analogo/digital =====================*/ // myerror = AD_init_adc(); /*========================= modulo CPP ====================================*/ //myerror = CP_init_ccp(); /*========================= configuracion del Reloj Digital ===============*/ //ds1307_init(DS1307_OUT_ON_DISABLED_HIHG | DS1307_OUT_ENABLED | DS1307_OUT_1_HZ); //ds1307_set_date_time(0x0d, 0x01, 0x0d, 0x00, 0x0a, 0x2a, 0x00); /*-------------------------------------------------------------------------*/ setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); #ifndef CAPTURA_FRECUENCIA_H setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_ccp1(CCP_OFF); #endif /*-------------------------------------------------------------------------*/ /*===================para los indicadores========================*/ set_tris_e(0x00); set_tris_b(0x00); set_tris_c(0x80); //configuracion para el modulo de memoria set_tris_d(0x48); output_bit(INDICADOR_USB, 0); output_bit(INDICADOR_AMARILLO, 1); //////////////////////////////// output_low(SPI_SCL); output_high(SPI_SS); output_low(SPI_MOSI); output_high(SPI_MISO); //////////////////////////////// //delay_ms(3000); /*===============================================================*/ return; }
void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_low_volt_detect(FALSE); //Setup_Oscillator parameter not selected from Intr Oscillotar Config tab //intitSerie(31); set_tris_a(0b00101111); set_tris_c(0b11111101); Set_tris_D(0b11100000); // port D : Led lectureTrame(); while(true){ if(truc=='c'){ clignotement(); } if(truc=='j'){ johnson(); } if(truc=='t'){ compteur(); } if(truc=='h'){ chenillard(); } } }
void main() { setup_timer_3 (T3_DISABLED|T3_DIV_BY_1); usb_init (); lcd_init (); lcd_putc ('\f'); delay_ms (1); while (TRUE) { lcd_refresh (); usb_task (); if (usb_enumerated ()) { if (usb_kbhit (1)) rxdata_len = usb_get_packet (1, rxdata, sizeof (rxdata)); } delay_ms (100); } }
void setup_peripherals() { setup_adc( ADC_CLOCK_INTERNAL ); setup_adc_ports( sAN0 | sAN9 ); set_adc_channel(0); setup_timer_0(T0_INTERNAL|T0_DIV_64); setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_timer_3(T3_DISABLED | T3_DIV_BY_1); setup_timer_4(T4_DISABLED,0,1); setup_timer_5(T5_DISABLED | T5_DIV_BY_1); setup_timer_6(T6_DISABLED,0,1); setup_wdt(WDT_OFF); }
void gen_setup(void){ usb_conn_test = Matlab_pos_tracking || go_to_location_test || debug_com || debug_goto || debug_find_puck; if (usb_conn_test ){ m_usb_init(); m_green(ON); while (!m_usb_isconnected()); m_green(OFF); } m_bus_init(); m_wii_open(); // m_port_init(PORT_ADD); setup_pins(); setup_puckfinding(); //Puck Finding Intialization setup_timer_1(); setup_timer_3(); setup_ADC(); }
//------------------------------------------------------------------------------ void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0x00); set_tris_b(0x24); set_tris_c(0x80); set_tris_d(0x00); set_tris_e(0x15); set_tris_f(0x58); set_tris_g(0x10); output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); // RF Modul and PA/LNA activation IOpin.modulepower=0; IOpin.moduleCTX=1; IOpin.moduleCPS=0; IOpin.modulePWRUP=1; }
void main() { int8 val; char car; // Initialization delay_ms(400); disable_interrupts(global); disable_interrupts(int_timer1); disable_interrupts(int_timer2); disable_interrupts(int_ext); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_spi(FALSE); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); setup_timer_2(T2_DIV_BY_1,2,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(False); delay_ms(400); while(1) { val = input(PIN_B0); if (val == 0) { output_a(0); } else if (val == 1) { output_a(255); } } }
//------------------------------------------------------------------------------ void main(){ int i; setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); disable_interrupts(INT_TIMER0); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF); output_low(PIN_C5); while(TRUE){ if(f_process){ f_process=0; output_toggle(PIN_C5); disable_interrupts(INT_RDA); printf("\n\r"); for(i=0;i<(cont-2);i++){ printf("vector[%u]=%c\n\r",i,p[i]); //muestro los datos recibidos } procesar_guardar(); cont=0; printf("Fin programacion\n\r"); enable_interrupts(INT_RDA); } } }
void main () { setup_timer_3 (T3_DISABLED|T3_DIV_BY_1); pwm_init (0); pwm_duty (0, 50); usb_init (); lcd_init (); lcd_putc ('\f'); delay_ms (1); lcd_refresh (); while (TRUE) { usb_task (); if (usb_enumerated ()) { if (usb_kbhit (1)) { rx_msg_len = usb_get_packet (1, &rx_msg, sizeof (rx_msg)); process_usb_data (); } } lcd_refresh (); delay_ms (100); } }
int main(void) { m_clockdivide(0); m_bus_init(); setup_timer_3(); m_rf_open(chan,TX_add,p_length); setup_pins(); if (debug_ADC){ setupUSB();} long VLeftSum=0; long HLeftSum=0; long VRightSum=0; long HRightSum=0; // int VLeftSum=0; // int HLeftSum=0; // int VRightSum=0; // int HRightSum=0; int cnt_RB = 0; int cnt_LB = 0; ///////////////////////////////////////////////////////////////////////////////// // // give me a half second to go from switching on the m2 to holding the config buttons. // ////////////////////////////////////////////////////////////////////////////////// m_green(1); int timer_3_cnt=0; int Calibration = 50; for (timer_3_cnt=0 ; timer_3_cnt< Calibration ; ){ if(check(TIFR3,OCF3A)){ ///// timer 3 runs at 100Hz set(TIFR3,OCF3A ); timer_3_cnt++; } } m_red(ON); for (timer_3_cnt=0 ; timer_3_cnt<Calibration ; ){ if(check(TIFR3,OCF3A)){ ///// timer 3 runs at 100Hz set(TIFR3,OCF3A ); timer_3_cnt++; update_ADC(0,0,0,0); check_buttons(); if (send_buffer[1]==1){ cnt_RB++ ;} if (send_buffer[0]==1){ cnt_LB++ ;} VLeftSum += *(int*)(&send_buffer[2]); HLeftSum += *(int*)(&send_buffer[6]); VRightSum += *(int*)(&send_buffer[4]); HRightSum += *(int*)(&send_buffer[8]); // if (debug_ADC){while(!m_usb_rx_available()); m_usb_rx_flush();} if (debug_ADC){debug_ADC_sums( timer_3_cnt, VRightSum, VLeftSum, HLeftSum, HRightSum );} } } // if (debug_ADC){while(!m_usb_rx_available()); m_usb_rx_flush();} int VLeftOffset = (int)(VLeftSum/Calibration); int HLeftOffset = (int)(HLeftSum/Calibration); int VRightOffset= (int)(VRightSum/Calibration); int HRightOffset= (int)(HRightSum/Calibration); int VLeftOffset = 512;//(int)(VLeftSum/Calibration); int HLeftOffset = 512;//(int)(HLeftSum/Calibration); int VRightOffset= 512;//(int)(VRightSum/Calibration); int HRightOffset= 512;//(int)(HRightSum/Calibration); bool L_bump = ( cnt_LB > Calibration/2 ); bool R_bump = ( cnt_RB > Calibration/2 ); if (debug_ADC){while(!m_usb_rx_available()); m_usb_rx_flush();} if (debug_ADC){debug_ADC_vals( Calibration, VRightSum, VLeftSum, HLeftSum, HRightSum );} m_green(0); m_red(OFF); set_drive_mode( L_bump , R_bump ); while (1){ check_buttons(); update_ADC( VLeftOffset,HLeftOffset,VRightOffset,HRightOffset ); TX_comm(); if (debug_ADC){deal_with_new();} } }
/************************************************************************ * Main Program ***** Programa Principal * ************************************************************************/ void main() { setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_timer_2(T2_DIV_BY_16,0xFF,16); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_adc( ADC_OFF ); enable_interrupts(INT_TIMER1); enable_interrupts(INT_TIMER2); enable_interrupts(INT_RDA); enable_interrupts(INT_EXT1); enable_interrupts(global); str_init(print_date); str_init(print_time); set_timer1(0); init_ext_eeprom(); ds1307_init(); glcd_init(ON); readconfig(); draw_sect(); while (1) { if (firstrun==255) { glcd_fillscreen(OFF); glcd_loadscreen(); glcd_showlogo(); delay_ms(1500); menu_mainmenu(); firstrun = 0; write_eeprom(0x00, firstrun); } if (config==1) { menu_mainmenu(); if(UniTemp[0]==0x43) { write_eeprom(0x01, 1); } else if(UniTemp[0]==0x46) { write_eeprom(0x01, 2); } if(UniPres[0]==0x6D) { write_eeprom(0x02, 1); } else if(UniPres[0]==0x50) { write_eeprom(0x02, 2); } if(UniVel[0]==0x4E) { write_eeprom(0x03, 1); } else if(UniVel[0]==0x6B) { write_eeprom(0x03, 2); } else if(UniVel[0]==0x6D) { write_eeprom(0x03, 3); } update_readings(); button = !PRESSED; config=0; } if (uh>40) { twop[0]=":"; guion[0]="-"; spa[0]=" "; str_init(print_time); str_init(print_date); ds1307_get_time(aux_hr,aux_min,aux_sec); ds1307_get_date(aux_day, aux_month, aux_year, aux_dow); itoa(aux_day,10,print_day); itoa(aux_month,10,print_month); itoa(aux_year,10,print_year); switch(aux_dow) { case 0: { print_dow[0] = "D"; break; } case 1: { print_dow[0] = "L"; break; } case 2: { print_dow[0] = "M"; break; } case 3: { print_dow[0] = "I"; break; } case 4: { print_dow[0] = "J"; break; } case 5: { print_dow[0] = "V"; break; } case 6: { print_dow[0] = "S"; break; } } sprintf(print_date,"%s:%s-%s-%s",print_dow,print_day,print_month,print_year); //strcat(print_date,print_dow); //strcat(print_date,twop); //strcat(print_date,print_day); //strcat(print_date,guion); // strcat(print_date,print_month); //strcat(print_date,guion); //strcat(print_date,print_year); if(aop[0]==0x50) { aux_hr=aux_hr-20; } itoa(aux_hr,10,print_hr); itoa(aux_min,10,print_min); strcat(print_time,print_hr); strcat(print_time,twop); strcat(print_time,print_min); if ((aop[0]==0x41)||(aop[0]==0x50)) { strcat(print_time,twop); strcat(print_time,aop); } rcv_td=1; uh=0; } poll_ok(); lightbuttons(); while(bkbhit) { auxi = bgetc(); switch (auxi) { case 0x54: //T { type=1; str_init(string); break; } case 0x50: //P { type=2; str_init(string); break; } case 0x48: //H { type=3; str_init(string); break; } case 0x41: //A { type=4; str_init(string); break; } case 0x57: //W { type=5; str_init(string); break; } case 0x52: //R { type=6; str_init(string); break; } case 0x44: //D { type=7; str_init(string); break; } case 0x4C: //L { type=8; str_init(string); break; } case 0x56: //V { type=9; str_init(string); break; } case 0x42: //B { type=10; str_init(string); break; } } switch (type) { case 1: //Temperatura { if ((auxi!=0x0D)&&(auxi!=0x54)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(tprint); tt = atol(string); if(UniTemp[0]==0x46) { tt = ((tt*9)/5)+320; } strcat(temp_buffer_eeprom,string); eep+=3; sprintf(ttt,"%3.1w",tt); strcat(tprint,ttt); strcat(tprint,UniTemp); strcpy(t2_print,tprint); rcv_t=1; } break; } case 2: //Presion { if ((auxi!=0x0D)&&(auxi!=0x50)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(pprint); pp = atoi32(string); if(UniPres[0]==0x50) { pp = pp*10; sprintf(ppp,"%6.0w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } else { sprintf(ppp,"%4.1w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } rcv_p=1; } break; } case 3: //Humedad { if ((auxi!=0x0D)&&(auxi!=0x48)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(hprint); hh = atol(string); sprintf(hhh,"%2.1w",hh); strcat(hprint,hhh); strcat(hprint,uni); rcv_h=1; } break; } case 4: //Altitud { if ((auxi!=0x0D)&&(auxi!=0x41)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="m"; str_init(aprint); aa = atol(string); sprintf(aaa,"%5.1w",aa); strcat(aprint,aaa); strcat(aprint,uni); rcv_a=1; } break; } case 5: //Clima { if ((auxi!=0x0D)&&(auxi!=0x57)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ww = atoi(string); rcv_w=1; } break; } case 6: //Probabilidad de lluvia { if ((auxi!=0x0D)&&(auxi!=0x52)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(pdlprint); ppdl = atol(string); sprintf(pppdl,"%2.0w",ppdl); strcat(pdlprint,pppdl); strcat(pdlprint,uni); rcv_pdl=1; } break; } case 7: //Direccion del viento { if ((auxi!=0x0D)&&(auxi!=0x44)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(dprint); dd = atol(string); switch(dd) { case 0: { dprint[0]="N"; dprint[1]="\0"; break; } case 1: { dprint[0]="N"; dprint[1]="E"; dprint[2]="\0"; break; } case 2: { dprint[0]="E"; dprint[1]="\0"; break; } case 3: { dprint[0]="S"; dprint[1]="E"; dprint[2]="\0"; break; } case 4: { dprint[0]="S"; dprint[1]="\0"; break; } case 5: { dprint[0]="S"; dprint[1]="O"; dprint[2]="\0"; break; } case 6: { dprint[0]="O"; dprint[1]="\0"; break; } case 7: { dprint[0]="N"; dprint[1]="O"; dprint[2]="\0"; break; } } rcv_d=1; } break; } case 8: //Intensidad de luz { if ((auxi!=0x0D)&&(auxi!=0x4C)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ll = atoi(string); ll = ll*6.3+67; rcv_l=1; } break; } case 9: //Velocidad del viento { if ((auxi!=0x0D)&&(auxi!=0x56)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(vprint); vv = atoi32(string); if(UniVel[0]==0x6D) { vv = vv * 0.5144; } else if(UniVel[0]==0x6B) { vv = vv * 1.852; } else { } sprintf(vvv,"%4.1w",vv); strcat(vprint,vvv); strcat(vprint,UniVel); rcv_v=1; } break; } case 10: //Bat Status { if ((auxi!=0x0D)&&(auxi!=0x42)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; bat1_st = atoi(string); rcv_bat1_st=1; } break; } } if(eep>=9) { update_eeprom(); eep=0; } update_readings(); glcd_update(); //END KBHIT } glcd_update(); //ENDWHILE } //ENDMAIN }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
void main() { enable_interrupts(INT_RDA); enable_interrupts(INT_EXT1); enable_interrupts(global); setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_adc( ADC_OFF ); //setup_adc_ports(NO_ANALOGS|VREF_VREF); // setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_PLL_OFF); glcd_init(ON); int8 axt,axp,axv; axt = read_eeprom(0x01); axp = read_eeprom(0x02); axv = read_eeprom(0x03); if(axt==1) { UniTemp[0]="C"; } if(axt==2) { UniTemp[0]="F"; } if(axp==1) { UniPres[0]="Pa"; } if(axp==2) { UniPres[0]="mBa"; } if(axv==1) { UniVel[0]="m/s"; } if(axv==2) { UniVel[0]="km/h"; } if(axv==3) { UniVel[0]="Nud"; } int16 auxi; int8 type,z; int8 string[10]; int16 tt; int32 pp; char tprint [15]; char pprint [15]; char ttt[10]; char ppp[10]; char temp[] = "T:"; char pres[] = "P:"; for (z=0;z<15;z++) { tprint[z]=0; pprint[z]=0; } //firstrun = read_eeprom(0x00); draw_sect(); while (1) { if (firstrun==71) { glcd_loadscreen(); glcd_showlogo(); delay_ms(1500); menu_mainmenu(); firstrun = 0; write_eeprom(0x00, firstrun); } if (config==1) { menu_mainmenu(); if(UniTemp[1]=="C") { write_eeprom(0x01, 1); } else if(UniTemp[1]=="F") { write_eeprom(0x01, 2); } if(UniPres[1]=="P") { write_eeprom(0x02, 1); } else if(UniPres[1]=="m") { write_eeprom(0x02, 2); } if(UniVel[1]=="m") { write_eeprom(0x03, 1); } else if(UniVel[1]=="k") { write_eeprom(0x03, 2); } else if(UniVel[1]=="N") { write_eeprom(0x03, 3); } pressed=0; config=0; } if (try==1) { try=0; output_toggle(PIN_C2); } while(bkbhit) { auxi = bgetc(); if (auxi==0x54) { type=1; for(i=0;i<15;i++) { string[i]=0x00; } i = 0; } if (auxi==0x50) { type=2; for(i=0;i<15;i++) { string[i]=0x00; } i = 0; } if (auxi!=0x0D) { } if (type==1) //Temperatura { if ((auxi!=0x0D)&&(auxi!=0x54)) { string[i] = auxi; i++; } if (auxi==0x0D) { str_init(tprint); tt = atol(string); sprintf(ttt,"%3.1w",tt); strcat(tprint,temp); strcat(tprint,ttt); strcat(tprint,UniTemp); draw_sect(); glcd_text_sec(1, 1, tprint, OFF); glcd_update(); } } if (type==2) //Presion { if ((auxi!=0x0D)&&(auxi!=0x50)) { string[i] = auxi; i++; } if (auxi==0x0D) { str_init(pprint); pp = atoi32(string); sprintf(ppp,"%3.1w",pp); strcat(pprint,pres); strcat(pprint,ppp); strcat(pprint,UniPres); draw_sect(); glcd_text_sec(1, 2, pprint, OFF); glcd_update(); } } glcd_update(); //END KBHIT } glcd_update(); //ENDWHILE } //ENDMAIN }
void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_CLOCK_DIV_2); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); //Setup_Oscillator parameter not selected from Intr Oscillator Config tab set_tris_a(0b00000011); set_tris_b(0b00000000); set_tris_c(0b10110011); set_tris_d(0b11110000); set_tris_e(0b00000100); while(1) { // waits for B1 to go high while ( !input(PIN_B1) ) {} //PE- playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //tit playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //pa- playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //pa playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //Noe- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //el playSound(NOTE_DO4,TEMPS_BLANCHE); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //Quand playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tu playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //Des- playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //cen- playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //dras playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //du playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //ciel playSound(NOTE_MI4,TEMPS_BLANCHE); playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //A- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //vec playSound(NOTE_DO4,TEMPS_NOIRE); playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tes playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //jou- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //ets playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //par playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //mi- playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //liers playSound(NOTE_SOL3,TEMPS_BLANCHE); playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //N'ou- playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //blie playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //pas playSound(NOTE_DO4,TEMPS_BLANCHE); delay_us(WAIT); //mon playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //pet- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tit playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //pa- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //nier playSound(NOTE_RE4,TEMPS_BLANCHE); playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //Mais playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //a- playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //vant playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //de playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //par- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //tir playSound(NOTE_DO4,TEMPS_BLANCHE); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //il playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //fau- playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //dra playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //bien playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //te playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //cou- playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //vrir playSound(NOTE_MI4,TEMPS_BLANCHE); playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //De- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //hors playSound(NOTE_DO4,TEMPS_NOIRE); playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //il playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //fait playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //dé- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //jà playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //bien playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //froid playSound(NOTE_SOL3,TEMPS_BLANCHE); playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //C'est playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //un playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //peu playSound(NOTE_DO4,TEMPS_BLANCHE); delay_us(WAIT); //a playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //cau- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //se playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //de playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //Moi playSound(NOTE_DO4,TEMPS_RONDE); delay_us(WAIT); //-------------------------------- //Il playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //me playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //tar- playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //de playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //tant playSound(NOTE_LA3,TEMPS_NOIRE); delay_us(WAIT); //que playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //le playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //jour playSound(NOTE_DO4,TEMPS_NOIRE); playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //se playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //lè- playSound(NOTE_LA3,TEMPS_NOIRE); delay_us(WAIT); //ve playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //Pour playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //voir playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //si playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tu playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //m'as playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //ap- playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //por- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //té playSound(NOTE_RE4,TEMPS_RONDE); delay_us(WAIT); //-------------------------------- //tous playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //les playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //beaux playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //jou- playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //joux playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //que playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //je playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //vois playSound(NOTE_FA4,TEMPS_NOIRE); playSound(NOTE_FA4,TEMPS_CROCHE); delay_us(WAIT); //en playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //re- playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //ve playSound(NOTE_SI3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //et playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //que playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //je playSound(NOTE_MI4,TEMPS_CROCHE); delay_us(WAIT); //t'ai playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //com- playSound(NOTE_FA4,TEMPS_CROCHE); delay_us(WAIT); //man- playSound(NOTE_FA4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //de playSound(NOTE_SOL4,TEMPS_BLANCHE); playSound(NOTE_SOL4,TEMPS_BLANCHE); delay_us(WAIT); //PE- playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //tit playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //pa- playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //pa playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //Noe- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //el playSound(NOTE_DO4,TEMPS_BLANCHE); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //Quand playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tu playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //Des- playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //cen- playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //dras playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //du playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //ciel playSound(NOTE_MI4,TEMPS_BLANCHE); playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //A- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //vec playSound(NOTE_DO4,TEMPS_NOIRE); playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tes playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //jou- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //ets playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //par playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //mi- playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //liers playSound(NOTE_SOL3,TEMPS_BLANCHE); playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //N'ou- playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //blie playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //pas playSound(NOTE_DO4,TEMPS_BLANCHE); delay_us(WAIT); //mon playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //pet- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //tit playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //pa- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //nier playSound(NOTE_RE4,TEMPS_BLANCHE); playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //Mais playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //a- playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //vant playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //de playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //par- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //tir playSound(NOTE_DO4,TEMPS_BLANCHE); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); //il playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //fau- playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //dra playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //bien playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //te playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //cou- playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //vrir playSound(NOTE_MI4,TEMPS_BLANCHE); playSound(NOTE_MI4,TEMPS_NOIRE); delay_us(WAIT); //De- playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- //hors playSound(NOTE_DO4,TEMPS_NOIRE); playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //il playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //fait playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //dé- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //jà playSound(NOTE_SI3,TEMPS_CROCHE); delay_us(WAIT); //bien playSound(NOTE_LA3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //froid playSound(NOTE_SOL3,TEMPS_BLANCHE); playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //C'est playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //un playSound(NOTE_SOL3,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //peu playSound(NOTE_DO4,TEMPS_BLANCHE); delay_us(WAIT); //a playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //cau- playSound(NOTE_DO4,TEMPS_CROCHE); delay_us(WAIT); //se playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //de playSound(NOTE_RE4,TEMPS_CROCHE); delay_us(WAIT); //-------------------------------- //Moi playSound(NOTE_DO4,TEMPS_BLANCHE); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); playSound(NOTE_SOL3,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- playSound(NOTE_LA3,TEMPS_NOIRE); delay_us(WAIT); playSound(NOTE_DO4,TEMPS_NOIRE); delay_us(WAIT); playSound(NOTE_RE4,TEMPS_NOIRE); delay_us(WAIT); playSound(NOTE_FA4,TEMPS_NOIRE); delay_us(WAIT); //-------------------------------- playSound(NOTE_SOL4,TEMPS_RONDE); delay_us(WAIT); } }
void main(void) { setup_adc(ADC_CLOCK_DIV_8); setup_adc_ports(sAN0); set_adc_channel(0); setup_wdt(WDT_ON); setup_timer_1(T1_EXTERNAL | T1_ENABLE_SOSC); // Set up the timekeeping timer setup_timer_2(T2_DIV_BY_1, 0x28, 1); // Set up SPI clock timer setup_timer_3(T3_INTERNAL | T3_DIV_BY_8); // Set up scheduler timer output_low(ALARM_PIN); enable_interrupts(INT_RDA); // Enable serial interrupt enable_interrupts(INT_TIMER1); // Enable timekeeping timer interrupt enable_interrupts(INT_TIMER3); // Enable scheduler timer interrupt enable_interrupts(GLOBAL); // Enable interrupts globally if(read_eeprom(EEPROM_RESET)==0x42) { time.hours=read_eeprom(EEPROM_HOURS); time.minutes=read_eeprom(EEPROM_MINUTES); time.seconds=read_eeprom(EEPROM_SECONDS); #IFDEF DRINKING_GAME shot_count=read_eeprom(EEPROM_SHOTS); #ENDIF write_eeprom(EEPROM_RESET,0x00); } else { #IFDEF DRINKING_GAME time.seconds=0; #ELSE time.seconds=(((uint8_t)timestr[6]-48)*10)+((uint8_t)timestr[7]-46); #ENDIF time.minutes=(((uint8_t)timestr[3]-48)*10)+((uint8_t)timestr[4]-48); time.hours=(((uint8_t)timestr[0]-48)*10)+((uint8_t)timestr[1]-48); // Parse timestr to time struct } memset(command_buffer, 0, sizeof(command_buffer)); memset(command, 0, sizeof(command)); restart_wdt(); init_display(); fprintf(COM1, "HELLO!\r\n"); // Say hello! set_timer1(-32768); // Begin timekeeping t10ms=0; t100ms=0; t100ms0=0; t1s0=0; set_timer3(-20000); // Reset and set scheduler while(TRUE) { restart_wdt(); if(t10ms0==1) { t10ms0=0; if(command_waiting) process_command(); } if(t100ms0==1) { t100ms0=0; update_brightness(); if((alarm)&&(alarm_count<5)) { if(alarm_count==0) output_high(ALARM_PIN); alarm_count++; } else { output_low(ALARM_PIN); alarm=FALSE; alarm_count=0; } } if(t100ms1==5) { t100ms1=0; } if(t1s0==1) { t1s0=0; #IFNDEF DRINKING_GAME toggle_colon(); #ENDIF update_display(); if(manual_alarm==FALSE) wallclock_alarm(); } } }
void main() { int1 flag = 0; porta = 0;//all ports are zero portb = 0; portc = 0; setup_adc_ports(no_analogs|vss_vdd); //digital functions selected setup_adc(adc_off); //internal rc oscillator disabled for adc setup_wdt(wdt_off); //watch dog timer disabled setup_timer_0(rtcc_off); //all timers disabled setup_timer_1(t1_disabled); setup_timer_2(t2_disabled,0,1); setup_timer_3(t3_disabled|t3_div_by_1); setup_comparator(nc_nc_nc_nc); //comparators disabled setup_vref(false); //no reference voltage in ra2 setup_ccp1(ccp_off); //disable ccp1 setup_ccp2(ccp_off); //disable ccp2 enable_interrupts(int_rda); //uart rx interruption enabled enable_interrupts(global); //global interruptions enabled usb_cdc_init(); usb_init(); //initialize hardware usb and wait for PC conection set_tris_a(0b00111111); set_tris_b(0b11111011);//rb2 output mclr dspic port_b_pullups(false); set_tris_c(0b10111111); stateDspic = running; counterReset = 0; delay_ms(500);//wait for supply stabilization while(true) { usb_task(); manage_conection(); if (usb_cdc_kbhit()) { data_rx_usb=usb_cdc_getc();//read buffer and save in data_rx printf("%c",data_rx_usb);//send through uart if (data_rx_usb == rstKeyword[0]) { if (counterReset == 0) counterReset++; } else if (data_rx_usb == rstKeyword[1]) { if (counterReset == 1) counterReset++; else counterReset = 0; } else if (data_rx_usb == rstKeyword[2]) { if (counterReset == 2) counterReset++; else counterReset = 0; } else if (data_rx_usb == rstKeyword[3]) { if (counterReset == 3) counterReset++; else counterReset = 0; } else if (data_rx_usb == rstKeyword[4] && counterReset == 4)//here, all requirements were met { counterReset = 0; flag = 0; //reset flag for(i = 0; i < 10000; i++) //wait for the next byte { if (usb_cdc_kbhit()) //if a new byte is received { data_rx_usb = usb_cdc_getc();//read buffer and save in data_rx printf("%c",data_rx_usb);//send through uart flag = 0; break; } flag = 1; } if (flag == 1) //apply reset when no characters were received { stateDspic = stop; delay_ms(50); stateDspic = running; } } else counterReset = 0; } } }
void main() { struct rx_stat rxstat; int32 rx_id; int in_data[8]; int rx_len; int out_data[8]; int16 tmp; int32 tx_id; int1 tx_rtr=0; int1 tx_ext=0; int tx_len=8; int tx_pri=3; // bitmap, expanded to 8 bit (needed?) int8 sequence[MAX_CHANNELS]; int32 val; int i; for (i = 0; i < MAX_CHANNELS; i++) sequence[i] = MAX_CHANNELS; // resource initialization. setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); setup_spi(FALSE); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); //setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //set_timer1(16000); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); _board_ID = read_eeprom(0); can_init(); adc_init(); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); while(TRUE) { if (can_kbhit() || _wait) // wait for a message on the CAN bus { // handles timer message if (_wait) { _wait = 0; for (i = 0; i <= MAX_CHANNELS-3; i+=3) { if (sequence[i] < MAX_CHANNELS) tmp = read_analog(i); else tmp = 0; out_data[1] = (int8)(tmp); out_data[2] = (int8)(tmp>>8); if (sequence[i+1] < MAX_CHANNELS) tmp = read_analog(i+1); else tmp = 0; out_data[3] = (int8)(tmp); out_data[4] = (int8)(tmp>>8); if (sequence[i+2] < MAX_CHANNELS) tmp = read_analog(i+2); else tmp = 0; out_data[5] = (int8)(tmp); out_data[6] = (int8)(tmp>>8); while (!can_tbe()) ; tx_id = ID_BASE; tx_id |= ((_board_ID) << 4); //tx_id |= ((0 & 0x00f0) >> 4); out_data[0] = 0x30+i; tx_len = 7; can_putd(tx_id, out_data, tx_len, tx_pri, tx_ext, tx_rtr); } // last message. if (sequence[30] < MAX_CHANNELS) tmp = read_analog(30); else tmp = 0; out_data[1] = (int8)(tmp); out_data[2] = (int8)(tmp>>8); if (sequence[31] < MAX_CHANNELS) tmp = read_analog(31); else tmp = 0; out_data[3] = (int8)(tmp); out_data[4] = (int8)(tmp>>8); while (!can_tbe()) ; tx_id = ID_BASE; tx_id |= ((_board_ID) << 4); //tx_id |= ((0 & 0x00f0) >> 4); out_data[0] = 0x30+30; tx_len = 5; can_putd(tx_id, out_data, tx_len, tx_pri, tx_ext, tx_rtr); } if (can_getd(rx_id, &in_data[0], rx_len, rxstat)) { // handles message for the analog channel if ((rx_len == 1) && ((rx_id & 0x700) == 0x200) && (in_data[0] < MAX_CHANNELS)) { tmp = read_analog(in_data[0]); out_data[1] = (int8)(tmp); out_data[2] = (int8)(tmp>>8); while (!can_tbe()) ; tx_id = ID_BASE; tx_id |= ((_board_ID) << 4); tx_id |= ((rx_id & 0x00f0) >> 4); out_data[0] = in_data[0]; tx_len = 3; // replies to message. can_putd(tx_id, out_data, tx_len, tx_pri, tx_ext, tx_rtr); } // handles message to prepare a sequence (32). else if ((rx_len == 5) && ((rx_id & 0x700) == 0x200) && (in_data[0] == MAX_CHANNELS)) { for (i = 0; i < MAX_CHANNELS; i++) sequence[i] = MAX_CHANNELS; // perhaps this is not needed. while (!can_tbe()) ; tx_id = ID_BASE; tx_id |= ((_board_ID) << 4); tx_id |= ((rx_id & 0x00f0) >> 4); out_data[0] = in_data[0]; tx_len = 1; setup_timer_1(T1_DISABLED); // replies to message. can_putd(tx_id, out_data, tx_len, tx_pri, tx_ext, tx_rtr); } // handles message to prepare a broadcast sequence (33). else if ((rx_len == 5) && ((rx_id & 0x700) == 0x200) && (in_data[0] == MAX_CHANNELS+1)) { for (i = 0; i < MAX_CHANNELS; i++) { val = *((int32 *)(&in_data[1])); if (val & 0x00000001) { sequence[MAX_CHANNELS-1-i] = MAX_CHANNELS-1-i; } else { sequence[MAX_CHANNELS-1-i] = MAX_CHANNELS; } val >>= 1; } // perhaps this is not needed. // LATER: check the driver. while (!can_tbe()) ; tx_id = ID_BASE; tx_id |= ((_board_ID) << 4); tx_id |= ((rx_id & 0x00f0) >> 4); out_data[0] = in_data[0]; tx_len = 1; val = *((int32 *)(&in_data[1])); if (val == 0) { setup_timer_1(T1_DISABLED); } else { setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); set_timer1(65536-5000); } // replies to message. can_putd(tx_id, out_data, tx_len, tx_pri, tx_ext, tx_rtr); } // handles CAN bus messages for the downloader else if ((rx_len == 1) && (((rx_id>>8) & 0x7)==7))
//***************************************************************************************** //***************************************************************************************** //P RO G R A M A P R I N C I P A L //***************************************************************************************** //***************************************************************************************** void main(){ float32* fltPtr; float32 varX,varY,varZ; float32 Xp,Yp; float32 fx,fy,fz; float incX; float incY; char x,y,z; char posicion; setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_spi2(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_timer_4(T4_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); set_tris_a(0x00); set_tris_b(0x00); set_tris_c(0xC0); set_tris_d(0x00); set_tris_e(0x00); DELAY_MS(200); output_b(0xFF); GLCD_init(1); DELAY_MS(500); output_b(0x00); //Setear propiedades de la grafica. graph.x1=0.0; graph.y1=0.0; graph.x2=127.0; graph.y2=63.0; graph.minX=-1.0; graph.maxX=1.0; graph.minY=-1.0; graph.maxY=1.0; graph.minViewX=-2.5; graph.maxViewX=2.5; graph.minViewY=-1.25; graph.maxViewY=1.25; printf("Hecho por Bruno Fascendini @ 2009 para uControl y Todopic\r\ncomo parte de proyecto calculadora cientifica con PIC del foro uControl\r\n"); printf("Parseador version: %s Evaluador version: %s\r\n",ParserVer,EvaluadorVer); //menú: printf("Ingrese la superficie a graficar: "); posicion=0; do{ EquIn[posicion]=getc(); if(posicion>0 && EquIn[posicion]==8) posicion--; else posicion++; //delete if delete key pressed... if(posicion==BUFFER_SIZE) break; }while(EquIn[posicion-1]!=13); EquIn[posicion]='\0'; printf("Ha pedido que se grafique la ecuacion: %s",EquIn); printf("Ingrese valor minimo de x: "); posicion=0; do{ temp[posicion]=getc(); if(posicion>0 && temp[posicion]==8) posicion--; else posicion++; //delete if delete key pressed... if(posicion==BUFFER_SIZE) break; }while(temp[posicion-1]!=13); temp[posicion]='\0'; graph.minX=atof(temp); printf("Ingrese valor maximo de x: "); posicion=0; do{ temp[posicion]=getc(); if(posicion>0 && temp[posicion]==8) posicion--; else posicion++; //delete if delete key pressed... if(posicion==BUFFER_SIZE) break; }while(temp[posicion-1]!=13); temp[posicion]='\0'; graph.maxX=atof(temp); printf("Ingrese valor minimo de y: "); posicion=0; do{ temp[posicion]=getc(); if(posicion>0 && temp[posicion]==8) posicion--; else posicion++; //delete if delete key pressed... if(posicion==BUFFER_SIZE) break; }while(temp[posicion-1]!=13); temp[posicion]='\0'; graph.minY=atof(temp); printf("Ingrese valor maximo de y: "); posicion=0; do{ temp[posicion]=getc(); if(posicion>0 && temp[posicion]==8) posicion--; else posicion++; //delete if delete key pressed... if(posicion==BUFFER_SIZE) break; }while(temp[posicion-1]!=13); temp[posicion]='\0'; graph.maxY=atof(temp); graph.minViewX=graph.minX; graph.maxViewX=graph.maxX; graph.minViewY=graph.minY; graph.maxViewY=graph.maxY; //Calculating centers... graph.centerX= (graph.x2-graph.x1)/2; graph.centerY= (graph.y2-graph.y1)/2; incX=(graph.maxX-graph.minX)/50; //set step cuantity for X axis incY=(graph.maxY-graph.minY)/50; //set step cuantity for Y axis printf("Graficando...\r\n"); ////////////////////////////////////////////////// //PROCESO.............. //comienzo del parseado de la ecuacion ingresada... ////////////////////////////////////////////////// strlwr(EquIn); //1) PASAR EQUACION A MINUSCULAS //printf("Cadena en minusculas: %s\r\n",EquIn); strCodificar(EquIn); // 2) REDUCIR ECUACION PARA OPTIMIZAR PROCESADO POSTERIOR printf("Cadena codificada: %s\r\n",EquIn); strPosFijar(EquIn,EquIn); // 3) Pasar a notación PostFija printf("Cadena en notacion postfija: %s\r\n",EquIn); //cut unuseful zones... //if(graph.minX<graph.minViewX) graph.minX=graph.minViewX; //if(graph.maxX>graph.maxViewX) graph.maxX=graph.maxViewX; //if(graph.minY<graph.minViewY) graph.minY=graph.minViewY; //if(graph.maxY>graph.maxViewY) graph.maxY=graph.maxViewY; /* //Ejes! varx=0.0; varz=0.0; for(vary=0.0;Xp>=0;vary+=0.4){ Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX; Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY; GLCD_pixel((int8)Xp,(int8)Yp,1); } vary=0.0; varz=0.0; for(varx=0.0;Xp<Radius+CentroX;varx+=0.4){ Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX; Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY; GLCD_pixel((int8)Xp,(int8)Yp,1); } varx=0.0; vary=0.0; for(varz=0.0;Yp>0;varz+=1.0){ Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX; Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY; GLCD_pixel((int8)Xp,(int8)Yp,1); } */ /* //2D: for(varX=graph.minX;varX<graph.maxX;varX+=0.1){ fltPtr=strEvaluar(EquIn,StackNum,&varX,NULL,NULL); printf("X: %f Y: %f\r\n",varX,*fltPtr); Xp=varX+graph.centerX; Yp=graph.centerY-(*fltPtr); //ensure that pixel belongs to actual graph section...else do not show it!(out of bounds) if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1); } printf("HECHO!\r\n"); while(1); */ //Proyeccion Isométrica... for(varY=graph.minY;varY<graph.maxY;varY+=incY){ for(varX=graph.minX;varX<graph.maxX;varX+=incX){ //indicate no error... errno=0; fltPtr=strEvaluar(EquIn,StackNum,&varX,&varY,NULL); //if errors during calculating...do not bother at all.. if(errno) continue; //calculate isometric proyection varZ = *fltPtr; Xp = RAIZ2SOBRE2 * (varX - varY); Yp = (RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)); //ensure that values are inside drawing zone... if(Xp>=graph.minViewX && Xp<=graph.maxViewX && Yp>=graph.minViewY && Yp<=graph.maxViewY){ //printf("X: %f Y: %f Z: %f\r\n",varX,varY,varZ); //now let´s ubicate them inside actual graphic bounds... Xp=(Xp-graph.minViewX)*(float32)(graph.x2-graph.x1)/(graph.maxViewX-graph.minViewX)+(float32)graph.x1; Yp=(float32)graph.y2-((Yp-graph.minViewY)*(float32)(graph.y2-graph.y1)/(graph.maxViewY-graph.minViewY))+(float32)graph.y1; //printf("XP: %f YP: %f\r\n",Xp,Yp); if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1); } } } printf("Proceso de graficacion finalizado.\r\n"); /* //polares for(varY=-PI/2;varY<PI/2;varY+=PI/63){ for(varX=-PI;varX<PI;varX+=2*PI/31){ fX=Radius*cos(varX)*cos(varY); fY=Radius*cos(varX)*sin(varY); fZ=Radius*sin(varX); Xp=Sqrt(2.0) / 2.0 * (fX - fY) * Distance + CentroX; Yp = (Sqrt(2.0 / 3.0) * fZ - (1.0 / Sqrt(6.0)) * (fX + fY)) * Distance + CentroY; GLCD_pixel((int8)Xp,(int8)Yp,1); //printf("Xp: %f Yp: %f\r\n",Xp,Yp); } } */ //printf("EL resultado de la ecuacion es: %9f\r\n",*fltPtr); while(1); }
//programa principal void main() { set_tris_A(0x00);/* 0000 0000 RA0 LED1 PIN 02 RA1 LED2 PIN 03 RA2 LED3 PIN 04 RA3 LED4 PIN 05 RA4 LED5 PIN 06 RA5 LED6 PIN 07 */ set_tris_B(0x00);/* (0000 0000) RB0 LED7 PIN 40 RB1 LED8 PIN 39 RB2 LED9 PIN 38 RB3 LED10 PIN 37 RB4 LED11 PIN 36 RB5 LED12 PIN 35 RB6 LED13 PIN 34 RB7 LED14 PIN 33 */ set_tris_C(0X00);/* RC0 ----- PIN 15 RC1 ----- PIN 16 RC2 ----- PIN 17 RC6 LED15 PIN 25 RC7 LED16 PIN 26 */ // Configuración de Leds 17 hasta 20 y Pulsadores 1 y 2 set_tris_D(0X00);/* RD0 SW01 PIN 19 --->Pulsador 1 RD1 SW02 PIN 20 --->Pulsador 2 RD2 ----- PIN 21 RD3 ----- PIN 22 RD4 LED17 PIN 27 RD5 LED18 PIN 28 RD6 LED19 PIN 29 RD7 LED20 PIN 30 */ set_tris_E(0x00);/* bits(**** 0000) RE0 ----- PIN 08 RE1 ----- PIN 09 RE2 ----- PIN 10 RE3 ----- PIN 01 */ //Habilitando y deshabilitando modulos... setup_timer_1(T1_disabled); setup_timer_2(T2_disabled,0,1); setup_timer_3(T3_disabled); setup_ccp1(CCP_OFF); setup_ADC(ADC_OFF); setup_VREF(FALSE);//no voltaje de referencia setup_COMPARATOR(NO_ANALOGS);// //limpie los puertos OUTPUT_A(0x00); OUTPUT_B(0x00); OUTPUT_C(0X00); OUTPUT_D(0X00); //limpiar registros, probar limpiar todos los registros en assembler con =0 //#ZERO_RAM limpiarRegistros(); /*condicional para lanzar secuencia cuando el pulsador esté presionado. */ output_float(SW01); output_float(SW02); while(TRUE) { if (input_state(SW01) == 1 && input_state(SW02) == 1) { secuencia1(); }else if (input_state(SW01) == 0 && input_state(SW02) == 1) { secuencia2(); }else if (input_state(SW01) == 1 && input_state(SW02) == 0) { secuencia4(); }else { } } //vuelva a inicio y vuelva y arranque reset_cpu(); }