Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Program Timer 0 in C to generate a square wave of 3 kHz. Assume that XTAL = 1

ID: 665922 • Letter: 1

Question

1. Program Timer 0 in C to generate a square wave of 3 kHz. Assume that XTAL = 11.0592 MHz.

2. Program Timer 1 in C to generate a square wave of 3 kHz. Assume that XTAL = 11.0592 MHz.

3. Program Timer 1 in C to be an event counter. Use mode 1 and display the binary count on P1 and P2 continuously. Set the initial count to 20,000.

4. Program Timer 0 in C to be an event counter. Use mode 2 and display the binary count on P2 continuously. Set the initial count to 20.

5. Write an 8051 C program to transfer serially the letter “Z” continuously at a 1,200 baud rate.

6. Write an 8051 C program to transfer serially the message “The earth is but one country and mankind its citizens” continuously at a 57,600 baud rate.

7. Write a C program for DS89C4z0 to transfer serially the letter “Z” continuously at a 1,200 baud rate. Use the second serial port.

8. Write a C program for the DS89C4x0 to transfer serially the message “The earth is but one country and mankind its citizens” continuously at a 57,600 baud rate. Use the second serial port.

9. Write a program in which every 2 seconds, the LED connected to P2.7 is turned on and off four times, while the 8051 is getting data from P1 and sending it to P0 continuously. Make sure the on and off states are 50 ms in duration.

10. Write a program using interrupts to get data from P1 and send it to P2 while Timer 0 is generating a square wave of 3 kHz.

11. Write a program using interrupts to get data serially and send it to P2 while Timer 0 is generating a square wave of 5 kHz.

Explanation / Answer

2. Program Timer 1 in C to generate a square wave of 3 kHz. Assume that XTAL = 11.0592     MHz.

(XTAL / 12) /32 frequency provided by UART

(a)9600 11.0592Mhz/12=921.6KHz/32=28800/9600=3 = -3 OR FDH(265-3=FDH)

(b) 4800

11.0592MHz / 12 = 921.6kHz 921.6kHz/32 = 28,800Hz 28800/4800 = -6d or FAh

© 1200       28800/1200=24=-24 OR E8

(d)300

11.0592MHz / 12 = 921.6kHz 921.6kHz/32 = 28,800Hz 28800/300 = -96d or A0h

(e)150

28800/150 = 192=-192 OR 40H

5. Write an 8051 C program to transfer serially the letter “Z” continuously at a 1,200 baud rate

28800/1200=24=-24

MOV TMOD

6. Write an 8051 C program to transfer serially the message “The earth is but one country and mankind its citizens” continuously at a 57,600 baud rate.

// So far it only displays it once

ORG    0000H

MOV    TMOD, #20H ; Timer 1, mode 2(auto-reload)

MOV A, PCON        ; place a copy of PCON in ACC

SETB ACC.7        ; make D7 = 1

MOV PCON, A        ; SMOD of PCON register = 1

CLR A            ; clear A for later use

MOV    TH1, # -1    ; from example 10-7 and 10-8 57600/1=57600

MOV    SCON, #50H ; 8-bit, 1 stop, REN enabled

SETB TR1

MOV DPTR, #MYDATA

H_1:        CLR    A
           MOVC    A,@A+DPTR       
           JZ    B_1             
           ACALL    SEND            
           INC    DPTR            
           SJMP    H_1             
B_1:        MOV    A,P2         
           ACALL    SEND           
           ACALL    RECV           
           MOV    P1,A         
           SJMP    B_1             
SEND:   MOV    SBUF,A       
H_2:        JNB    TI,H_2       
           CLR    TI             
           RET               
RECV:       JNB    RI,RECV      
           MOV    A,SBUF       
           CLR    RI           
        RET

MYDATA: DB “The earth is but one country and mankind its citizens”, 0

END