SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
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

}

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Kürzlich hochgeladen (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

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 }