Serial Communication Using AVR Lab 8 PDF
Serial Communication Using AVR Lab 8 PDF
DB9 Female (Front View) Serial Control (SCON) SFR (Bit Addressable)
Bit# 7 6 5 4 3 2 1 0 Name SM0 SM1 SM2 REN TB8 RB8 TI RI Description Serial port mode bit 0 Serial port mode bit 1 Multiprocessor Communications Enable (explained later) Receiver Enable. This bit must be set in order to receive characters Transmit bit 8. The 9th bit to transmit in mode 2 and 3 Receive bit 8. The 9th bit received in mode 2 and 3 Transmit Flag. Set when a byte has been completely transmitted Receive Flag. Set when a byte has been completely received Page 27
Lab 08: Serial Communication between PC & Microcontroller Explanation 8-bit Shift Register 8-bit UART 9-bit UART 9-bit UART Baud Rate Oscillator / 12 Set by Timer 1 (*) Oscillator / 64 (*) Set by Timer 1 (*)
Following table shows some standard baud rates used for serial communication. Right most column shows the value of higher byte of timer 1, to generate the respective baud rate. Baud Rate 9600 4800 2400 1200 Crystal Freq 11.0592 MHz 11.0592 MHz 11.0592 MHz 11.0592 MHz TH1 decimal -3 -6 -12 -24 TH1 Hex FD FA F4 E8
To calculate the value of TH1 for a required baud rate, following formula can also be used:
We can double the Baud Rate by setting high the SMOD (LSB, D7) bit of PCON register. When 8051 is powered up, SMOD bit is zero so Baud Rate is generated on normal speed. Steps to receive a character through UART of 8051: 1. Configure SCON SFR to Mode 1 and enable the reception through REN bit. 2. Configure Timer 1 to 8 bit auto-reload mode by assigning appropriate value to TMOD SFR 3. Load TH1 and TL1 with a value given in theTH1 Hex column of above table for a required baud rate generation. 4. Set ES and EA bits in IE SFR to enable serial port and global interrupts 5. Start the Timer 1 by setting TR1 bit of TCON register. 6. Reset the RI bit of SCON SFR 7. Check for RI flag. 8. When RI goes up, copy the received byte from SBUF register and move it to a safe location. 9. Now reset the RI flag to enable reception of another byte.
Steps to transmit a character from UART of 8051: 1. There is no need to configure the serial port again from step 1 to 5. These steps are required to be configured only one time. 2. Reset TI flag of SCON SFR 3. Put the character in SBUF for start of transmission. When a character is copied into SBUF, transmission is started immediately. 4. Wait until TI flag is raised, which indicates that complete byte has been transmitted. 5. Now reset the TI flag and repeat the step 3 to transmit another byte. Steps to configure the PC for serial communication using RS232: Latest PCs / Laptops does not contain the serial ports. For serial communication on these PCs, we can use the USB to Serial converter which are easily available in the market. All you need to do is
Page 28
to attach the USB to serial converter into the serial port of your PC and the other end of converter cable can be used as serial interface. Generally, Hyper Terminal is the software used for serial communication which is not available in the Windows 7 and Windows 8. You can download the free Hyper Terminal from: http://files.digitizor.com/wp-content/uploads/2009/08/hyperterminal1.zip Make sure you keep the files hypertrm.dll and hypertrm.exe in the same folder. Now you can launch the HyperTerminal client by double clicking the hypertrm.exe. After running this file, Location Information window will appear. You can cancel this windows and proceed. Next, Connection Description windows will appear:
Enter new connection name and press OK. Now, Connect To window will appear. Here, you should select COM1 (or your available COM Port number) in Connect Using field and press OK
Page 29
In the following window, select the baud rate (Bits per second), Data bits, Parity, Stop Bit and Flow control as per the settings done while programming the USART of 8051. Normally, we keep the flow control None. After pressing OK, your connection would be established. Now you can transmit or receive from PC to microcontroller or from microcontroller to PC.
At this stage when you will type a letter on the hyper terminal, it will not be shown. You can see your typed character by navigation to the following setting: File -> Properties -> Setting -> ASCII Setup -> and there you can enable the option of Echo typed characters locally by checking the check box.
Page 30
Page 31