uart.c
/*******************************************************************************
* examples/uart.c *
* =============== *
* *
* Version: 1.0.4 *
* Date : 01.11.17 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testUart(void);
int main(void);
//*********************************[testUart]***********************************
void testUart(void) {
uint8_t flag_redraw_menu = 0xFF;
uint8_t menu_pos = 0;
uint8_t display_pos = 0;
lcdclr();
lcdstr_p(PSTR("UART - XBee" ));
while (1) {
// redraw menu
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
lcdxy(7,0);
switch (menu_pos) {
case 1:
lcdstr_p(PSTR("USB "));
break;
case 2:
lcdstr_p(PSTR("RS232 "));
break;
case 3:
lcdstr_p(PSTR("Internal"));
break;
default:
lcdstr_p(PSTR("XBee "));
menu_pos = 0;
break;
}
lcdxy(0,1); lcdstr_p(PSTR("######## <+> <s>"));
mdelay(400);
}
// check if buttons were pushed
// middle button --> increase menu
mdelay(100);
menu_pos++;
if (menu_pos > 3) {menu_pos = 0;}
flag_redraw_menu = 0xFF;
} else {
// right button --> send text
mdelay(100);
if (menu_pos == 1) {
serstr0_p(PSTR("Test - UART" "\n\r" "send to "));
serstr0_p(PSTR("USB "));
serout0('\n'); serout0('\r');
} else {
serstr1_p(PSTR("Test - UART" "\n\r" "send to "));
switch (menu_pos) {
case 2: serstr1_p(PSTR("RS232 ")); break;
case 3: serstr1_p(PSTR("Internal")); break;
default: serstr1_p(PSTR("XBee ")); break;
}
serout1('\n'); serout1('\r');
}
mdelay(400);
}
// update display depending on menu position
if (menu_pos == 1) {
if (serstat0()) {
lcdxy(display_pos,1);
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
} else {
if (serstat1()) {
lcdxy(display_pos,1);
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
}
}
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testUart();
return (0);
}
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
serstat1
uint8_t serstat1(void)
Gets the number of bytes in the input buffer from UART1.
serstat0
uint8_t serstat0(void)
Gets the number of bytes in the input buffer from UART0.
serstr0_p
void serstr0_p(const char *send_data)
Sends a string located in the flash through the UART0.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
uart_select
void uart_select(eUart select)
Selects the interface of the UART1.
kUartInternal
@ kUartInternal
constant (1): select DSub15 interface
Definition: uart.h:55
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
serinp0
uint8_t serinp0(void)
Receives one byte from the UART0.
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
serout1
void serout1(uint8_t send_data)
Sends one byte through the UART1.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
kUartXbee
@ kUartXbee
constant (2): select XBee interface
Definition: uart.h:57
lcdclr
void lcdclr(void)
Clears the display.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
serstr1_p
void serstr1_p(const char *send_data)
Sends a string located in the flash through the UART1.
kUartRS232
@ kUartRS232
constant (0): select RS232 interface
Definition: uart.h:53
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
serinp1
uint8_t serinp1(void)
Receives one byte from the UART1.
serout0
void serout0(uint8_t send_data)
Sends one byte through the UART0.