原创 利用定时器1延时1秒的程序

2008-4-25 21:51 1838 9 9 分类: MCU/ 嵌入式
;利用定时器精确延时1秒
                         ;循环点亮P1口接的八只发光二极管。  
                            ORG 0000H
                             AJMP START
                             ORG                       001BH                           ;T1中断入口地址
                             AJMP INT_T1
                             ORG                       0030H
START:
                             MOV                       SP,#60H
                             MOV                       TMOD,#10H                       ;置T1为方式1
                             MOV                       TL1,#00H                        ;延时50mS的时间常数
                             MOV                       TH1,#4CH
                             MOV                       R0,#00H
                             MOV                       R1,#20
                             SETB TR1                            ;启动定时器1,开始定时
                             SETB ET1
                             SETB EA                              ;开中断
                             SJMP $
INT_T1:                                      ;T1中断服务子程序
                             PUSH ACC                             ;保护现场
                             PUSH PSW
                             PUSH DPL
                             PUSH DPH
                             CLR                       TR1                             ;关闭定时器1,停止定时
                             MOV                       TL1,#00H                        ;延时50mS常数
                             MOV                       TH1,#4CH       
                             DJNZ R1,EXIT
                             MOV                       R1,#20                          ;延时一秒的常数
                             MOV                       DPTR,#DATAb ;置常数表基址
                             MOV                       A,R0                            ;置常数表偏移量
                             MOVC A,@A+DPTR                       ;读常数表
                             MOV                       P1,A                            ;送P1口显示
                             INC                       R0
                             ANL                       R0,#07H
EXIT:
                             SETB TR1                             ;启动定时器1,开始定时
                             POP                       DPH                             ;恢复现场
                             POP                       DPL
                             POP                       PSW
                             POP                       ACC
                             RETI
                                             ;发光二极管显示常数表
DATAb:                        DB 55H,0AAH,05H,0AH,50H,0A0H,0FFH,0H
                             END
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
9
关闭 站长推荐上一条 /3 下一条