SERIAL TX:
void main()
{
UART1_Init(9600); // Initialize UART module at 9600 bps
DELAY_ms(100);
DDRB= 0X00; // Set PORTB as input
DDRC= 0XFF; // Set PORTC as output
do {
if (Button(&PINB, 0, 1, 1)) { // Detect logical one
UART1_Write_TEXT("V");
}
else if (Button(&PINB, 1, 1, 1)) { // Detect logical one
UART1_Write_Text("I");
}
else if (Button(&PINB, 2, 1, 1)) { // Detect logical one
UART1_Write_Text("S");
}
else if (Button(&PINB, 3, 1, 1)) { // Detect logical one
UART1_Write_Text("I");
}
else if (Button(&PINB, 4, 1, 1)) { // Detect logical one
UART1_Write_Text("O");
}
else if (Button(&PINB, 5, 1, 1)) { // Detect logical one
UART1_Write_Text("N");
}
PORTC = ~PORTC;
} while(1); // Endless loop
}
SERIAL RX:
// LCD module connections
sbit LCD_RS at PORTD2_bit;
sbit LCD_EN at PORTD3_bit;
sbit LCD_D4 at PORTD4_bit;
sbit LCD_D5 at PORTD5_bit;
sbit LCD_D6 at PORTD6_bit;
sbit LCD_D7 at PORTD7_bit;
sbit LCD_RS_Direction at DDD2_bit;
sbit LCD_EN_Direction at DDD3_bit;
sbit LCD_D4_Direction at DDD4_bit;
sbit LCD_D5_Direction at DDD5_bit;
sbit LCD_D6_Direction at DDD6_bit;
sbit LCD_D7_Direction at DDD7_bit;
// End LCD module connections
unsigned long int uart_rd;
void main() {
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (UART1_Data_Ready()==1) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
Lcd_chr(1,1,uart_rd); // and send data via UART
Lcd_chr(2,1,uart_rd); // and send data via UART
}}}