Module 3
Module 3
Module 3
M3.01 Illustrate the interfacing of Serial Port, LCD and Keyboard Interfacing.
M3.02 Illustrate the interfacing of ADC, DAC and Sensors.
Contents:
Interfacing: ATMega32 Connection to RS232, Serial Port Programming in C, LCD Interfacing,
Keyboard Interfacing, ADC, DAC and Sensor interfacing and Programming in C.
• Serial communication is used for transferring data between two systems located at distances
of hundreds of feet to millions of miles apart.
• For long-distance data transfers, serial data communication requires a modem to modulate
(convert from Os and 1s to audio tones) and demodulate (convert from audio tones to Os
and 1s).
• Serial data communication uses two methods:
✓ Asynchronous
✓ Synchronous.
• The synchronous method transfers a block of data (characters) at a time, whereas the
asynchronous method transfers a single byte at a time.
• Special IC chips are made by many manufacturers for serial data communications.
• These chips are commonly referred to as UART(universal asynchronous receiver
transmitter) and USART(universal synchronous asynchronous receiver-transmitter).
• The AVR chip has a built-in USART.
• Data transmission methods are:
◦ Duplex – Data can be both transmitted and received.Duplex transmissions can be half or
full duplex.Half duplex – Data is transmitted one way at a time.Full duplex – Data can
go both ways at the same time.
◦ Simplex – only sends data.
RS232 standards
• RS232 is one of the most widely used serial I/O interfacing standards.
• it is used in PCs and numerous types of equipment.
• Different versions- RS232A, RS232B, RS232C.
• Voltage representation-:1 is –3 to -25, 0 is +3 to +25
• -3 to +3 are undefined. For this reason, to connect RS232 to a microcontroller, we use a
voltage converter. e.g.MAX232 IC.
• This IC is commonly known as line driver.
• RS232 cables nad labels are commonly referred as DB-25 connector.
• The simplest connection between a PC and a microcontroller requires minimum 3 pins-
TX,RX and ground.
• The ATmega32 has two pins that are used specifically for transferring and receiving data
serially.
• These two pins are called TX and RX and are part of the PortD group (PD0 and PD1) of the
40-pinpackage.
• Pin15 of the ATmega32 is assigned to TX and pin 14 is designated as RX.
MAX232
• The MAX232 converts from RS232 voltage levels to TTL voltage levels, and vice versa.
• One advantage of the MAX232 chip is that it uses a +5Vpower source, which is the same as
the source voltage fo r the AVR.
• The MAX232 has two sets of line drivers for transferring and receiving data.
• The line drivers used for TX are called T1 and T2 while the line drivers for RX are
designated as R1 and R2.
• It requires 4 capacitors ranges from 0.1 to 22microfarad.
UCSRC register
UBRR register
• the value loaded into the UBRR decides the baud rate.
• Desired baud rate= fosc/16(X+1), where fosc- frequency of oscillator connected to the
XTAL1 and XTAL2, X-value loaded into the UBRR register.
Program
LCD INTERFACING
• In recent years the LCD is finding wide spread use replacing LEDs (seven segment LEDs or
other multisegment LEDs). This is due to the following reasons:
1. The declining prices of LCDs.
2. The ability to display numbers, characters, and graphics. This is in contrast to LEDs, w h i
c h are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, there by relieving the CPU of the
task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU (or in some other
way) to keep displaying the data.
4.Ease of programming for characters and graphics.
LCD pin descriptions
• LCD has 14pins..
• The function of each pins are:
D0-D7
• The 8-bit data pins, DO-D7,are used to send information to the LCD or read the contents of
the LCD's internal registers.
#include<avr/io.h>
#include<util/delay.h>
unsigned char key[4][3]={‘1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’,’0’,’*’,’#’};
int main(void)
{
unsigned char col,row;
DDRD=0xFF; //portd as output
DDRC=0xF8; //PC4-PC7 as output, PC@-PC0 as input
while(1)
{
do
{
PORTC=0x07; //ground all rows
col=PINC&0x07; //read columns
}while(col!=0x07);
while(1)
{
PORTC=0xEF; // ground PC4, row=0
col=PINC&0x07; // read the column
if(col!=0x07) // if key is pressed this row
{
row=0; break; // assign row value and break from the loop
}
if(col==0x06) // col==0(PC2=0)
{
PORTD=key[row][0];
}
else if(col==0x05) // col==0(PC1=0)
{
PORTD=key[row][1];
}
else // col==2(PC0=0)
{
PORTD=key[row][2];
}
}
}
return 0;
}
ADC(Analog to Digital Converter)
• ADC converts the analog signal to digital number.
• These are most widely used device for data acquisition.
• Transducer is a device that converts the physical quantity to electrical signal.
• Characteristics of ADC
1) resolution – high resolution ADC provide a smaller step size. Step size is the smallest
change that can be discerned by an ADC.
2) Conversion time- time it takes the ADC to convert the analog input to digital
3) vref- reference voltange. Range is 0 to 5V
4) digital data output- 8 bit ADC has 8 bit digital data output.
5) Analog input channels- 16 ADC channels
1. 10 bit ADC
2. 8 input channels,7 differential input channels and 2 differential input channels with optiona gain
of 10x & 200X
3. 2 special function register- ADCL and ADCH. These are 8 bit each.
4. we have the option of making eithe upper 6 bits or lower 6 bits of ADCL:ADCH register unused.
5. Vref can be- Analog VCC, internal 2.56V,external AREF pin
6. conversion time is dictated by the crystal frequency(Fosc pin),and ADP0:2 bits
Hardware considerations
ADC programming in C
ADCH:ADCL
• result is stored in ADCL and ADCH register.
ADCSRA
ADMUX
ADC connection
program
sensors
• a transducer that converts temperature to electrical signal called thermistor.
• A thermistor responds to temperature change by changing resistance.
• Its response is not linear.
• Simple and widely used temperature sensors are- LM34 &LM35
LM34
• precision integrated- circuit temperature sensor
• output is in fahrenheit temperature
• requires no external calibration
• for each fahrenheit, its output is 10mv
LM35
• precision integrated- circuit temperature sensor
• output is in celsius temperature
• requires no external calibration
• for each celsius temperature, its output is 10mv
Interfacing LM34 to atmega32
program
important questions
1. explain the interfacing of LCD.
2. illustrate the interfacing of Keyboard.
3. explain the registers related to USART interface.
4. differentiate LM34 and LM35.
5. Explain DAC .
6. Explain the interfacing of ADC.
7. what do you mean by sensors.
8. explain the pin description of LCD.
9. explain the ADC features of ATMega32.
10.Explain RS232.
Video links
1. serial communication-https://www.youtube.com/watch?v=PE8n5oSfRBc,
https://www.electronicwings.com/avr-atmega/atmega1632-usart
2.LDC interfacing-https://www.youtube.com/watch?v=rp9EIwFuv4g
3. keyboard interfacing-https://www.youtube.com/watch?v=3jMoF9HPChw
4. ADC interfacing-https://www.youtube.com/watch?v=QFD6D4fhTc8
5.DAC interfacing-
6. sensors-https://www.youtube.com/watch?v=q5hn0O6czJU
onword questions
1. what voltage levels are used for binary 0 in RS232.
2.true or false. The AVR has a built in UART.
3. what is the advantage of MAX233 over the MAX232 chip?
4. which registers of the AVR are used to set te baud rate?
5. UCSRA stands for........................
6. the E pin requires an ........................pulse to latch in information at the data pins of LCD.
7. what is the difference between Vcc and Vee pin on the LCD.
8.what is the internal Vref of the Atmega32.
9. how many single ended inputs are available in the Atmega32 ADC?
10. the LM34 sensor produces .......mv for each degree of temperature.
11. in the Atmega32, what should the Vref value if we want a step size of 2mv.