You are on page 1of 2
EXAMPLE 64 EXAMPLE 6.2 Square Wave Using Timer Interrupts Write a program using Timer 0 and interrupts to create a 10 kHz square wave on P10. Solution 0000 5 onc 0 reeset entry point 0000 020030 6 LIMP MAIN ijump above interrupt vectors coon 7 ORG O0OBH —; Timer 0 interrupt vector 0008 5290 8“ TOTSR: CPL 1.0 itoggle port bit ooep 32 8 RETI 0030 10 ORG 0030H —;Main program entry point 0030 758902 11 MAIN: MOV ‘MOD,#02H ;timer 0, mode 2 0033 75acce 12 MoV THO,#-50 ;50 us delay 0036 D2ec 13 SETB TRO istart timer 0038 75A882 14 MoV IE, #82H ;enable timer 0 interrupt 0038 80FE 15 SOMP S$ ido nothing ‘Two Square Waves Using Interrupts Write a program using interrupts to simultaneously create 7 kHz and 500 Hz waves on P1.7 and P16. Solution ‘The hardware configuration with the timings for the desired waveforms is shown in 4. This combination of outputs would be extremely difficult to generate on a nor rupt-driven system. Timer 0, providing synchronization for the 7 kHIz signal, oper mode 2, as in the previous example; and timer 1, providing synchronization for the ! signal, operates in mode 1, 16-bit timer mode. Since $00 Hz requires a high-time 0 fice oa fete im —4 PL6 Ra. mov Same BND sare coon pTimer 0 vector addzene doin pimer 2 vector adaves oo30H ‘rmoD, #12 iTimer 4 = mode 1 Trt Hforce timer 1 iatezrupe TE, wean jenable both timer interrupt ¢ ‘THI, AHEGH(-1000) ;1 me high time © TL HLOW (1000) ; low Eizo EXAMPLE Character Output Using Interrupts Write a program using interrupts to continually transmit the ASCII code set (excluding ‘control codes) o a terminal attached to the 80S1's serial port. Solution ‘There are 128 7-bit codes in the ASCII chart. (See Appendix F.) These consist of 95 graphic ‘codes (2011 to 7EH) and 33 control codes (00H to IFH, and 7FH), The program shown below is self-contained and executable from EPROM or ROM immediately after a system reset. 9000 0000 0023 0023 0030 0030 0033 0036 0038 0038 0030 0080 0042 0045 020030, 020042 758920 758086 2ez 759842 7420 75n890 30FE B47FO2 7420 MAIN: SersR: arp. ors LOM: oc LIMP caNE Mov ° MAIN 00238 jserial port interrupt entry SPISR 00308 TOD, #20H © ;Timer 1, mode 2 TH, #-26 712000 baud reload value TRL art timer SCON,#42H ;mode 1, set TY to force 1st } interrupt; send ist char. A, #20 jsend ASCII space first TE, 90H jenable serial port interrupt 3 :do nothing A,HTFH,SKIP ;4f Finished ASCII set, A, #20H } reset to SPACE SBUF.A end char. to serial port

You might also like