Spread the love

serial communication of  ATmega16

____________________________________________________________________________________________________

  • What is serial COM ?-   A computer transfers data by two methods called serially and parallelly, both have its own merits and demerits according to application. Here we discuss only about serial communication. In serial com data are transfers bit by bit from transmitter to receiver.

 

type of serial communication

  • About & Types serial COM-
  1. If data transmitted one way a time, it is referred to as half duplex.
  2. If data can go both ways at a time, it is full duplex.

connectors  used in SERIAL COMMUNICATION OF ATmega16400px-RS232-TTL_Converter

Following are the pin connectors that are used to connect microcontroller with PCs.

  • Serial data communication uses two methods:
  1. 1.  Synchronous method transfers a block of data at a time
  2. Asynchronous method transfers a single byte at a time
  • Asynchronous serial data communication is widely used for character-oriented transmissions

(1)     Each character is placed in between start and stop bits, this is called framing (8-bit = single character)

(2)     Block-oriented data transfers use the synchronous method

  • The start bit is always one bit, but the stop bit can be one or two bits. Due to the extended ASCII Characters, 8-bit ASCII data is common. In modern PCs, the use of one stop bit is standard. Assuming that we are transferring a text file of ASCII characters using 1 stop bit, we have a total of 10 bits for each character including 8 character with 1 start and 1 stop bit.
  •  The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate.  It is modem terminology and is defined as the number of signal changes per second. In modems, there are occasions when a single change of signal transfers several bits of data.
  • The data transfer rate of given computer system depends on communication ports incorporated into that system
    • IBM PC/XT could transfer data at the rate of 100 to 9600 bps
    • Pentium-based PCs transfer data at rates as high as 56Kbps
    • In asynchronous serial data communication, the baud rate is limited to 100Kbps
  • In RS232 protocol, a 1 is represented by -3  to -25 V, while a 0 bit is +3  to  +25 V, making -3 to +3 undefined and support TTL logics.
  • Microcontroller used CMOS logics generally, so we need a line driver such as the MAX232 chip which is required to convert RS232 voltage levels to CMOS levels, and vice versa.
  • Following diagram is shown interfacing diagram of ATmega32 with PC and use of MAX232 IC.

 MRI-PCIDS

  • To allow data transfer between the PC and an microcontroller system without any error, we must make sure that the baud rate of microcontroller system matches the baud rate of the PC’s COM port.
  • Applications-  Communication between computer and microcontroller.

Click Here : Understanding of RS232 protocol and setting up baud rate

Click Here : Registers used in serial com programming

 

1. Circuit Diagram Of  serial communication of  ATmega16

serial communication of  ATmega16

 2. Circuit Diagram Of  serial communication of  ATmega16 With LCD

 Circuit Diagram Of serial communication of  ATmega16 With LCD

 

_______________________________________________________________________________________________________

 

1. Program of  serial communication of  ATmega16 

In this program controller send “www.firmcodes.com” to PC or Laptop and it will display on the hyper terminal of PC or Laptop

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CONTROLLER SEND "FIRMCODES.COM" TO PC BY RS232 PROTOCOL
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

void delay(int x);
void serial_ini();
void serial_transmit(unsigned char x);
unsigned char temp;

int main()
    {
        serial_ini();
        while(1)
          {
                         serial_transmit('W');  //  call transmit function 
                         delay(100);           // calling of delay function
                         serial_transmit('W');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('W');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('.');  //  call transmit function
                         delay(100);           // calling of delay function
                         serial_transmit('F');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('I');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('R');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('M');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('C');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('O');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('D');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('E');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('S');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('.');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('C');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('O');  //  call transmit function
                         delay(100);          // calling of delay function
                         serial_transmit('M');  //  call transmit function
                         delay(100);          // calling of delay function
                        serial_transmit(0x0d);  //  call transmit function
                        delay(400);
                        delay(400);

          }
        return 0;
   }

void serial_ini()
  {
     UCSRB=(1<<TXEN)|(1<<RXEN);
     UCSRC=(1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
     UBRRL=0X33; 
  }


void serial_transmit(unsigned char x)
  {
     while(!(UCSRA & (1<<UDRE)));
     UDR= x; 
     while(TXC ==0);
  }
  
void delay(int x)
   {
        x=x*2;
        _delay_ms(x);
   }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

_______________________________________________________________________________________________________

2. Program of  serial communication of  ATmega16  with LCD 

In this program data entered from the hyper terminal of PC or Laptop is appeared on the LCD connected to the controller

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- DATA SEND FROM PC DISPLAYED ON LCD CONNECTED  TO ATMEGA16
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

void serial_ini();
char serial_re();

unsigned char temp;

#define lcd PORTA

void cmd(unsigned char x);
void lcd_display(unsigned char x);
void lcd_ini();

int main()
   {
      int i=0;
      DDRA=0XFF;
      DDRB=0XFF;
      serial_ini();
      lcd_ini();
      while(1)
        {
            i++;
            serial_re();
            lcd_display(temp);
            if(i==16)
               cmd(0xc0);
            else if(i==32)
               {
                   i=0;
                   cmd(0x01);
                }
         }
      return 0;
   }

void serial_ini()
   {
       UCSRB=(1<<TXEN)|(1<<RXEN);
       UCSRC=(1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
       UBRRL=0X33;
   }

char serial_re()
   {
       while((UCSRA & (1<<RXC))==0);
       temp=UDR;
       return temp;
   }

void cmd(unsigned char x)
   {
       lcd=x;
       PORTB=(0<<0);
       PORTB=(0<<1);
       PORTB=(1<<2);
       _delay_ms(10);
       PORTB=(0<<2);

   }

void lcd_display(unsigned char x)
  {
      lcd=x;
      PORTB=(1<<0);
      PORTB=(0<<1)|(1<<0);
      PORTB=(1<<2)|(0<<1)|(1<<0);
      _delay_ms(20);
      PORTB=(0<<2)|(0<<1)|(1<<0);
  } 

void lcd_ini()
  {
     cmd(0x38);
     cmd(0x0e);
     cmd(0x01);
     cmd(0x06);
     cmd(0x80);
  }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

_______________________________________________________________________________________________________

Content for the tab VIDEO