Interface the Atmega 16/32 with the PC

May 18, 2009 at 20:19 (microcontroller, Uncategorized)

There are many ways to interface your microcontroller to computer , the most easiest way is using serial port and MAX-232.In this tutorial is about how to interface a ATMEGA32 to your computer using serial  port , max232 and programming the atmega32 using CodeVisionAVR.

INTRODUCTION:

ATMEGA32 is a 8-bit AVR microcontroller with 32K Bytes In-system Programmable Flash. In Atmega32pins pin no.14 and 15 are RxD and TxD resp. For basics of atmega32 click here

SERIAL PORT:

In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time.Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals and various peripherals.

MAX232: As we know for serial port we require TIA/EIA-232-F voltage level i.e. it can accept ±30-V. MAX232 has a capacitive voltage generator to supply TIA/EIA-232-F voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F inputs to 5-V TTL/CMOS levels.

So, to interface the atmega32 to the computer we will be connecting atmega32 (pin no 14 & 15) to serial port via max232. We are using max232 because atmega32 works at TTL voltage level and for serial port we require other voltage level, max232 converts the TTL voltage level to the required voltage level.

Atmega32 will receive the signal from MAX232 and transmit to max232 which will be received by serial port. Do the following connections:

  1. connect pin no 2 (Tx) of serial port to Tx out of the MAX 232 IC (pin no 14)
  1. connect pin no 3 (Rx) of serial port to Rx in of the MAX 232 IC (pin no 13)
  2. connect pin no 14 (RxD) of Atmega to Rx out of MAX 232 IC (pin no 12)
  3. connect pin no 15 (TxD) of Atmega to Tx in of MAX 232 IC (pin no 11)
  4. Do other necessary connections like ground and Vcc.

PROGRAMMING:

  1. By selecting UART tab of the CodeWizardAVR , you can specify the UART configuration
  2. Specify the baud rate and communication parameter.
  3. Click on save, generate and exit.
  4. Write the code.
  5. Burn the program.
  6. Open the terminal in CodeVisionAVR TOOL—-à TERMINAL (shift + F5).
  7. Specify the baud rate and communication parameter.(ensure that you specify the same parameter which you have specify in step 2)
  8. In terminal you monitor the whole operation.

uart

NOTE: instead of terminal of CodeVisionAVR you can use other software like DockLight.

It allows us to specify the following communication modes:

  • Asynchronous
  • Synchronous Master, with the UCSRC register’s UCPOL bit set to 0
  • Synchronous Master, with the UCSRC register’s UCPOL bit set to 1
  • Synchronous Slave, with the UCSRC register’s UCPOL bit set to 0
  • Synchronous Slave, with the UCSRC register’s UCPOL bit set to 1

The serial communication is realized using the Standard Input/Output Function getchar , gets , scanf , putchar , puts and printf.

SAMPLE PROGRAM:

If we want to write program in which, when button ‘a’ on keyboard is pressed then all the LED connected to PORTA should be ON , when button ‘s’ is pressed all LED should be OFF.

#include <mega32.h>

#include <stdio.h> // Standard Input/Output functions

Void main()

{

DDRA=0xFF;

PORTA=0x00;

// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud Rate: 9600

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

while (1)

{

if (getchar() == ‘a’)

{

PORTA=0x11111111;

}

if (getchar() == ‘b’)

{

PORTA=0x00;

}

};

}

In this way you can interface your ATMEGA32 to your computer. In similar way you can control the motor (in semi-autonomous BOT).

u can also view this post @  http://expertscolumn.com/content/interface-atmega-1632-pc

………………….if you found this tutorial helpful or have any suggestions … do leave a comment.

Permalink 30 Comments