首页 2051单片机6位数字钟

2051单片机6位数字钟

举报
开通vip

2051单片机6位数字钟2051单片机6位数字钟 51单片机作的电子钟程序在很多地方已经有了介绍,对于单片机教程者而言这个程序基本上是一道门槛,掌握了电子钟程序,基本上可以说51单片机就掌握了80%。常见的电子钟程序由显示部分,计算部分,时钟调整部分构成,这样程序就有了一定的长度和难度。这里我们为了便于大家理解和掌握单片机,我们把时钟调整部分去除,从而够成了这个简单的电子钟程序。 时钟的基本显示原理:时钟开始显示为0时0分0秒,也就是数码管显示000000,然后每秒秒位加1 ,到9后,10秒位加1,秒位回0。10秒位到5后,即59秒 ...

2051单片机6位数字钟
2051单片机6位数字钟 51单片机作的电子钟程序在很多地方已经有了介绍,对于单片机教程者而言这个程序基本上是一道门槛,掌握了电子钟程序,基本上可以说51单片机就掌握了80%。常见的电子钟程序由显示部分,计算部分,时钟调整部分构成,这样程序就有了一定的长度和难度。这里我们为了便于大家理解和掌握单片机,我们把时钟调整部分去除,从而够成了这个简单的电子钟程序。 时钟的基本显示原理:时钟开始显示为0时0分0秒,也就是数码管显示000000,然后每秒秒位加1 ,到9后,10秒位加1,秒位回0。10秒位到5后,即59秒 ,分钟加1,10秒位回0。依次类推,时钟最大的显示值为23小时59分59秒。这里只要确定了1秒的定时时间,其他位均以此为基准往上累加。 开始程序定义了秒, 十秒, 分, 十分,小时,十小时,共6位的寄存器, 分别存在30h,31h,32h,33h,34h,35h单元,便于程序以后调用和理解。 电路原理图: 为了节省硬件资源,电路部分采用6位共阳极动态扫描数码管,数码管的段位并联接在51单片机的p0口,控制位分别由6个2N5401的PNP三极管作驱动接在单片机的p2.1,p2.2,p2.3,p2.4,p2.5,p2.6口。 that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and 从标号 star开始把这些位全部清除为0,从而保证了开始时显示时间为0时0分0秒。 然后是程序的计算部分: inc a_bit(秒位),这里用到了一个inc指令, 意思是加1,程序运行到这里自动加1。然后把加1后的数据送acc: mov a,a_bit (秒位),这时出现了一个问题,如果不断往上加数字不会加爆, 所以有了下面的一句话cjne a,#10,stlop; 如果秒位到10那么转到10秒处理程序。cjne是比较的意思,比较如果a等于10 就转移到10秒处理程序,实际上也就限定了在这里a的值最大只能为9,同时 mov a_bit,#00h,这时 a_bit(秒位)被强行清空为0,又开始下一轮的计数。 秒位处理完了到下面10秒的处理程序: inc b_bit,把10秒位b_bit加1,由于程序开始对各位的寄存器已经清0,这时10秒位就变成1 ,然后同样送到累加器ACC:mov a,b_bit 现在开始新一轮的10秒位计数cjne a,#6,stlop ;如果10秒到了6那么到分位处理程序。也就限定了10秒位最多显示5。 下面的部分分位, 十分位,小时位,十小时位的计算方法与上面的类似,应当不难领会。 计算部分完成后,最终要把结果送到数码管显示,这一部分电路上采用最简洁的并联型动态扫描接法。其基本原理是利用人眼的视觉暂留效应,在6个数码管上依次送需要显示的数字, 然后依次打开各个数码管,并不断循环,如果速度足够快, 我们看到就是一串连续的数字,而不是各个独立的数字。 但是必须注意,实际上单片机是逐个往各个数码管送数据的。明白了这个原理,我们就不难理解下面的程序。首先看秒位的显示程序:dplop: mov a,a_bit ;把秒位(a_bit)送到寄存器A。 MOVC A,@A+DPTR 根据取到的值到指定的地址取数,意思是假如此时a_bit(秒位)的值是2,那么到数据表的第三个位置去取数, 取到的值则是 0a2h。这里或者有人会问为什么不是第2个位置呢,没错,因为开始程序就已经把各个位清0,第一次运行时显示的是0,第二次运行显示1,第3次运行则为2。而mov p0,a (送出个位的7段代码)硬件上数码管的段位接在P0口。0A2H也就是数码管显示2的代码了。这时,数码管还没有显示。由于他们是并联的,我们必须指定哪一个数码管亮。clr p2.6把P2.6端口打开也就是秒位,此时秒位的数码管亮了。亮了以后,是不是不管他了呢,当然不是,还要指定他亮多长的时间。假定是1毫秒,后面就有了acall d1ms(调用1毫秒时间);完成后再关闭这个数码管: setb p2.6。 that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and 程序进行到这里,然后继续扫描10秒位 b_bit,过程也是先查表, 取数,送显示,开十秒位数码管,延时1毫秒,关闭显示。下面的部分分位,十分位, 小时位,十小时位的显示方法与上面的相同。大家自行领会。 可能大家会问程序漏了一个地方没有讲,r0,r1寄存器在这里器什么作用,这里还是要从动态扫描讲起。我们是以1秒位为基准的,但是整个显示部分每秒钟轮流扫描一次,显然就不能达到要求。视觉暂留特性告诉我们,至少每秒显示30次以上人眼睛才不会有闪烁感,所以我们在这里把显示程序的首位段使用了r0,r1作扫描次数的计数器,分别送4,和250,相乘得1000,然后再显示程序的尾段 加上以下代码 djnz r1,dpl op ;100次没完循环djnz r0,dpl1 ;4个100次没完循环 ,这样总共显示1000次,人眼就不会感觉到显示闪烁的问题了。 程序的最后是1毫秒的延时子程序和7段数码管各划的数字排列表, 如果走时的时间不准,可以适当调整1毫秒的延时子程序的数值,直到准确。 程序的扩展1:改动计算部分 cjne a,#6,stlop全部改为cjne a,#10,stlop,那么就变成了一个6位的计数器。所有位都是从0到9依次显示。 程序的扩展2:改动的计数器不能受外界的控制,因此没有实际意义。 那么可已通过一个按键来进行控制,每按一次按键数字加一,那么可以在程序的计算部分增加几行判断按键的代码: stlop: acall display ;调用显示 jb p3.2,stlop ;监测键盘,如果p3.2按下那么执行显示 we: acall display ;显示保持! acall d1ms ;延时1ms避免键盘误动作 jnb p3.2,we ;如果p3.2还没有放开继续延时 那么就可以通过按键来实现计数显示的功能了,由p3.2端口作控制,每按键一次程序加1。 完整的程序清单: that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and org 00h a_bit equ 30h ;秒寄存器 b_bit equ 31h ;10秒寄存器 c_bit equ 32h ;分寄存器 d_bit equ 33h ;10分寄存器 e_bit equ 34h ;小时寄存器 f_bit equ 35h ;10小时集存器 org 0000h ajmp star org 0030h star: mov a,#00h ;把各个位全部清0 mov a_bit,a mov b_bit,a mov c_bit,a mov d_bit,a mov e_bit,a mov f_bit,a stlop: acall display ;程序的计算部分 inc a_bit ;秒位加1 mov a,a_bit ;送a cjne a,#10,stlop;如果秒到10那么转到10秒处理 mov a_bit,#00h ;秒位清0 inc b_bit ;10秒位加1 mov a,b_bit ;送a cjne a,#6,stlop ;如果10秒到了6那么到分处理 mov b_bit,#00h ; 10秒位清0 inc c_bit mov a,c_bit cjne a,#10,stlop mov c_bit,#00h inc d_bit mov a,d_bit cjne a,#6,stlop mov d_bit,#00h inc e_bit mov a,e_bit that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and cjne a,#10,stlop mov e_bit,#00h inc f_bit mov a,f_bit cjne a,#3,stlop mov f_bit,#00h ajmp stlop ;重新开始计算 display: ;显示子程序 mov dptr,#numtab ;指定查表启始地址 mov r0,#4 dpl1: mov r1,#250 ;显示1000次 dplop: mov a,a_bit ;取秒位的值 MOVC A,@A+DPTR ;查秒位数的7段代码 mov p0,a ;送出到P0口显示 clr p2.6 ;开个位显示 acall d1ms ;显示1ms setb p2.6 ;关闭显示 mov a,b_bit ;取10秒位的值 MOVC A,@A+DPTR ;查10秒位的7段代码 mov p0,a ;送出10秒位到P0口显示 clr p2.5 ;开10秒位显示 acall d1ms ;显示1ms setb p2.5 mov a,c_bit ;取分位 MOVC A,@A+DPTR ; mov p0,a ; clr p2.4 ; acall d1ms ; setb p2.4 mov a,d_bit ;取10分位 MOVC A,@A+DPTR ; mov p0,a ; that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and clr p2.3 ; acall d1ms ; setb p2.3 mov a,e_bit ;取小时位 MOVC A,@A+DPTR ; mov p0,a ; clr p2.2 ; acall d1ms ; setb p2.2 mov a,f_bit ;取10小时位 MOVC A,@A+DPTR ; mov p0,a ; clr p2.1 ; acall d1ms ; setb p2.1 djnz r1,dplop ;100次没完循环 djnz r0,dpl1 ;4个100次没完循环 ret D1MS: MOV R7,#20 ;1MS延时(按12MHZ算) DJNZ R7,$ RET ;7段数码管各划的数字排列表 numtab: db 28h,7eh,0a2h,62h,74h,61h,21h,7ah,20h,60h ;0 1 2 3 4 5 6 7 8 9 end that the wiring is correct, the operation is flexible, auxiliary contact is accurate. 11 current and voltage circuits check: current transformer wiring is correct, correct polarity, the secondary side are not allowed to open. 5.3.2.2 debugging 12 wiring insulation resistance test methods: secondary circuit insulation resistance must be greater than 1M (use 500V megohmmeter to check). 2 control loop simulation action test: disconnect electrical line of main loop switch outlet at, motor, electrical equipment not by electric, connected control power, check the Department of voltage whether meet provides, lights following electrical, work whether normal; operation the button or switch, corresponding of the following electrical, and contact device of sucking collection and release are should quickly, the related lights indicates to meet drawings requirements; with artificial simulation of method try moving the protection components, should can achieved quickly, and accurate, and reliable of protection function; manual the trip switch, Check its limited bit role of directional and the reliability; on has electrical joint lock link of equipment, should according to principle figure check chain function anti-mine grounding system debugging 5.3.3.1 grounding resistance of test method following figure by shows, along was measuring grounding very E' makes potential detection needle P' and current detection needle C' according to line each other apart 20m, insert to in the, and
本文档为【2051单片机6位数字钟】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_219945
暂无简介~
格式:doc
大小:57KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-10-12
浏览量:14