void ZIGB_ch_wrt(U8 *ch_no) { uart1_send_string("ATCH"); uart1_send_string(ch_no); uart1_send_byte('\r'); if(ZIGB_responce(3,"OK\r")) { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rCH: OK "); #endif ms_delay(10000); } else { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rCH: ERROR "); #endif ms_delay(10000); } }
void ZIGB_my_wrt(U8 *my_add) { uart1_send_string("ATMY"); uart1_send_string(my_add); uart1_send_byte('\r'); if(ZIGB_responce(3,"OK\r")) { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rMY: OK "); #endif ms_delay(10000); } else { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rMY: ERROR "); #endif ms_delay(10000); } }
void ZIGB_pan_wrt(U8 *pan_add) { uart1_send_string("ATID"); uart1_send_string(pan_add); uart1_send_byte('\r'); if(ZIGB_responce(3,"OK\r")) { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rPAN: OK "); #endif ms_delay(10000); } else { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rPAN: ERROR "); #endif ms_delay(10000); } }
void ZIGB_dl_wrt(U8 *dest_add) { uart1_send_string("ATDL"); uart1_send_string(dest_add); uart1_send_byte('\r'); if(ZIGB_responce(3,"OK\r")) { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rDL: OK "); #endif ms_delay(10000); } else { #if RESP_ON_UART0 == 1 uart0_send_string("\n\n\rDL: ERROR "); #endif ms_delay(10000); } }
void ZIGB_my_read() { U8 temp_arr[20]= "000"; U8 temp_cnt; uart1_send_string("ATMY"); uart1_send_byte('\r'); for(temp_cnt = 0; Uc_zigb_my[temp_cnt - 1] != '\r'; temp_cnt++) { while((U1LSR & 0x01) == 0); Uc_zigb_my[temp_cnt] = U1RBR; } Uc_zigb_my[temp_cnt - 1] = '\0'; uart0_send_string("\n\n\rMY Address: "); uart0_send_string(&Uc_zigb_my[0]); }
///////////////// // main routine ///////////////// void main (void) { uint8_t Rx, loop; ///////////////// // init peripherals ///////////////// // disable interrupts DISABLE_INTERRUPTS; // switch to 16MHz (default is 2MHz) CLK.CKDIVR.byte = 0x00; // configure green LED pin (PH2) gpio_init(&PORT_H, PIN_2, OUTPUT_PUSHPULL_FAST); // init timer TIM4 for 1ms clock with interrupts tim4_init(); // init pins for UART1 Rx(=PA4) and Tx(=PA5) gpio_init(&PORT_A, PIN_4, INPUT_PULLUP_NOEXINT); gpio_init(&PORT_A, PIN_5, OUTPUT_PUSHPULL_FAST); // init UART1 (connected to PC on muBoard) uart1_init(115200L); // init pins for UART3 Rx(=PD6) and Tx(=PD5) gpio_init(&PORT_D, PIN_6, INPUT_PULLUP_NOEXINT); gpio_init(&PORT_D, PIN_5, OUTPUT_PUSHPULL_FAST); // init UART3 (available on io-plug on muBoard) uart3_init(115200L); // enable interrupts ENABLE_INTERRUPTS; ///////////////// // main loop ///////////////// loop = 0; while (1) { // if byte received via UART1 send via UART3 if (uart1_check_Rx()) uart3_send_byte(uart1_receive()); // if byte received via UART3 send via UART1 if (uart3_check_Rx()) uart1_send_byte(uart3_receive()); // every 1ms do if (g_flagClock) { g_flagClock = 0; // every 500ms toggle LED & print text if (g_clock > 500) { g_clock = 0; // toggle LED PORT_H.ODR.bit.b2 ^= 1; } // loop 500ms } // loop 1ms } // main loop } // main
void main() { PINSEL0 |= 0X00050005; // selecting UART0 and UART1 PINSEL1 |= 0X00080000; IO1DIR |= 0X0FFF0000; //pins 1.16 to 1.23 output pins IO0DIR |= 0X003E0C00; //port 0 rs and en as output IO0CLR = 0X00FF0000; IO0SET = 0X0FF00400; IO0CLR = BUZZER; //*************************************// // Initialisations // //*************************************// lcd_init(); irq_init(); uart_init(); adc_init(); //wdt_init(); pwm5_init(); timer1_init_interrupt(); rtc_init_interrupt(); //*************************************// // Welcome Note // //*************************************// lcd_line2_disp(&welcome_note1[0],0); lcd_line3_disp(&welcome_note2[0],6); ms_delay(50000); clrscr(); lcd_line1_disp(&lcd_data_sys_chk[0],0); display_dots(); display_dots(); //*************************************// // Displaying Static Messages // //*************************************// clrscr(); default_page(); U0IER = 0; rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); lcd_line4_disp(&Uc_set_user_time[0],0); wdt_init(); while(1) { wdt_feed(0x03ffffff); rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); if(wdt_timeout == 1) { wdt_timeout = 0; lcd_line3_disp("WDEnable",12); } //*********************************************// // ADC input value // //*********************************************// if(Uc_adc_time_out_flag == 1) { Uc_adc_time_out_flag = 0; Ui_sample1 = adc1_getval(); ms_delay(800); Ui_sample2 = adc1_getval(); ms_delay(800); Ui_sample3 = adc1_getval(); ms_delay(800); Ui_sample4 = adc1_getval(); ms_delay(800); Ui_sample5 = adc1_getval(); adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5, 1); temp_ctrl(); lcd_line1_disp(&Uc_dec_arr[1],5); //*********Sending DATA to User desk*************// //uart0_send_string("\n\r "); uart0_send_byte((Ui_sample1 & 0xff)); uart1_send_byte(0x7E); uart1_send_string(&Uc_dec_arr[1]); uart1_send_byte('\0'); //**********************************************// Ui_sample1 = adc3_getval(); ms_delay(900); Ui_sample2 = adc3_getval(); ms_delay(900); Ui_sample3 = adc3_getval(); ms_delay(900); Ui_sample4 = adc3_getval(); ms_delay(900); Ui_sample5 = adc3_getval(); ms_delay(750); Ui_sample6 = adc3_getval(); ms_delay(750); Ui_sample7 = adc3_getval(); ms_delay(750); Ui_sample8 = adc3_getval(); ms_delay(750); Ui_sample9 = adc3_getval(); Ui_sample6 = ((Ui_sample6 + Ui_sample7 + Ui_sample8 + Ui_sample9) / 4); Ui_sample5 = ((Ui_sample6 + Ui_sample5)/2); adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5 , 0); lcd_line3_disp(&Uc_dec_arr[1],5); //*********Sending DATA to User desk*************// uart1_send_string(&Uc_dec_arr[1]); //**********************************************// } //*********************************************// // displaying Real Time & user Set Time // //*********************************************// if(Uc_alrm == 1) { Uc_alrm = 2; pwm5_pulse_width(5000, 100); } /* else if(Uc_alrm == 3) { if(Uc_user_dwn_sec == 0) { Uc_user_dwn_sec = 59; if( (Uc_user_dwn_min + Uc_user_dwn_hr) != 0) { Uc_user_dwn_min -= 1; } Uc_set_user_time[3] = ((Uc_user_dwn_min / 10) + 0x30); Uc_set_user_time[4] = ((Uc_user_dwn_min % 10) + 0x30); } if(Uc_user_dwn_min == 0) { Uc_user_dwn_min = 59; if(Uc_user_dwn_hr != 0) { Uc_user_dwn_hr -= 1; } Uc_set_user_time[0] = ((Uc_user_dwn_hr / 10) + 0x30); Uc_set_user_time[1] = ((Uc_user_dwn_hr % 10) + 0x30); } Uc_set_user_time[6] = ((Uc_user_dwn_sec / 10) + 0x30); Uc_set_user_time[7] = ((Uc_user_dwn_sec % 10) + 0x30); } */ //*********************************************// rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); lcd_line4_disp(&Uc_set_user_time[0],0); //*********************************************// // key press on background // //*********************************************// Uc_key_temp = get_key(0); if(Uc_key_temp == 'E') { Uc_key_temp = 0; get_user_time(); } else if((Uc_key_temp == '.')&(Uc_alrm == 2)) { Uc_key_temp = 0; Uc_alrm = 0; pwm_disable(); } else if(Uc_key_temp == 'A') { clrscr(); ms_delay(1000); lcd_line2_disp("Emergency Stop!",3); lcd_line4_disp("Cooling ON",5); IO0CLR = SSR_ON; IO0CLR = HEATER_ON; IO0SET = COOLER_ON; while(1); } else if(Uc_key_temp == 'D') { Uc_key_temp = 0; rtc_change_time(); } } }