void listenCAN() // Fonction assurant la réception des messages sur le CAN et l'envoi de ces derniers sur le RS232 { struct rx_stat rxStat; int32 rxId; int8 rxData[8]; int8 rxLen; int i; if(can_kbhit()) // Une donnée est présente dans le buffer de réception du CAN { if(can_getd(rxId,&rxData[0],rxLen,rxStat)) // on récupère le message { putc(255); // on envoie le message de début de trame putc(rxId); // on envoie l'ID for(i=0;i<rxLen;i++) { putc(rxData[i]); // on envoie les données si besoin } #ifdef TRACE_CAN tmp=ms+1000*sec; printf("\r\n [%Lu] - CAN_DEBUG - BUFF=%u - ID=%u - LEN=%u - OVF=%u", tmp,rxStat.buffer, rxId, rxLen, rxStat.err_ovfl); #endif } else { #ifdef TRACE_CAN restart_wdt(); tmp=ms+1000*sec; printf("[%Lu] - CAN_DEBUG - FAIL on can_getd function", tmp); #endif } } }
void main(void){ int8_t data=0; setup_adc(ADC_CLOCK_DIV_8); //ADCのサンプリング設定 setup_wdt(WDT_1152MS); while(1){ restart_wdt();/* output_high(PIN_A0); output_low(PIN_A1); output_high(PIN_A2); //以上アドレスピン設定 output_low(PIN_A3); output_low(PIN_A4); output_high(PIN_A5); //以上エネーブルピン設定*/ output_a(0b00001111); setup_adc_ports(ALL_ANALOG); set_adc_channel(6); /* ここでADCを適用できるピンと実際に適用するピンを決めます。 ちなみに仕様として各ピンの役割を個別に設定できないようです。 ですがすべてアナログに設定しても問題なくエネーブルピンやアドレスピンは動いてくれているので見なかったことにしましょう。 */ delay_us(20); restart_wdt(); data=read_adc(); setup_adc_ports(NO_ANALOGS);//一応戻しています。 putc((char)data); sleep(); } }
void txinit(){ key_off(); pll_off(); output_low(CWSTB); output_low(CWCLK); output_low(CWDAT); restart_wdt(); delay_ms(500); delay_ms(500); restart_wdt(); pll_on(); delay_ms(500); delay_ms(500); txhotflag=TX_IS_COOL; restart_wdt(); pll_init_cw( 0x0EF, // refernce driver (Nref = 239) 0x015, // swallow counter (Nprg = 2613) 0x051, // programmable_counter (Nprg = 2613) 1, // channel (Group code "01") 3, // charge_pump_tx (CPT1 = 1, CPT2 = 1) 0, // charge_pump_rx (CPR1 = 0, CPR2 = 0) 1, // lock_detector (LD1 = 1, LD2 = 0) 0, // standby_control_tx (Tx = 0) 1 // standby_control_rx (Rx = 1) ); delay_ms(500); restart_wdt(); }
void main() { union { unsigned int32 hours; unsigned int8 minutes; unsigned int8 seconds;} upTime; TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick; resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register) STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags PortInit(); OutputInit(); restart_wdt(); romEZHRInit(); //set up default ezhr settings eeROMinit(); //set up default eprom settings IPAddressInit(); //set up MAC and default IP addresses delay_ms(500); ADCInit(); //set up ADC ports iniADCParams(); SerialInit(); //set up serial ports TickInit(); //set up tick timer enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); StackInit(); WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi SetLEDConfig(E_LED_CONFIG); // swap LED's output_high(E_SW_PWR_DN); // Power Ethernet Switch output_high(E_SW_RST); output_low(RS485_TXEN); output_high(RS485_RXDIS); output_high(RS232_F_OFF); output_high(RS232_F_ON); CurrentTick = PreviousUDPTick = get_ticks(); UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND; portControlInit(); while(TRUE) { CurrentTick = get_ticks(); restart_wdt(); StackTask(); restart_wdt(); MyTCPTask();//handles TCP connections restart_wdt(); setIO();// checks voltage status and sets ports accordingly //! if(CurrentTick-PreviousUDPTick >= UDPSampleRate) //! { //! currentRoutine=UDPTASK; //! BOOL UDPDone = MyUDPTask(); //! if(UDPDone) //! { //! PreviousUDPTick=CurrentTick; //! } //! } StackApplications(); } }
void main() { char reponse='a'; int flag=255; int id1=23; int id2=12; int value1=15; int value2=16; int value3=17; //initialisation du PIC setup_adc(ADC_OFF); //on gère toutes les entrées comme étant de type analogique et on mesure les tensions par rapport à une ref 5V enable_interrupts(INT_TIMER2); //configuration des interruptions enable_interrupts(INT_AD); enable_interrupts(GLOBAL); setup_timer_2(T2_DIV_BY_4,250,5); //setup up timer2 to interrupt every 0,1ms can_init(); //initialise le CAN can_set_baud(); //obsolète à priori à tester restart_wdt(); #ifdef DEBUG // Mise en évidence d'un problème lié au Watchdog switch ( restart_cause() ) { case WDT_TIMEOUT: { printf("\r\nRestarted processor because of watchdog timeout!\r\n"); break; } case NORMAL_POWER_UP: { printf("\r\nNormal power up! PIC initialized \r\n"); break; } } restart_wdt(); #endif // BOUCLE DE TRAVAIL while(TRUE) { putc(flag); putc(id1); putc(value1); putc(flag); putc(id1); putc(value2); putc(flag); putc(id2); putc(value3); } }
void sendtl(void){ restart_wdt(); write_ResetMarker(RESET_SENDING); printf(send); for(j=0;j<32;j++) putc((char)tlm[j]); restart_wdt(); putc(' '); putc('\r'); putc('\n'); task_hk=WAIT_TASKHK; HKInit(); write_ResetMarker(RESET_OTHERS); return; }
void log_init(void) { fprintf(stream_wireless,"# initializing logging\r\n"); lcd_clear(); printf(lcd_putch,"Resetting Log!"); delay_ms(1200); write_ext_fram(FRAM_ADDR_RECORD_N,0); write_ext_fram(FRAM_ADDR_DATAFLASH_PAGE+0,0); write_ext_fram(FRAM_ADDR_DATAFLASH_PAGE+1,0); /* erase the first block of the data flash */ dataflash_select(); spi_write2(0x50); spi_write2(0x00); spi_write2(0x00); spi_write2(0x00); dataflash_unselect(); delay_ms(10); /* wait for page to finish erasing and writing */ while ( ! bit_test(dataflash_read_status(),7) ) { restart_wdt(); //fputc('x',modem); } lcd_goto(LCD_LINE_TWO); printf(lcd_putch,"Done"); fprintf(stream_wireless,"> done\r\n"); delay_ms(1200); }
void ext_flash_waitUntilReady(void) { // this function read status register // Bit7 : 1=RDY, 0=BUSY // Bit6 : COMP, 1=Recent Main memory page compare, 0 == match // Bit 5-2 : 0b0111 , density code for 4MBit // Bit 1: Protect // Bit 0: Page size. 0= 264 byte, 1=256 byte int flashData; int i; output_low(FLASH_SELECT); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 0); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 0); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK); for(i=0;i<255;i++) { flashData = 0; output_high(FLASH_CLOCK); flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK); if (bit_test(flashData,7) == 1) break; // device is not busy delay_cycles(50); restart_wdt(); } output_high(FLASH_SELECT); }
/* Restarts servicing of WD with timer0 */ void restart_heartbeat() { // pre-sets timer0, resets WDT, LED ON, clear t0 int set_timer0(TIMER0_PRESET); restart_wdt(); clear_interrupt(INT_TIMER0); enable_interrupts(INT_TIMER0); setup_led_pulse(); }
void main() { //initialisation du PIC setup_adc_ports(NO_ANALOGS); //on gère toutes les entrées comme étant de type numérique enable_interrupts(INT_TIMER2); //configuration des interruptions enable_interrupts(GLOBAL); setup_timer_2(T2_DIV_BY_4,250,5); //setup up timer2 to interrupt every 1ms can_init(); //initialise le CAN restart_wdt(); #ifdef DEBUG // Mise en évidence d'un problème lié au Watchdog switch ( restart_cause() ) { case WDT_TIMEOUT: { printf("\r\nRestarted processor because of watchdog timeout!\r\n"); break; } case NORMAL_POWER_UP: { printf("\r\nNormal power up! PIC initialized \r\n"); break; } } restart_wdt(); #endif // BOUCLE DE TRAVAIL while(TRUE) { restart_wdt(); listenCAN(); } }
//################## MAIN ################################### int main(void){ unsigned char prv; idata IData; boolian IPacketMode=0; odata OData; boolian OPacketMode=0; sint8 debug_cnt=0; //初期化 initialize(); //メッセージ登録 msg_regist('m',motor_setup_listen,motor_listen,motor_setup_talk,motor_talk); msg_regist('j',sprite_setup_listen,sprite_listen,sprite_setup_talk,sprite_talk); msg_regist('b',battery_setup_listen,battery_listen,battery_setup_talk,battery_talk); msg_regist('g',gps_setup_listen,gps_listen,gps_setup_talk,gps_talk); msg_regist('C',co2_setup_listen,co2_listen,co2_setup_talk,co2_talk); // msg_regist('S',h2s_message); msg_regist('t',thermo_setup_listen,thermo_listen,thermo_setup_talk,thermo_talk); // msg_regist('T',infrared_setup_listen,infrared_listen,infrared_setup_talk,infrared_talk); msg_regist('h',0,0,0,0); msg_regist('c',compass_setup_listen,compass_listen,compass_setup_talk,compass_talk); msg_regist('a',axel_setup_listen,axel_listen,axel_setup_talk,axel_talk); msg_regist('G',gyro_setup_listen,gyro_listen,gyro_setup_talk,gyro_talk); msg_regist('!',debug_setup_listen,debug_listen,debug_setup_talk,debug_talk); /* HMR_PIN_RedLED_set(0); HMR_PIN_YellowLED_set(0); delay_ms(500); HMR_PIN_RedLED_set(1); HMR_PIN_YellowLED_set(1); delay_ms(500); HMR_PIN_RedLED_set(0); HMR_PIN_YellowLED_set(0); delay_ms(500); HMR_PIN_RedLED_set(1); HMR_PIN_YellowLED_set(1); delay_ms(500); HMR_PIN_RedLED_set(0); HMR_PIN_YellowLED_set(0); HMR_PIN_RedLED_set(1); */ HMR_PIN_DebugLED_set(0); HMR_PIN_Debug2LED_set(0); while(1){ delay_ms(5); //Watch Dog Timer リセット restart_wdt(); //受信可能なデータが無ければ再び待つ if(!com_in_empty()){ //@@@@@@ Begin Critical@@@@@@ prv = hmr_lock_interrupt(); com_in_move_pop(&IData); hmr_release_interrupt(prv); //@@@@@@ End Critical@@@@@@ if(idata_is_construct(&IData)){ //PacketModeに入っていないとき if(!IPacketMode){ //Packetをここで開く IPacketMode=hmLib_true; msg_setup_listen(); } //Packet終了IDだった場合 if(IData.ID==HMR_COM_PACTRMNID){ //Packetがここで終了 IPacketMode=hmLib_false; prv = hmr_lock_interrupt(); idata_destruct(&IData); hmr_release_interrupt(prv); }else{ //メッセージ処理 prv = hmr_lock_interrupt(); msg_listen(&IData); hmr_release_interrupt(prv); } } } delay_ms(5); //送信待ちのPacketがなく、comの送信バッファがいっぱいでもないとき if(!com_isWaitSendPacket() && !com_out_full()){ //PacketModeに入っていないとき if(!OPacketMode){ //Packetをここで開く OPacketMode=hmLib_true; msg_setup_talk(); } //送信用データを準備する odata_format(&OData); //送信データの取得に失敗した場合 prv = hmr_lock_interrupt(); if(msg_talk(&OData)){ //内部で作成されていれば破棄 if(odata_is_construct(&OData))odata_destruct(&OData); //Packetをここで閉じる OPacketMode=hmLib_false; OData.ID=HMR_COM_PACTRMNID; } hmr_release_interrupt(prv); //送信データを登録する //@@@@@@ Begin Critical@@@@@@ prv = hmr_lock_interrupt(); com_out_move_push(&OData); hmr_release_interrupt(prv); //@@@@@@ End Critical@@@@@@ } //送信割り込みが切られていて、かつ送信可能状態のときには、送信割り込みをオンにする if(!uart1_is_enable_fput_interrupt()){ if(vmc1_can_send(pVMC))uart1_enable_fput_interrupt(); } if(debug_cnt<0){ HMR_PIN_DebugLED_set(1); }else{ HMR_PIN_DebugLED_set(0); } ++debug_cnt; } finalize(); return 0; }
void main() { mydevices.numberOfInputs=0; mydevices.numberOfOutputs=0; clock = 0; ledErrorCounter=0; hw_setup(); //TODO: User Code //struct switches array[NUMBER_OF_SWITCHES]; /* button_test(); dimmer_test(); */ ///////////////SALA////////////////////////////// /* eeprom_on_off_init(20,21,6);//2 int Grande a comecar da esquerda eeprom_on_off_init(22,23,0);//2 //eeprom_dimmer_init(40,41,42,7);//2 eeprom_on_off_init(41,42,7);//2 eeprom_on_off_init(26,27,3);//2 ///Sanca parede grande unsigned int on_adr[8]={20,255,255,255,255,255,255,255}; unsigned int off_adr[8]={21,255,255,255,255,255,255,255}; eeprom_onOff_out_init(on_adr,off_adr,3);//Sanca parede grande eeprom_onOff_out_init(on_adr,off_adr,5);//Sanca parede grande ///Sanca parede rosa unsigned int on_adrr[8]={22,255,255,255,255,255,255,255}; unsigned int off_adrr[8]={23,255,255,255,255,255,255,255}; eeprom_onOff_out_init(on_adrr,off_adrr,7);//Sanca parede grande on_adrr[1]=26; off_adrr[1]=27; eeprom_onOff_out_init(on_adrr,off_adrr,4);//Sanca parede grande ///VARANDA unsigned int dimmer_dim_adr[8]={40,255,255,255,255,255,255,255}; unsigned int dimmer_on_adr[8]={41,255,255,255,255,255,255,255}; unsigned int dimmer_off_adr[8]={42,255,255,255,255,255,255,255}; //eeprom_dimmer_out_init(dimmer_dim_adr,dimmer_on_adr,dimmer_off_adr,6);//varanda eeprom_onOff_out_init(dimmer_on_adr,dimmer_off_adr,6);//varanda eeprom_button_init(28,29,4,true);//estores down eeprom_button_init(30,31,5,true);//estores up unsigned int up_adr[8]={30,255,255,255,255,255,255,255}; unsigned int down_adr[8]={28,255,255,255,255,255,255,255}; unsigned int x_adr[8]={255,255,255,255,255,255,255,255}; eeprom_shutter_out_init(up_adr,down_adr,x_adr,x_adr,8,9,0,10); eeprom_shutter_out_init(up_adr,down_adr,x_adr,x_adr,10,11,0,10); eeprom_shutter_out_init(up_adr,down_adr,x_adr,x_adr,12,13,0,10); eeprom_shutter_out_init(up_adr,down_adr,x_adr,x_adr,14,15,0,10); */ /////////////////////////////////////////////////7 /* ///////////////QUARTO GRANDE////////////////////////////// eeprom_on_off_init(1,2,2);//2 on_adr off_adr real_button inicia botao unsigned int on_adr[8]={1,255,255,255,255,255,255,255}; unsigned int off_adr[8]={2,10,255,255,255,255,255,255}; unsigned int nill_adr[8]={255,255,255,255,255,255,255,255}; unsigned int ventax_off_adr[8]={16,255,255,255,255,255,255,255}; unsigned int x_adr[8]={1,255,255,255,255,255,255,255}; eeprom_onOff_out_init(on_adr,off_adr,4);//SANCA? //outputs 4=sanca 3=casabanho 2=casa de banho 9=ventax 1=corredor ///casa de banho eeprom_on_off_init(3,4,4);//interruptor casa de banho?? off_adr[0]=4; on_adr[0]=3; eeprom_timer_init(off_adr,on_adr,15,16,time_off,60); eeprom_onOff_out_init(on_adr,off_adr,3); //luz casa de banho eeprom_onOff_out_init(on_adr,off_adr,2); //luz2 casa de banho eeprom_onOff_out_init(on_adr,ventax_off_adr,9);//VENTAX ///fim casa de banho //corredor eeprom_on_off_init(17,18,5);//interruptor luz corredor unsigned int corredor_on_adr[8]={17,255,255,255,255,255,255,255}; unsigned int corredor_off_adr[8]={18,255,255,255,255,255,255,255}; eeprom_onOff_out_init(corredor_on_adr,corredor_off_adr,1); //luz corredor //fim corredor eeprom_button_init(5,6,0,true);//2 //estores eeprom_button_init(7,8,1,true);//2 off_adr[0]=255; off_adr[1]=255; on_adr[0]=5; x_adr[0]=7; eeprom_shutter_out_init(on_adr,x_adr,off_adr,off_adr,11,10,0,10);//up down fullup full down eeprom_on_off_init(9,10,6); eeprom_on_off_init(20,21,7); unsigned int cama_on_adr[8]={9,255,255,255,255,255,255,255}; unsigned int cama_off_adr[8]={10,255,255,255,255,255,255,255}; eeprom_onOff_out_init(cama_on_adr,cama_off_adr,7); cama_on_adr[0]=20; cama_off_adr[0]=21; eeprom_onOff_out_init(cama_on_adr,cama_off_adr,6); /////////////////////////////////////////////////7 */ /////////////////////QUARTO RENATA/////////////// // // INPUTS // 0,1 cozinha // 2,3 quarto // // OUTPUTS // 5 quarto renata economica // 6 janela hologeneo // 7 entrada // 2 cozinha fluorescente // 3 cima balcao halogeneo // 4 divisoria halogeneo // 10 balcao baixo verde // 11 balcao cima verde // 12 balcao cima vermelho // 13 balcao cima azul // 14 balcao baixo azul // 15 balcao baixo vermelho //INPUT INIT eeprom_on_off_init(60,61,0);//on_adr off_adr real_btn interruptor cozinha 1 eeprom_on_off_init(62,63,1);//on_adr off_adr real_btn interruptor cozinha 2 // eeprom_dimmer_init(68,62,63,1);//dim_adr on_adr off_adr eeprom_on_off_init(64,65,2);//on_adr off_adr real_btn interruptor quarto renata 1 // eeprom_on_off_init(66,67,3);//on_adr off_adr real_btn interruptor quarto renata 2 eeprom_dimmer_init(68,66,67,3);//dim_adr on_adr off_adr //OUTPUT INIT unsigned int on_adr[8]={60,255,255,255,255,255,255,255}; unsigned int off_adr[8]={61,10,255,255,255,255,255,255}; unsigned int dim_adr[8]={68,255,255,255,255,255,255,255}; eeprom_onOff_out_init(on_adr,off_adr,2); //luz cozinha fluorescente on_adr[0]=62; off_adr[0]=63; eeprom_onOff_out_init(on_adr,off_adr,3); //luz cozinha cima balcao halogeneo eeprom_onOff_out_init(on_adr,off_adr,4); //luz cozinha divisoria eeprom_onOff_out_init(on_adr,off_adr,15); //luz balcao baixo vermelho eeprom_onOff_out_init(on_adr,off_adr,12); //luz balcao cima vermelho //eeprom_dimmer_out_init(dim_adr,on_adr,off_adr,3); //luz cozinha cima balcao halogeneo //eeprom_dimmer_out_init(dim_adr,on_adr,off_adr,4); //luz cozinha divisoria //eeprom_dimmer_out_init(dim_adr,on_adr,off_adr,15); //luz cozinha divisoria on_adr[0]=64; off_adr[0]=65; eeprom_onOff_out_init(on_adr,off_adr,5); //luz quarto renata economica on_adr[0]=66; off_adr[0]=67; // eeprom_onOff_out_init(on_adr,off_adr,7); //luz quarto renata entrada // eeprom_onOff_out_init(on_adr,off_adr,6); //luz quarto renata janela eeprom_dimmer_out_init(dim_adr,on_adr,off_adr,7); //luz quarto renata entrada eeprom_dimmer_out_init(dim_adr,on_adr,off_adr,6); //luz quarto renata janela readDevices(); #ifdef DEBUG printf("inputs:%d outputs:%d %d %d\n\r",mydevices.numberOfInputs,mydevices.numberOfOutputs,((struct outputs)mydevices.myoutputs[0]).type,((struct outputs)mydevices.myoutputs[1]).type); #endif dimmer_outputs_init(); // printf("start %Lu %Lu %Lu\n\r",fpointer(N_LUZES,0),delays1[N_LUZES][0],delays2[N_LUZES][0]); /*((struct light)mydevices.myoutputs[0].device).dim_value.value=50; ((struct light)mydevices.myoutputs[0].device).dim_value.needs_update=true; ((struct light)mydevices.myoutputs[0].device).off.value=1; ((struct light)mydevices.myoutputs[0].device).off.needs_update=true; */ write_outputs(); // printf("start %Lu\n\r",fpointer(N_LUZES,0)); interrupts_enable(); while(true){ restart_wdt(); if(syncError || oscError) { ++ledErrorCounter; if(ledErrorCounter>1000) { output_toggle(LED); ledErrorCounter=0; } } #ifdef DEBUG if(kbhit()) { setup_wdt(WDT_OFF); disable_interrupts (GLOBAL) ; goDebug(); } #endif process_outpoints(); write_outputs(); if(secondFlag) { secondFlag=false; processTimedEvents(); if(!syncError && !oscError) output_toggle(LED); } // print_inputs(false); } }
/* Stops timer isr from servicing WD. If heartbeat(TRUE) is not called within 4 seconds WD will bark (=reset_cpu) */ void suspend_heartbeat() { disable_interrupts(INT_TIMER0); restart_wdt(); }
void main(void) { init(); splash(); while (TRUE) { restart_wdt(); #if STACK_USE_SERIAL if (kbhit(USER)) { ui_handle(); } #endif //every second: refresh current IP, blink LED if (second_counter>=1) { display_ip_lcd(); #if defined(USER_LED3) output_toggle(USER_LED3); #endif second_counter=0; } //just something to test the buttons #if STACK_USE_CCS_PICNET if (BUTTON_PRESSED(USER_BUTTON1)) { output_low(USER_LED1); } else { if (g_LEDState[0]) output_low(USER_LED1); else output_high(USER_LED1); } if (BUTTON_PRESSED(USER_BUTTON2)) { output_low(USER_LED2); } else { if (g_LEDState[1]) output_low(USER_LED2); else output_high(USER_LED2); } #elif STACK_USE_CCS_PICENS if (g_LEDState[0]) output_low(USER_LED1); else output_high(USER_LED1); if (g_LEDState[1]) output_low(USER_LED2); else output_high(USER_LED2); if (BUTTON_PRESSED(USER_BUTTON1)) output_low(USER_LED3); #endif #if STACK_USE_PPP if (ppp_is_connected()) { #endif StackTask(); //Microchip's TCP/IP stack handler. Must be called routinely. #if STACK_USE_PPP } #endif } }
void main() { setup_wdt(WDT_ON); // Watchdog starten InitPeripheral(); lcd_init(); systeminit(); // Werte aus dem EEPROM lesen lcd_putc('\f'); // Clear display lcd_send_byte(0,0x0C); // Cursor aus Menue = 0; Pfad = 0; GutMeldung=0; if(!Tag)Jahrwartung=1; for(;;) { restart_wdt(); // Watchdog rücksetzen ///////////////////////////////////////////// // Analogwerte einlesen, auswerten und anzeigen memset(Zeile1, 0x20, sizeof(Zeile1)); memset(Zeile2, 0x20, sizeof(Zeile2)); if (input(Wartung )) { NeuMenue=1; ADW(); if(!KSZ) { Alarmpunkte(); if(Alarmalt<Alarm)Hupen=1; Alarmalt=Alarm; if(Stoerung[0]||Stoerung[1])Gutmeldung=0; else Gutmeldung=32; PORTD=Out[0]|Out[1]|GutMeldung|Hupen; } TasterReset(); if(!JahrWartung) { WertAnzeige(); } else AusWart(); } /////////////////////////////////////////// // oder Konfigurationsmenue else { if(NeuMenue) { Passwort = 1; p[0]='0'; p[1]='0'; p[2]='0'; p[3]='0'; Pos=2; Menue=0; Pfad=0; NeuMenue=0; } if(Passwort) { PWDisplay(); lcd_gotoxy(Pos,2); lcd_send_byte(0,0x0F); // Cursor ein Tasterauswertung(); } else { Tasterauswertung(); Menuefuehrung(); Untermenue(); NeuerWert=0; } } }//for(;;) }
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(); } } }