The 8051 Microcontroller and Embedded

(lily) #1
Department of Computer Scien

ce and Information Engineering

National Cheng Kung University, TAIWAN

TIMER HANEL
INTERRUPTS

(cont’)


Example 11-4Write a program to generate a square wave if 50Hz frequency on pin P1.2. This is similar to Example 9-12


except that it uses an interrupt

for timer 0. Assume that XTAL=11.0592 MHzSolution:

ORG 0LJMP MAIN ORG 000BH ;ISR for Timer 0CPL P1.2MOV TL0,#00MOV TH0,#0DCHRETIORG 30H
;--------main program

for initialization

MAIN:MOV TM0D,#000000

01B ;Timer 0, Mode 1

MOV TL0,#00MOV TH0,#0DCHMOV IE,#82H ;e

nable Timer 0 interrupt

SETB TR0
HERE:SJMP HERE

END
Free download pdf