原创 利用定时器1延时1秒的程序(c51语言)

2008-4-24 22:30 6743 11 12 分类: MCU/ 嵌入式
//利用定时器1延时1秒的程序2007-07-16 ;利用定时器精确延时1秒
                                                     // 循环点亮P1口接的八只发光二极管。  
                                                     //与另一个汇编语言程序相对应,完成相同的功能
                                                     //作者:徐学军
                                                     #include<reg51.h>
                                                     unsigned                                                   char                                                   i="0",j=0;
                                                     code unsigned char datab[8]={0x55,0x0AA,0x05,0x0A,0x50,0x0A0,0x0FF,0x0};
                                                     void                                                   t1int() interrupt 3
                                                           {
                                                              TR1=0;
                                                              TL1=0;
                                                              TH1=0x4C;
                                                              i++;
                                                              if(i==20)
                                                                 {
                                                                  i="0";
                                                                  P1=datab[j];
                                                                  j++;
                                                                  if(j==7)
                                                                     j="0";
                                                                 }
                                                             TR1=1;
                                                           }
        
                                                     void main()
                                                          {
                                                           TMOD="0x10";
                                                           TL1=0;
                                                            TH1=0x4C;
                                                            TR1=1;
                                                            ET1=1;
                                                            EA="1";          
                                                            while(1);
                                                          }    
/*利用定时器1延时1秒的程序2007-06-27 09:57;利用定时器精确延时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

文章评论1条评论)

登录后参与讨论

用户139060 2008-4-25 11:10

顶,学习
相关推荐阅读
用户1158167 2008-09-15 10:59
如何成为杰出的电子工程师?
工程师要有《亮剑》精神。用都梁的话说,古代剑客明知对方是天下第一剑客,明知是死也要亮出宝剑,没有这个本事就别当剑客。“尽管敌强我弱,尽管身陷重围,我们也要亮剑”。工程师也要敢于挑战对手,敢于战胜自己。...
用户1158167 2008-08-27 15:01
80C51复位标志位的设置与应用研究
 设置复位标志位便于区分不同原因引发的复位,作为一种新技术被越来越多的新型单片机所采纳。例如Philips公司的P87LPC700和 P89LPC900系列、Freescale公司(原Motorola...
用户1158167 2008-08-27 15:00
博物馆智能防盗保护器系统设计
摘  要:本设计的目的是实现博物馆藏品防盗和保护的智能化。以微处理器为核心,利用美国国家半导体的彩色图像传感器LM9628和温度传感器LM19进行环境监控,并控制报警系统和空调系统以及进行图像处理。关...
用户1158167 2008-08-27 14:58
可控数字语音延迟器的PIC设计
摘要:详细阐述一种采用PIC16C55单片机实现可控数字语音延迟器的设计方案,同时提供控制电路图及软件算法流程图。关键词:延迟器 语音信号 PIC单片机    延迟器在音频信号处理中有着重要而特殊的用...
用户1158167 2008-08-27 14:57
HT46X23设计微波炉控制器实例分析
微波炉控制器的工作环境相对比较恶劣。首先是炉腔温度比较高,控制器附近温度也会比较高,达到60℃~70℃;另一方面,微波辐射对单片机抗干扰的要求也很高,在做多次快速开关门试验中,当少量微波泄露时,对控制...
用户1158167 2008-08-27 14:53
智能电梯语音系统的设计
   随着城市文明化和现代化建设步伐的加快,对建筑物中电梯的服务要求也越来越高,人们越来越追求智能化、人性化的乘梯环境。在电梯语音服务方面,目前主要是传统的人工服务,即通过电梯管理员告知乘客所要到达的...
EE直播间
更多
我要评论
1
11
关闭 站长推荐上一条 /3 下一条