SlideShare une entreprise Scribd logo
1  sur  4
Télécharger pour lire hors ligne
Receive.c

/* Since we never know when we are going to get data, we write a
Interrupt Routine that will execute on receiving data.
   You can write different conditions depending on your convenience to
test whether data reception is complete and also
   whether it is accurate
*/


#include <avr/io.h>
#include <avr/interrupt.h>

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

void initusart(void);                                  // Set the baud
rate ( communication speed in bits per second)

int i=0;                        // Global variable acts as a counter

unsigned char str[8];     // String to be sent, declared global if to be
used in interrupts

int main (void)
{
      DDRA=0xff;        // Initialise all ports
      DDRC=0xff;
      DDRB=0xff;
      DDRD=0X00;        // Set PORTD for input, since it contains RX and
TX pins
      PORTB=0x00;       // Set all ports
      PORTC=0xff;
      PORTA=0x01;
      PORTD=0XFF;       // Pull up PORTD
      initusart();      // Initialise USART
      while(1);         // Infinite loop to keep the program running
      }



ISR(USART_RXC_vect)
{
      PORTC -= 0x01;         // Decrement PORTC by one
      str[i]=UDR;            // Load the character in the receive buffer
to string variable
      if (str[6]=='g') { PORTC=0x00;}   // Condition to test accuracy of
last variable
      i++;                   // Increment counter to read next character

}


void initusart(void)
{
   UCSRB |= (1 << RXEN);                                 // Turn on the
transmission and reception circuitry
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit
character sizes
   UBRRL = BAUD_PRESCALE;         // Load lower 8-bits of the baud rate
value into the low byte of the UBRR register

   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate
value into the high byte of the UBRR register
   UCSRB |= (1 << RXCIE);                                // Enable the
USART Recieve Complete interrupt (USART_RXC)
   sei();                         // Enable global interrupts, necessary
if you want to use ANY interrupt

}
Transmit.c

/* The execution of the code below is such: After initialising USART, I
call a send function to transmit the character.
    An interrupt is triggered on completion, the counter goes to the next
character and calls the send function. So,
    the exectution will be in the form of continuous loops and will enter
the main function only on completion of
    transmission of all characters
*/



#include <avr/io.h>
#include <avr/interrupt.h>

#define USART_BAUDRATE 9600                                // Set the
baud rate ( communication speed in bits per second)
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) //
Prescale factor,calculated automatically

void initusart(void);          // Function for USART initialisation

void send(void);               // Function to send characters

int i=0;                      // Global variable acts as a counter

unsigned char str[8]="Testing"; // String to be sent, declared global if
to be used in interrupts

int main (void)
{
   initusart();                         // Initialise USART
   send();                              // Call send function
   while(1);                            // Infinite loop to keep the
program running
   }

void send()
{ if (i<7)                              // Send the character only if i
is less than string size
      {
      UDR=str[i];                       // Loads the character into the
transmit buffer
      }

}


ISR(USART_TXC_vect)                     // Interrupt Service Routine,
fires on Transmit Complete (Tx C)
{
      i++;                              // Increments i to send next
character
UCSRA &= (0 << TXC);             // Clears the Transmit complete
flag, Do this to avoid errors
      send();                          // Call the send function again
}


void initusart(void)
{
   UCSRB |= (1 << TXEN);                                 // Turn on the
transmission and reception circuitry
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit
character sizes
   UBRRL = BAUD_PRESCALE;         // Load lower 8-bits of the baud rate
value into the low byte of the UBRR register

   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate
value into the high byte of the UBRR register
   UCSRB |= (1 << RXCIE);                                // Enable the
USART Transmit Complete interrupt (USART_TXC)
   sei();                         // Enable global interrupts, necessary
if you want to use ANY interrupt

}

Contenu connexe

En vedette

What Is Literary Criticism[1]2
What Is Literary Criticism[1]2What Is Literary Criticism[1]2
What Is Literary Criticism[1]2makeefer
 
Crew, FOIA,Documents 017782- 017823
Crew, FOIA,Documents 017782- 017823Crew, FOIA,Documents 017782- 017823
Crew, FOIA,Documents 017782- 017823Obama White House
 
Websense Hosted Email Security
Websense Hosted Email SecurityWebsense Hosted Email Security
Websense Hosted Email Securityfartur
 
Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09pageway
 
SADI SWSIP '09 'cause you can't always GET what you want!
SADI SWSIP '09  'cause you can't always GET what you want!SADI SWSIP '09  'cause you can't always GET what you want!
SADI SWSIP '09 'cause you can't always GET what you want!Mark Wilkinson
 
PPT母版_简约_v0.1
PPT母版_简约_v0.1PPT母版_简约_v0.1
PPT母版_简约_v0.1jiaqing zheng
 
Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Obama White House
 
The Abc’s of Dad And Me
The Abc’s of Dad And MeThe Abc’s of Dad And Me
The Abc’s of Dad And Mesunnymel20
 
The ABC's of Dad and Me
The ABC's of Dad and MeThe ABC's of Dad and Me
The ABC's of Dad and Mesunnymel20
 
F1inschools Design
F1inschools DesignF1inschools Design
F1inschools DesignKry Said
 
The Scientific Method on the Semantic Web
The Scientific Method on the Semantic WebThe Scientific Method on the Semantic Web
The Scientific Method on the Semantic WebMark Wilkinson
 
Tutorial - Creating SADI semantic-web-services
Tutorial - Creating SADI semantic-web-servicesTutorial - Creating SADI semantic-web-services
Tutorial - Creating SADI semantic-web-servicesMark Wilkinson
 
Dump The Tubes The Economic Case For Led Backlighting Revised
Dump The Tubes   The Economic Case For Led Backlighting   RevisedDump The Tubes   The Economic Case For Led Backlighting   Revised
Dump The Tubes The Economic Case For Led Backlighting Revisedandyclark
 
Chase Oaks VBX - Monday - Greatness of the Journey
Chase Oaks VBX - Monday - Greatness of the JourneyChase Oaks VBX - Monday - Greatness of the Journey
Chase Oaks VBX - Monday - Greatness of the JourneyJason Loveless
 
Crew documents 020549 - 020563
Crew documents 020549 - 020563Crew documents 020549 - 020563
Crew documents 020549 - 020563Obama White House
 
VC_flier_HYD.compressed
VC_flier_HYD.compressedVC_flier_HYD.compressed
VC_flier_HYD.compressedSuneel Sharma
 
AGUILAS 2009
AGUILAS 2009AGUILAS 2009
AGUILAS 2009paobazzi
 
Almost vs San Juan2009
Almost vs San Juan2009Almost vs San Juan2009
Almost vs San Juan2009paobazzi
 

En vedette (20)

What Is Literary Criticism[1]2
What Is Literary Criticism[1]2What Is Literary Criticism[1]2
What Is Literary Criticism[1]2
 
Crew, FOIA,Documents 017782- 017823
Crew, FOIA,Documents 017782- 017823Crew, FOIA,Documents 017782- 017823
Crew, FOIA,Documents 017782- 017823
 
Websense Hosted Email Security
Websense Hosted Email SecurityWebsense Hosted Email Security
Websense Hosted Email Security
 
Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09Rest In Peace Tribute Tour 7 23 09
Rest In Peace Tribute Tour 7 23 09
 
SADI SWSIP '09 'cause you can't always GET what you want!
SADI SWSIP '09  'cause you can't always GET what you want!SADI SWSIP '09  'cause you can't always GET what you want!
SADI SWSIP '09 'cause you can't always GET what you want!
 
PPT母版_简约_v0.1
PPT母版_简约_v0.1PPT母版_简约_v0.1
PPT母版_简约_v0.1
 
Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236Crew, Foia, Documents 008159 - 008236
Crew, Foia, Documents 008159 - 008236
 
The Abc’s of Dad And Me
The Abc’s of Dad And MeThe Abc’s of Dad And Me
The Abc’s of Dad And Me
 
The ABC's of Dad and Me
The ABC's of Dad and MeThe ABC's of Dad and Me
The ABC's of Dad and Me
 
F1inschools Design
F1inschools DesignF1inschools Design
F1inschools Design
 
The Scientific Method on the Semantic Web
The Scientific Method on the Semantic WebThe Scientific Method on the Semantic Web
The Scientific Method on the Semantic Web
 
Tutorial - Creating SADI semantic-web-services
Tutorial - Creating SADI semantic-web-servicesTutorial - Creating SADI semantic-web-services
Tutorial - Creating SADI semantic-web-services
 
Dump The Tubes The Economic Case For Led Backlighting Revised
Dump The Tubes   The Economic Case For Led Backlighting   RevisedDump The Tubes   The Economic Case For Led Backlighting   Revised
Dump The Tubes The Economic Case For Led Backlighting Revised
 
Chase Oaks VBX - Monday - Greatness of the Journey
Chase Oaks VBX - Monday - Greatness of the JourneyChase Oaks VBX - Monday - Greatness of the Journey
Chase Oaks VBX - Monday - Greatness of the Journey
 
Crew documents 020549 - 020563
Crew documents 020549 - 020563Crew documents 020549 - 020563
Crew documents 020549 - 020563
 
Alfresco企业内容管理标准方案
Alfresco企业内容管理标准方案Alfresco企业内容管理标准方案
Alfresco企业内容管理标准方案
 
VC_flier_HYD.compressed
VC_flier_HYD.compressedVC_flier_HYD.compressed
VC_flier_HYD.compressed
 
AGUILAS 2009
AGUILAS 2009AGUILAS 2009
AGUILAS 2009
 
Pysec
PysecPysec
Pysec
 
Almost vs San Juan2009
Almost vs San Juan2009Almost vs San Juan2009
Almost vs San Juan2009
 

Similaire à USART

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controllerSyed Ghufran Hassan
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver艾鍗科技
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docxajoy21
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScriptJens Siebert
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-programDimz I
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)Omkar Rane
 
Radix 2 code
Radix 2 codeRadix 2 code
Radix 2 codepradipakv
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Vikas Dongre
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfarmyshoes
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfamarnathmahajansport
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingDemetrio Siragusa
 
TCP IP
TCP IPTCP IP
TCP IPhivasu
 
CC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleCC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleAarya Technologies
 
Gsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerGsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerYonas Andualem
 

Similaire à USART (20)

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Uart
UartUart
Uart
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
 
Radix 2 code
Radix 2 codeRadix 2 code
Radix 2 code
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
UART
UARTUART
UART
 
Please fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdfPlease fill in the code to run the program based on the following in.pdf
Please fill in the code to run the program based on the following in.pdf
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
 
TCP IP
TCP IPTCP IP
TCP IP
 
Product catlog
Product catlogProduct catlog
Product catlog
 
CC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleCC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver Module
 
USART.pptx
USART.pptxUSART.pptx
USART.pptx
 
Gsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontrollerGsm modem interfacing with pic microcontroller
Gsm modem interfacing with pic microcontroller
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

USART

  • 1. Receive.c /* Since we never know when we are going to get data, we write a Interrupt Routine that will execute on receiving data. You can write different conditions depending on your convenience to test whether data reception is complete and also whether it is accurate */ #include <avr/io.h> #include <avr/interrupt.h> #define USART_BAUDRATE 9600 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) void initusart(void); // Set the baud rate ( communication speed in bits per second) int i=0; // Global variable acts as a counter unsigned char str[8]; // String to be sent, declared global if to be used in interrupts int main (void) { DDRA=0xff; // Initialise all ports DDRC=0xff; DDRB=0xff; DDRD=0X00; // Set PORTD for input, since it contains RX and TX pins PORTB=0x00; // Set all ports PORTC=0xff; PORTA=0x01; PORTD=0XFF; // Pull up PORTD initusart(); // Initialise USART while(1); // Infinite loop to keep the program running } ISR(USART_RXC_vect) { PORTC -= 0x01; // Decrement PORTC by one str[i]=UDR; // Load the character in the receive buffer to string variable if (str[6]=='g') { PORTC=0x00;} // Condition to test accuracy of last variable i++; // Increment counter to read next character } void initusart(void)
  • 2. { UCSRB |= (1 << RXEN); // Turn on the transmission and reception circuitry UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC) sei(); // Enable global interrupts, necessary if you want to use ANY interrupt }
  • 3. Transmit.c /* The execution of the code below is such: After initialising USART, I call a send function to transmit the character. An interrupt is triggered on completion, the counter goes to the next character and calls the send function. So, the exectution will be in the form of continuous loops and will enter the main function only on completion of transmission of all characters */ #include <avr/io.h> #include <avr/interrupt.h> #define USART_BAUDRATE 9600 // Set the baud rate ( communication speed in bits per second) #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) // Prescale factor,calculated automatically void initusart(void); // Function for USART initialisation void send(void); // Function to send characters int i=0; // Global variable acts as a counter unsigned char str[8]="Testing"; // String to be sent, declared global if to be used in interrupts int main (void) { initusart(); // Initialise USART send(); // Call send function while(1); // Infinite loop to keep the program running } void send() { if (i<7) // Send the character only if i is less than string size { UDR=str[i]; // Loads the character into the transmit buffer } } ISR(USART_TXC_vect) // Interrupt Service Routine, fires on Transmit Complete (Tx C) { i++; // Increments i to send next character
  • 4. UCSRA &= (0 << TXC); // Clears the Transmit complete flag, Do this to avoid errors send(); // Call the send function again } void initusart(void) { UCSRB |= (1 << TXEN); // Turn on the transmission and reception circuitry UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register UCSRB |= (1 << RXCIE); // Enable the USART Transmit Complete interrupt (USART_TXC) sei(); // Enable global interrupts, necessary if you want to use ANY interrupt }