int main(void) { int c; int led = 0; unsigned long count = 0; unsigned long baud = 1000000; init(); uart1_putstr("\r\nStarting CM720 Dynamixel relay controller\r\n"); uart1_printf("Switching serial to %lu baud...\r\n", baud); _delay_ms(100); uart1_setbaud(baud); uart1_printf("\r\nRunning serial at %lu baud\r\n", baud); _delay_ms(100); while (1) { count++; if (count % 1000 == 0) { // Toggle MON and Dynamixel Leds if (led) { led = 0; sbi(PORTC, PORTC4); rs485_putstrn("\xFF\xFF\xFE\x04\x03\x19\x00\xE1", 8); } else { led = 1; cbi(PORTC, PORTC4); rs485_putstrn("\xFF\xFF\xFE\x04\x03\x19\x01\xE0", 8); } } c = uart1_getchar(); while (c != EOF) { // RxD LED on cbi(PORTC, PORTC1); rs485_putchar(c); c = uart1_getchar(); } // RxD LED off sbi(PORTC, PORTC1); c = rs485_getchar(); while (c != EOF) { // TxD LED on cbi(PORTC, PORTC2); uart1_putchar(c); c = rs485_getchar(); } // TxD LED off sbi(PORTC, PORTC2); } return 0; }
/******************************************************************************* * PRIVATE FUNCTION: test_uart1a * * PARAMETERS: * ~ void * * RETURN: * ~ void * * DESCRIPTIONS: * Test the UART1 Alternative. * *******************************************************************************/ void test_uart1a(void) { unsigned char i = 0; while (SW1==1) // Loop until SW1 is press { lcd_clear(); lcd_putstr("SW1 test UART1A\nConnect UC00A"); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } lcd_clear(); lcd_putstr("TX Selector=TX1A\nRX Selector=RX1A"); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } lcd_clear(); lcd_putstr(arr_hyperterminal); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } }//while (SW1 == 1) while(SW1==0); //wait for SW1 to be release uart1a_initialize(); // initialize UART1A lcd_clear(); lcd_putstr(arr_enter); // Sending message to the PC through UART1 uart1_transmit(0x0C); //clear HyperTerminal uart1_putstr(arr_thanks); uart1_putstr("\r\n\nDemo UART1 Alternative on SKds40A...\r\n"); uart1_putstr(arr_keyboard); uart1_putstr(arr_echo); uart1_putstr(arr_enter_keyboard); do { c_received_data = uc_uart1_receive(); //echo what is received LED1 = ~LED1; // toggle LED 1 uart1_transmit(c_received_data); } while (c_received_data != '\r' && c_received_data != '\n'); // Sending message to the PC. uart1_putstr("\r\n\nUART1 Alternative Demo Completed.\r\n"); LED1 = 0; beep(2); lcd_clear(); lcd_putstr("UART1 Alternative\nPass!"); delay_ms(500); }
/******************************************************************************* * PRIVATE FUNCTION: test_uart1a * * PARAMETERS: * ~ void * * RETURN: * ~ void * * DESCRIPTIONS: * Test the UART1 Alternative. * *******************************************************************************/ void test_uart1a(void) { unsigned char i = 0; while (SW1==1) // Loop until SW1 is press { lcd_clear(); lcd_putstr("SW1 test UART1A\nConnect UC00A"); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } lcd_clear(); lcd_putstr("TX Selector=TX1A\nRX Selector=RX1A"); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } lcd_clear(); lcd_putstr("HyperTerminal\n9600, 8, N, 1"); for (i = 0; i < 50; i++) { if(SW1 == 0) break; delay_ms(30); } }//while (SW1 == 1) while(SW1==0); //wait for SW1 to be release uart1a_initialize(); // initialize UART1A lcd_clear(); lcd_putstr("Press enter on\nkeyboard to exit"); // Sending message to the PC through UART1 uart1_transmit(0x0C); //clear HyperTerminal uart1_putstr("\r\n\nThanks for using Cytron Technologies product\r\n"); uart1_putstr("\r\n\nDemo UART1 Alternative on SKds40A...\r\n"); uart1_putstr("Press any key on keyboard to demo.\r\n"); uart1_putstr("It will be echo back to HyperTerminal.\r\n"); uart1_putstr("Press enter to exit.\r\n\n"); do { c_received_data = uc_uart1_receive(); //echo what is received LED1 = ~LED1; // toggle LED 1 uart1_transmit(c_received_data); } while (c_received_data != '\r' && c_received_data != '\n'); // Sending message to the PC. uart1_putstr("\r\n\nUART1 Alternative Demo Completed.\r\n"); LED1 = 0; beep(2); lcd_clear(); lcd_putstr("UART1 Alternative\nPass!"); delay_ms(500); }