In: Electrical Engineering
Write a program using interrupts to get data serially and send it to P2 while at the same time Timer 0 is generating a square wave of 5 kHz. We've been basing our code on the Intel 8051 microntroller and assembly language.
ORG 0
LJPM MAIN
ORG 000BH ;ISR for Timer 0
CPL P0.1 ; toggle P0.1
RETI
ORG 23H
LJPM SERIAL ; jump to serial int. ISR
ORG 30H
MAIN: MOV P1, #OFFH ; make P1 an input port
MOV TMOD, #22H ; timer 0&1, mode 2, auto-reload
MOV TH1, #0F6H ; 4800 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
MOV THO, #-92 ; for 5 KHZ wave
MOV IE, #10010010B ; enable serail, timer 0 int.
SETB TR1 ; start timer 1
SETB TR0 ; start timer 0
BACK: MOV A, P1 ; read data from port 1
MOV SBUF, A ; give a copy to SBUF
MOV P2, A ; write it to P2
SJMP BACK ; stay in loop indefinitely
SERIAL PORT ISR
ORG 100H
SERIAL: JB TI, TRANS ; jump if TI is high
MOV A, SBUF ; otherwise due to received
MOV P0, A ; send serial data to P0
CLR RI ; clear RI since CPU does not
RETI ; return from ISR
TRANS: CLR TI ; clear TI since CPU does not
RETI ; return from ISR
END