Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save urmil0071/9f5b79a715d1e76db8e4291571dedc5c to your computer and use it in GitHub Desktop.
Save urmil0071/9f5b79a715d1e76db8e4291571dedc5c to your computer and use it in GitHub Desktop.
(INCOMPLETE) Standard C++ Codes for Data Exchange between Arduino UART and PC (Polling Method)
#include <Arduino.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(5,0);
pinMode(13,OUTPUT);
bitWrite(UCSR0B,4,1); /// L11 : PDO as RXD
bitWrite(UCSR0B,3,1); /// L12 : PD1 as TXD
bitWrite(UCSR0C,6,0); ///UMSEL1 = 0
bitWrite(UCSR0C,7,0); /// UMSEL1 = 0 : SET ASYNCHRONUS MODE
UBRR0H=0x00;
UBRR0L=0xCF; /// SELECTED 4800 BAUD
bitWrite(UCSR0B,2,0);
bitWrite(UCSR0C,2,1);
bitWrite(UCSR0C,1,1); /// 8 data bit
/// Send A by polling UDRE0
while(bitRead(UCSR0A,5) !=HIGH) ///L16: Wait for TX To be empty
{
}
UDR0=0x41; ///ASCII of A written on TX Register
while(bitRead(UCSR0A,5)!=HIGH)
{
}
UDR0=0x0D; /// CARRIAGE RETURN CODE
while(bitRead(UCSR0A,5) !=HIGH)
{
}
UDR0 = 0x0A; ///LINE FEED
while(bitRead(UCSR0A,7) !=HIGH) ///WAIT RXC0 to get high
{
}
byte x1=UDR0; /// Read Data
lcd.write(x1); /// Show On LCD
///SEND A by polling TXC0
lcd.setCursor(5,1);
bitWrite(UCSR0A,6,1); /// Make TX Register Ready to Recieve data by Making TXC0 Reset (LOGIC HIGH RESETS IT)
while(bitRead(UCSR0A,6) !=HIGH)
{
} /// Wait for TXC0 To get high
UDR0=0x41; /// L18C : ASCII For A
while(bitRead(UCSR0A,5)!=HIGH)
{
}
UDR0=0x0D; /// CARRIAGE RETURN CODE
while(bitRead(UCSR0A,5) !=HIGH)
{
}
UDR0 = 0x0A; ///LINE FEED
while(bitRead(UCSR0A,7) !=HIGH) ///WAIT RXC0 to get high
{
}
byte x2=UDR0; /// Read Data
lcd.write(x2); /// Show On LCD
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment