interfacing rs232
DESCRIPTION
TRANSCRIPT
Interfacing RS232Interfacing RS232
What is RS232What is RS232RS means Recommended Standard.RS 232 uses both synchronous and
asynchronous communication.In microcontrollers like ATmel 89C51
asynchronous communication is used and it is called as UART – universal asynchronous receiver and transmitter
Interfacing RS232Interfacing RS232We need a driver to use the
RS232 with microcontrollerThat driver turned out to be
MAX232It is a16 PIN Ic which is used to
interface RS232 with any other devices.
The transmission speed in the RS232 is called as baud rate.
Interfacing microcontroller with Interfacing microcontroller with RS232 standard devicesRS232 standard devices
Setting serial portSetting serial portIn microcontroller there are some
special function registers which are allocated to control the serial communication
The list of registers which is used to control the serial port are ◦SCON◦PCON◦SBUF
Double the baud rateDouble the baud rateThe baud rate standards are
1200 2400 4800 9600
But we can manually increase the baud rate into double the normal baud rate by setting the SMOD bit
SMOD bit is located in PCON register.
How to calculate baud How to calculate baud raterateIt is all depend upon the frequencyOur frequency is 11.0592MHzAtmel has 12 Tcycles for a machine
cycleEvery instruction except branch
instructions, execute in one machine cycle
To obtain the speed of operation we have to use the timers again. Unlike the previous classes, timers will be used to generate speed here.
Speed calculationSpeed calculation
11.0592M/12 = 921600921600/32 = 28800 here 32 is the
division factor it can be changed to 16 by setting SMOD bit
28800/?? = speedTo get required speed we have to
choose the value and store it in timer registers
For example: for 9600 the value is 3. in TH1 it will be FD ie., 256-3=253FD
Normal baud rate and double Normal baud rate and double the normal baud ratethe normal baud rateSMOD = 0 SMOD = 1
1200 24002400 48004800 96009600 19200
Transmit and ReceiveTransmit and ReceiveEvery thing is depends upon the
interrupt when it comes to microcontroller, it is true that serial communication is not an exceptional for this.
Transmit interrupt(TI) and receive interrupt(RI) are the two interrupt that control that operation of the serial communication
Transmission of data Transmission of data Data can be store in the BUFFER
assigned for serial communication(SBUF)
Transmission will be complete when the transmit buffer is empty
After acknowledging the transmit interrupt enabled due to empty transmit buffer we can reset the TI and continue the next transmission
Example for transmissionExample for transmissionConsider a letter A is going to be
send through serial communication
Then the coding should be
SBUF=‘A’;While(TI==0);TI=0;
Receive operationReceive operationIt is reverse of the transmit
operationThe interrupt for the receive will
be enabled when the receive buffer is full
After receiving the acknowledgment of the receive complete the value can be read from BUFFER (SBUF)
Example for receive dataExample for receive dataConsider a ‘A’ is send to
microcontroller through the serial port
The program logic is
While(RI==0);Read=SBUF;RI=0;
Programming serialProgramming serialIt is the same as all the
interfacing with microcontrollerFunctions to solve the problemSince we not only receive or send
a character but a lot of characters.
Therefore a function will make it easy to get and send all the data we required.
Assignments Assignments Send your name in serial portGet a data from serial portTry work with different baud rateGet a floating point from serial
port and manipulate it and print in LCD(round off the floating point data)