Upload
ramjee26
View
219
Download
0
Embed Size (px)
Citation preview
8/4/2019 Miicrocontroller Ece-Assignment 3
1/7
Homework Title / No. : _____3____________Course Code : ___ECE310______
Course Instructor : __Ms. Ritu__________ Course Tutor (if applicable) : ____________
Date of Allotment : ____________________ Date of submission : _______23/04/ 2010
Students Roll No. ____RH6802B54_____Section No. : _______H6802_____________
Declaration:I declare that this assignment is my individual work. I have not copied from any
other students work or from any other source except where due acknowledgment
is made explicitly in the text, nor has any part been written for me by another
person.
Students Signature : Ramjee
prasad
Evaluators comments:
_____________________________________________________________________
Marks obtained : ___________ out of _____________________
Content of Homework should start from this page only:
PART-A
1. Write a program to transfer 50 bytes placed at 0300H onwards and save
them to 20H onwards
Sol: Org 0h
Back : Mov dptr, #0300h
Mov r0, #50h
Mov r1, #20h
Mov a, @a+dptr
Mov @r1, a
Inc r1
Inc dptr
Djnz r0, Back
end
2. How can we send and receive data serially with 8051? How can we change
the baud rate?
8/4/2019 Miicrocontroller Ece-Assignment 3
2/7
Sol:-
One of the 8051s many powerful features is its integrated UART, otherwise
known as a serial port. The 8051 has an integrated serial port means that we
may very easily read and write values to the serial port. If it were not for the
integrated serial port, writing a byte to a serial line would be a rather tedious
process requiring turning on and off one of the I/O lines in rapid succession to
properly "clock out" each individual bit, including start bits, stop bits, and parity
bits.
The first things we must do when using the 8051s integrated serial port is,
obviously, configure it. This lets us tell the 8051 how many data bits we want,
the baud rate we will be using, and how the baud rate will be determined.
Bits SM0 and SM1 let us set the serial mode to a value between 0 and 3, inclusive.The four modes are defined in the chart immediately above. As you can see,selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or ShiftRegister) and also determines how the baud rate will be calculated. In modes 0 and
2 the baud rate is fixed based on the oscillators frequency. In modes 1 and 3 thebaud rate is variable based on how often Timer 1 overflows. Well talk more aboutthe various Serial Modes in a moment.
The next bit, SM2, is a flag for "Multiprocessor communication." Generally,whenever a byte has been received the 8051 will set the "RI" (Receive Interrupt)flag.
The next bit, REN, is "Receiver Enable." This bit is very straightforward: If you wantto receive data via the serial port, set this bit. You will almost always want to setthis bit.
The last four bits (bits 0 through 3) are operational bits. They are used whenactually sending and receiving data--they are not used to configure the serial port.
The TB8 bit is used in modes 2 and 3. In modes 2 and 3, a total of nine data bits aretransmitted. The first 8 data bits are the 8 bits of the main value, and the ninth bit istaken from TB8. If TB8 is set and a value is written to the serial port, the datas bitswill be written to the serial line followed by a "set" ninth bit. If TB8 is clear the ninthbit will be "clear."
8/4/2019 Miicrocontroller Ece-Assignment 3
3/7
The RB8 also operates in modes 2 and 3 and functions essentially the same way asTB8, but on the reception side. .
TI means "Transmit Interrupt." When a program writes a value to the serial port, acertain amount of time will pass before the individual bits of the byte are "clockedout" the serial port.
Finally, the RI bit means "Receive Interrupt." It functions similarly to the "TI" bit, butit indicates that a byte has been received.
Setting the baud rate
Baud rate register value
9600 -3
4800 -6
2400 -12
1200 -24
In order to select a baud rate we have to feed its corresponding register value to
the register th1 in serial port programming. This is done in the 2nd step after timer
mode 2 is selected.
3. Write a program to generate a square wave on port 3.1 with on/off duty cycle
having 60/40 ratio. Assume crystal oscillator to be 12MHz.
Sol: - Org 0h
Loop :setb p3.1
Acall delay
Acall delay
Clr p3.1
Acall delay
Sjmp loop
PART-B
1. Write a program which will transfer a byte placed in register R4, serially on
TxD pin of 8051 with baud rate 9600 bps.
8/4/2019 Miicrocontroller Ece-Assignment 3
4/7
Sol:- Org 0h
Mov a,@r4
Mov tmod, #20h
Mov th1, #-3h
Mov scon,#50h
Setb tr1
Mov sbuf, a
Check : Jnb TI, check
end
2. Assume that eight LEDs are connected with port-1 and their anodes areconnected with ground. Write a program to ON the LED one by one at an
interval of 1 second. When all LED are ON, then switch OFF the LEDs in the
similar fashion.
Sol: - org 0000
mov p1, #11111111blcall delaymov p1, #01111111blcall delaymov p1, #001111111blcall delaymov p1, #00011111blcall delaymov p1, #00001111blcall delaymov p1, #00000111blcall delaymov p1, #00000011blcall delaymov p1, #00000001blcall delaymov p1, #00000000blcall delaymov p1, #00000001blcall delaymov p1, #00000011blcall delaymov p1, #00000111blcall delaymov p1, #00001111b
8/4/2019 Miicrocontroller Ece-Assignment 3
5/7
lcall delaymov p1, #00011111blcall delaymov p1, #00111111blcall delaymov p1, #01111111blcall delaymov p1, #11111111blcall delay
delay : mov r0, #05hking :mov r1, #0ffhback : mov r2, #0ffhloop :djnz r2, loopdjnz r1, backdjnz r0, kingret
end
3. Write a program to read from the 4X4 matrix keyboard and display thecharacter on the 7 segment connected to port 1 as shown in fig. below
Org 0000
Mov p2, #0ffh
K1 : Mov p1, #0
Mov a, p2
Anl a, #00001111b
Cjne a, #00001111b, k1
K2 : Acall delay
Mov a, p2
Anl a , #00001111b
8/4/2019 Miicrocontroller Ece-Assignment 3
6/7
Cjne a, #00001111b, over
Sjmp k2
Over : mov a, p2
Anl a, #00001111b
Cjne a, #00001111b, over 1
Sjmp k2
Over 1: mov p1, #11111110b
Mov a, p2
Anl a, #00001111b
Cjne a, #00001111b, row_0
Mov p1, #11111101b
mov a, p2
anl a, #00001111b
cjne a, #00001111b, row_1
mov p1, #11111011b
mov p2, a
anl a, #00001111b
cjne a, #00001111b, row_2
mov p1, #11110111b
anl a, #00001111b
cjne a, #00001111b, row_3
ljmp k2
row 0 : mov dptr, #kcode0
sjmp find
row 1: mov dptr, #kcode1
sjmp find
row 2: mov dptr, #kcode2
sjmp find
8/4/2019 Miicrocontroller Ece-Assignment 3
7/7
row 3 : mov dptr, #kcode3
sjmp find
find : rrc a
jnc match
inc dptr
sjmp find
match : clr a
movc a, @a+dptr
mov p0,a
ljmp k1
org 300h
kcode0 : DB 0,1,2,3
kcode1 : DB 4,5,6,7
kcode2 : DB 8,9,a,b
kcode3 : DB c, d, e, f
end