Unit - 5
Serial port Structure in 8051
Q1) Explain the Serial port structure in 8051.
A1) The format of SCON register is shown
o In this mode the serial port function as half duplex serial port with fixed baud rate.
o The 8- bit serial data is received and transmitted through RxD pin and the controller output the shift clock through TxD pin during reception and transmission.
o The baud rate is fixed at 1 / 12 of the oscillator frequency.
o In this mode the serial port function as full duplex serial port with variable baud rate.
o In this mode one data consists of 10 bits, which includes one start bit, eight data bit and one stop bit. During reception the stop bit is stored as RB8 in SCON register.
o Baud rate in mode-1 depends on the value of SMOD bit in PCON register and the timer1overflow rate.
o In this mode the serial port function as full duplex serial port with a baud rate of either 1/32 or 1/64 of the oscillator frequency.
o In this mode one data consists of 11 bits which includes one start bit, eight data bit, a programmable 9th data bit and one stop bit.
o During transmission the TB8 of SCON register is added as 9th data bit and during reception the 9th data bit is stored as RB8 in SCON register.
o The baud rate depends on the value of SMOD bit in PCON register.
o The mode-3 is same as mode-2, except the baud rate. o In mode-3, the baud rate is variable. The baud rate depends on the value of SMOD bit in PCON register and the timer- 1 overflow rate.
The serial mode bit-2 (SM2) has no effect in mode-0 and when programmed for mode-0, the SM2 should be equal to zero.
In mode-1, SM2 is used to check a valid stop bit during reception.
In mode-1, if SM2 = 1, then receive interrupt (RI) is activated only when a valid stop bit is received.
In mode-2 and mode-3 the SM2 bit is used to enable multiprocessor communication.
In multiprocessor communication the serial port of a number of microcontrollers can be connected to a common serial bus. One controller will act as a master and all other controller will act as slave.
A unique 8-bit address is assigned to each slave and the SM2 bit in all the slaves is set to 1.
When SM2 bit is one, the slaves will consider the received byte as address and when SM2 bit is zero the slaves will consider the received byte as data. • For communication with a slave the master will first send as address byte and then a data byte.
The master initiates communication with a slave by sending the address of the slave on the bus. All the slaves will receive the address byte. Since SM2 = 1 initially in all the slaves, the received byte will be considered as address and the slaves will verify whether the received address matches with assigned address. The slave whose assigned address matches with received address will clear its SM2 bit. Now SM2 bit of only one of the slave will be zero.
Next the master will send a data byte which is also received by all the slave, but the data byte is accepted by the slave whose SM2 = 0 and so the receive interrupt is activated only in one of the slave whose SM2 = 0.
After reading the received data from SBUF register, the SM2 bit of the slave should be set to one again to receive next data.
The REN bit of SCON register can be used to enable or disable the serial reception. When REN = 1, the serial reception is enabled and when REN = 0, the serial reception is disabled.
The bits TI and RI of SCON register are transmitting interrupt flag and receive interrupt flag respectively.
The controller will set the TI bit during the transmission of stop bit of a data character in mode 1 to 3 and during the transmission 0 bit of a data character in mode-0.
The controller will set the RI bit during the reception of stop bit of a data character in mode 1 to 3 and during the reception of 8th bit of a data character in mode- 0.
Q2) Explain the programming of 8051 to transfer data serially
A2) In programming the 8051 to transfer character bytes serially, the following steps must be taken.
1 in mode 2 (8-bit auto-reload) to set the baud rate.
serial data transfer (assuming XTAL = 11.0592 MHz).
where an 8-bit data is framed with start and stop bits.
- The TI flag bit is monitored with the use of the instruction “JNB TI, xx” to see if the character has been transferred completely.
Q3) Explain the programming of 8051 to receive data serially?
A3) Programming the 8051 to receive data serially
In the programming of the 8051 to receive character bytes serially, the following steps must be taken.
1.TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate.
2. The TH1 is loaded with one of the initial values to set baud rate for serial data transfer (assuming XTAL = 11.0592 MHz).
3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1.
5. TI is cleared by CLR TI instruction.
6. The character byte to be transferred serially is written into SBUF register.
7. The TI flag bit is monitored with the use of instruction JNB TI, xy to see if the character has been transferred completely.
8. To transfer the next byte, go to step 5.
Q4) Write a C program for 8051 to transfer the letter “A” serially at 4800 baud continuously. Use 8-bit data and 1 stop bit.
A4)
#include<reg51.h>
void main(void)
{
TMOD = 0x20;
TH1= 0xFA;
SCON = 0x50;
TR1=1;
while(1)
{
SBUF = ‘A’
while(TI==0)
TI=0;
}
}
Q5) Program in 8051C to receive bytes of data serially and put them in P1. Set the baud rate at 4800 8-bit data and 1 stop bit.
A5)
#include<reg51.h>
void main(void)
{
unsigned char mybyte;
TMOD =0x20;
TH1=0xFA;
SCON =0x50;
TR1=1;
while(1)
{
while(RI==0)
mybyte=SBUF;
P1=mybyte;
RI=0;
}
}
Q6) Explain GSM module?
A6) GSM stands for (Global System for Mobile Communications )which is basically a modem which accepts SIM card and works in GSM network provided by the operator just like mobile phone. The GSM module can be controlled by computer or microcontroller to do different tasks in the network such as calling, sending messages,accepting messages,sending FAX etc.
The GSM module usually communicates with the parent hardware by means of serial communication. If the parent hard ware is a personal computer, the communication is usually done through the serial port (RS232) and if the parent system is microcontroller based, the communication is through the TTL pins Rx and Tx.
Q7) Explain interfacing of GSM with 8051?
A7)
Interfacing of GSM with 8051 microcontroller
Here the GSM module and the microcontroller communicates in between using serial communication. Rx pin of the 8051 is connected to Tx pin of the GSM module and Tx pin of the 8051 is connected to the Rx pin of the GSM module. The LCD module is involved in this project to give an indication message when the SMS is sent.
Switch S1, capacitor C4 and resistor R2 are associated with reset circuit of the microcontroller. Capacitor C1, C2 and crystal X1 are associated with clock circuit. C3 is just a noise by-pass capacitor. Resistor R2 is used to set the contrast of the LCD display. Resistor R3 limits the current through the back light LED.
Q8) Explain GSM commands?
A8) The parent hardware (PC or uC) does different tasks with the GSM module by sending different different commands and the data to the module in a suitable order and format.
The task in the module is to send a message to a mobile phone The commands and their format required for this application are
AT- to check the modem.
AT+CMGF=1 to configure the GSM module to SMS mode.
AT+CMGS=” mobile number” to send the mobile number to the GSM module.
CTRL+Z to send the message.
Q9) Write a program to send and read SMS?
A9)
ORG 000H
MOV TMOD,#00100001B
MOV TH1,#253D
MOV SCON,#50H
SETB TR1
RS EQU P2.7
RW EQU P2.6
E EQU P2.5
MAIN: ACALL DINT
MOV A,#"A"
ACALL SEND
MOV A,#"T"
ACALL SEND
MOV A,#0DH
ACALL SEND
ACALL DELAY1
MOV A,#"A"
ACALL SEND
MOV A,#"T"
ACALL SEND
MOV A,#"+"
ACALL SEND
MOV A,#"C"
ACALL SEND
MOV A,#"M"
ACALL SEND
MOV A,#"G"
ACALL SEND
MOV A,#"F"
ACALL SEND
MOV A,#"="
ACALL SEND
MOV A,#"1"
ACALL SEND
MOV A,#0DH
ACALL SEND
ACALL DELAY1
MOV A,#"A"
ACALL SEND
MOV A,#"T"
ACALL SEND
MOV A,#"+"
ACALL SEND
MOV A,#"C"
ACALL SEND
MOV A,#"M"
ACALL SEND
MOV A,#"G"
ACALL SEND
MOV A,#"S"
ACALL SEND
MOV A,#"="
ACALL SEND
MOV A,#34D
ACALL SEND
MOV A,#"+"
ACALL SEND
MOV A,#"9"
ACALL SEND
MOV A,#"1"
ACALL SEND
MOV A,#"9"
ACALL SEND
MOV A,#"5"
ACALL SEND
MOV A,#"4"
ACALL SEND
MOV A,#"4"
ACALL SEND
MOV A,#"3"
ACALL SEND
MOV A,#"4"
ACALL SEND
MOV A,#"0"
ACALL SEND
MOV A,#"0"
ACALL SEND
MOV A,#"7"
ACALL SEND
MOV A,#"7"
ACALL SEND
MOV A,#34D
ACALL SEND
MOV A,#0DH
ACALL SEND
ACALL DELAY1
MOV A,#"H"
ACALL SEND
MOV A,#"E"
ACALL SEND
MOV A,#"L"
ACALL SEND
MOV A,#"L"
ACALL SEND
MOV A,#"O"
ACALL SEND
ACALL DELAY1
MOV A,#1AH
ACALL SEND
ACALL DELAY1
ACALL DINT
ACALL TEXT1
ACALL DELAY1
HERE1:SJMP HERE1
SEND:CLR TI
MOV SBUF,A
WAIT:JNB TI,WAIT
RET
DELAY1:MOV R6,#15D
BACK: MOV TH0,#00000000B
MOV TL0,#00000000B
SETB TR0
HERE: JNB TF0,HERE
CLR TR0
CLR TF0
DJNZ R6,BACK
RET
DELAY: CLR E
CLR RS
SETB RW
MOV P0,#0FFh
SETB E
MOV A,P0
JB ACC.7,DELAY
CLR E
CLR RW
RET
DISPLAY:MOV P0,A
SETB RS
CLR RW
SETB E
CLR E
ACALL DELAY
RET
CMD: MOV P0,A
CLR RS
CLR RW
SETB E
CLR E
ACALL DELAY
RET
DINT:MOV A,#0FH
ACALL CMD
MOV A,#01H
ACALL CMD
MOV A,#0CH
ACALL CMD
MOV A,#06H
ACALL CMD
MOV A,#81H
ACALL CMD
MOV A,#3CH
ACALL CMD
RET
TEXT1: MOV A,#"S"
ACALL DISPLAY
MOV A,#"E"
ACALL DISPLAY
MOV A,#"N"
ACALL DISPLAY
MOV A,#"T"
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
RET
END
Q10) What is the use of GSM?
A10) GSM is an open and digital cellular technology used for transmitting mobile voice and data services operate at the 850MHz, 900MHz, 1800MHz, and 1900MHz frequency bands. GSM technology was developed as a digital system using the time division multiple access (TDMA) technique for communication purposes.