18. 1. Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the simulator.
org 0000H
XX: MOV DPTR,#MYDATA
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#14
AGAIN:CLR A
MOVC A,@A+DPTR
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
INC DPTR
DJNZ R1,AGAIN
SJMP XX
MYDATA: DB 'VIT UNIVERSITY'
END
19. 3. Assume that the 8051 serial port is connected to the COM port of
IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively.
Assume that XTAL-11.0592Mhz.
Write an 8051 assembly program to
(a) send to PC the message “We Are Ready”,
(b) receive any data send by PC and put it on LEDs connected to P1, and
(c) get data on switches connected to P2 and send it to PC serially. 4800 baud rate
END
20.
21.
22.
23.
24.
25.
26.
27. Write an 8051 program to get data from port P0 and send it to port P1 continuously
while an interrupt will do the following: Timer 0 will toggle the P2.1 bit every 200
microseconds.
Program number: 1
ORG 0000H
LJMP MAIN // Jump to main.
ORG 000BH // timer 0 Interrupt vector label
CPL P2.1 // Toggle P2.1 pin
RETI // Return from ISR
ORG 0030H // After Vector Table Space
MAIN:MOV TMOD,#02H //set Timer 0 in mode 2
MOV P0,#0FFH // Set P0 an I/P port
MOV TH0,#-92 //
MOV IE,#10000010B // enable Timer 0
SETB TR0 // Start the Timer
BACK:MOV A,P0 // Get data from P0.
MOV P1,A // move data P0 to P1
SJMP BACK //Loop it Unless interrupted
END
28. Program 2 Assembly Language
Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7
continuously while an interrupt will do the following:
A serial interrupt service routine will receive data from a PC and display it on P2 ports.
ORG 0000H
LJMP MAIN
ORG 0023H ; ----serial interrupt vector table
LJMP SERIAL
ORG 0030H ;-- after vector table space
MAIN:SETB P1.2 ; -- P1.2 made as input pin
MOV TMOD,#00100000B ; -- timer 1 mode 2
MOV TH1,#-3 ;-- set baud rate 9600
MOV SCON ,#01010000B ; -- one stop bit
MOV IE,#10010000B ; -- serial int. enabled.
SETB TR1 ;-- Timer 1 stared.
BACK:MOV C,P1.2
MOV P1.7,C
SJMP BACK
SERIAL:JB TI,TRANS
MOV A,SBUF
MOV P2,A
CLR RI
RETI
TRANS:CLR TI
RETI
END
29. Task
Write a 8051 ALP using interrupts to do the following:
(a) Receive data serially and sent it to P0, (UART p0)
(b) Have P1 port read and transmitted serially, and a copy given to P2, P1 UART
P1P2
(c) Make timer 0 mode 1 to generate a square wave of 5 Khz frequency on P3.2.
Assume that XTAL-11.0592Mhz. Set the baud rate at 4800.
30. #include <reg51.h>
sbit SW =P1^7;
sbit IND =P1^0;
sbit WAVE =P2^5;
void timer0(void) interrupt 1 {
WAVE=~WAVE; //toggle pin
}
void main() {
SW=1; //make switch input
TMOD=0x02;
TH0=0xA4; //TH0=-92
IE=0x82; //enable interrupt for timer 0
while (1) {
IND=SW; //send switch to LED
}
}
31. A) Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the
simulator.
org 0000H
XX: MOV DPTR,#MYDATA
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#14
AGAIN:CLR A
MOVC A,@A+DPTR
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
INC DPTR
DJNZ R1,AGAIN
SJMP XX
MYDATA: DB 'VIT UNIVERSITY'
END
32. B) Write a 8051 Assembly Language program to get data from the PC
and display it on P1. Assume 8051 is connected to PC and
observe the incoming characters. As you press a key on the PC's keyboard,
the character is sent to the 8051 serially at 4800 baud rate and is
displayed on LEDs. The characters displayed on LEDs are in ASCII (binary).
ORG 0000H
MOV TMOD ,#20H
MOV TH1,#-6
MOV SCON,#50H
SETB TR1
HERE:JNB RI,HERE
MOV A,SBUF
MOV P1,A
CLR RI
SJMP HERE
END
33. Assume that the 8051 serial port is connected to the COM port of
IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively.
Write an 8051 assembly program to
(a) send to PC the message “We Are Ready”,
(b) receive any data send by PC and put it on LEDs connected to P1, and
(c) get data on switches connected to P2 and send it to PC serially.
P2 INPUT UART OUTPUT
baud rate 4800
34.
35.
36. Write an 8051 program to get data from a single bit of P1.3 and send it to P1.5
continuously while an interrupt will do the following: A serial interrupt service routine
will receive data from a PC and display it on P2 ports. set baud rate 9600
timer 1 mode 2…… Analyse and rectify the errors and specify the output.
ORG 0000H
LJMP MAIN
ORG 0032H ; ----serial interrupt vector table
LJMP SERIAL
ORG 0030H ;-- after vector table space
MAIN:SETB P1.3 ; -- P1.2 made as input pin
MOV TMOD,#10H ; -- timer 1 mode 2
MOV TH1,# a4h ;-- set baud rate 9600
MOV SCON ,#50H ; -- one stop bit
MOV IE,10010010B ; -- serial int. enabled.
SETB TR1 ;-- Timer 1 stared.
BACK:MOV C,P1.3
MOV P1.5,C
SJMP BACK
SERIAL:JNB TI,TRANS
MOV A,SBUF
MOV P2,A
RETI
TRANS:CLR TI
RETI
END
37. Write a program using interrupts to do the following:
(a) Receive data serially and sent it to P0,
(b) Have P1 port read and transmitted serially, and a copy given to P2,
(c) Make timer 0 generate a square wave of 5kHz frequency on P3.2.
Assume that XTAL-11.0592. Set the baud rate at 4800.
ORG 0H
LJMP MAIN
ORG 100H
MAIN:
MOV TMOD,#22H
MOV TH1,#-3
SETB TR1
MOV SCON,#50H
MOV TH0,#0A4H
SETB TR0
MOV IE,#10010010b
MOV P1,#0FFH
REP:MOV A,P1
MOV SBUF,A
MOV P2,A
LOOP1:JNB TI,LOOP1
CLR TI
SJMP REP
ORG 0BH
CPL P3.2
RETI
ORG 23H
MOV A,SBUF
MOV P0,A
CLR RI
RETI
END
54. Connect the LCD to your 8051 Kit. Then write and run a program to display your
name on line 1 of the LCD (first name followed by last name with a space in
between).
;P1.0-P1.7 are connected to LCD data pins D0-D7
;P2.0 is connected to RS pin of LCD
;P2.1 is connected to R/W pin of LCD
;P2.2 is connected to E pin of LCD
ORG 0000H
MOV A,#38H
ACALL CMNWRT
ACALL DELAY
MOV A,#0EH
ACALL CMNWRT
ACALL DELAY
MOV A,#01H
ACALL CMNWRT
ACALL DELAY
MOV A,#06H
ACALL CMNWRT
ACALL DELAY
MOV A,#80H
ACALL CMNWRT
ACALL DELAY
MOV A,#'V'
ACALL DATWRT
ACALL DELAY
MOV A,#'I'
ACALL DATWRT
ACALL DELAY
MOV A,#'T'
ACALL DATWRT
ACALL DELAY
AGAIN: SJMP AGAIN
CMNWRT:
MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DATWRT:
MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DELAY: MOV R3,#0FFH
MOV R4,#0FFH
MOV R5,#55H
HERE: DJNZ R5,HERE
HERE1: DJNZ R4, HERE1
HERE2: DJNZ R3,HERE2
RET
END
69. • The digital-to-analog converter (DAC) is a device widely used
to convert digital pulses to analog signals.
• methods of creating a DAC: binary weighted and R/2R ladder.
• The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs.
• The common ones are 8, 10, and 12 bits.
• The number of data bit inputs decides the resolution of the
DAC since the number of analog output levels is equal to 2″,
where n is the number of data bit inputs. Therefore, an 8-
input DAC
70. • DAC0808 provides 256 discrete voltage (or current) levels of
output.
• Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
• There are also 16-bit DACs, but they are more expensive.