用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟

上传人:人*** 文档编号:560314535 上传时间:2023-02-02 格式:DOC 页数:12 大小:60KB
返回 下载 相关 举报
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟_第1页
第1页 / 共12页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟_第2页
第2页 / 共12页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟_第3页
第3页 / 共12页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟_第4页
第4页 / 共12页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟》由会员分享,可在线阅读,更多相关《用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟(12页珍藏版)》请在金锄头文库上搜索。

1、 用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟8位LED数码管驱动模块是通过HC595级联,只需要三个普通IO口就可以驱动八位LED数码管。以下是程序:#include#include#define uchar unsigned char#define uint unsigned intuchar table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0xff;/0-f -/uchar weima=0xfe,0xfd,0xfb,0xf7,

2、0xef,0xdf,0xbf,0x7f;/分别对应相应的数码管点亮,即位码,这里可以选择显示方向uchar weima=0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe;/分别对应相应的数码管点亮,即位码uchar time_buf=12,0,0;uchar disp_buf=0x00,0x01,0x02,0x00,0x01,0x02,0x00,0x01,0x02,0x00,0x01,0x02,0x00,0x01,0x02;uchar Time_temp = 0, LED_temp = 0;uchar uTH0=0;uchar zz,ix,k1,k2,k3,k4,

3、isk;/ 调时 led_NO= 0-7 key1 向右(led_NO+1)key2 向左(led_NO-1) 移动调整位置, key3 调数字(0-9循环) / 调快慢 led_NO =8-12 key1 向右(led_NO+1)key2 向左(led_NO-1) 移动调整位置, key3 调数字(0-9循环)uchar led_NO = 8; /一级菜单 调时 闪烁位uchar led_NO2 = 4; /一级菜单 调快慢 闪烁位 C 粗调 d 细调uchar t_buf=189 ;/ 调快慢 粗调 1秒=时基* t_buf uchar t_buf2=0 ;/ 调快慢 细调 每隔五分钟增减

4、几秒,由t_buf3决定加减 uchar t_buf3=1 ; /=1 增 1 减uchar ist;/ 键sbit key1=P33; / 向右 sbit key2=P35; / 向左-sbit key3=P34; / +sbit key4=P37; / - 暂没用/ 数码模块占用 IO 口sbit P00=P10;/SER 串行数据输入sbit P26=P30;/RCL 移位寄存器时钟输入sbit P25=P31;/CLK 存储寄存器时钟输入sbit P24=P32; /OE使能端/74hc595函数void hc595(uchar date) uint i; P25=0;/给rclk一个

5、下降沿 for(i=0;i8;i+) P26=0;/sclk拉低 if(date&0x80)!=0)P00=1;/判断m的值 如果为高ser1就拉高 else P00=0; P26=1;/给一个上升沿 _nop_; date=date0;x-)for(y=108;y0;y-);void ndisplay2(uint xa,uint da,uint ca) uint ya; if (ca=1) ya=led_NO; if (ca=2) ya=led_NO2; hc595(weimaxa); if(xa != ya) | ( zz = 3 ) ) hc595(tableda); else hc59

6、5(0xff); delay(4); hc595(0xff); hc595(0xff);/* 名称 : Time0_Init()* 功能 : 定时器的初始化,11.0592MZ晶振,50ms* 输入 : 无* 输出 : 无*/void Time0_Init()/*TMOD = 0x01;IE = 0x82;TH0 = 0x4c;TL0 = 0x00;TR0 = 1;*/ TMOD = 0x11; / 定时/计数器0,1工作于方式1 TH0 = 0xf6; / 预置产生45ms时基信号 TL0 = 0x3c; EA = 1; / 开总中断 ET0 = 1; / 定时/计数器0允许中断 TR0 =

7、 1; / 开闭定时/计数器0 /* 名称 : Time0_Int()* 功能 : 定时器中断,中断中实现 Count 加一* 输入 : 无* 输出 : 无*/void Time0_Int() interrupt 1 TH0 = 0xf6-uTH0; / 预置产生时基信号 TL0 = 0x3c; Time_temp+;if(Time_temp = t_buf ) / 1秒, time_buf2=time_buf2+1; /秒if ( time_buf259 ) time_buf1=time_buf1+1;time_buf2=0;ist=ist+1;/分if ( time_buf159 ) ti

8、me_buf0=time_buf0+1;time_buf1=0;/时 if ( time_buf023) time_buf0=0;/天 Time_temp = 0; void display0() uint ii; ii= time_buf0/10%10 ; ndisplay2(0,ii,1); ii= time_buf0%10 ; ndisplay2(1,ii,1); / ndisplay2(0,time_buf0/10%10);/ ndisplay2(1,time_buf0/10); ndisplay2(2,16,1); ii= time_buf1/10%10 ; ndisplay2(3,

9、ii,1); ii= time_buf1%10 ; ndisplay2(4,ii,1);/ ndisplay2(3,time_buf1/10%10);/ ndisplay2(4,time_buf1/10); ndisplay2(5,16,1); ii= time_buf2/10%10 ; ndisplay2(6,ii,1); ii= time_buf2%10 ; ndisplay2(7,ii,1); delay(4);/ ndisplay2(6,time_buf2/10%10);/ ndisplay2(7,time_buf2/10);void display() /调快慢 uint s,ii;

10、 unsigned char hms1,hms2; s=1; switch (led_NO) case 9: led_NO2=4 ; break; case 10: led_NO2=5 ; break; case 11: led_NO2=6 ; break; case 12: led_NO2=7 ; break; if (led_NO=9)/ 粗调 if ( k240 ) k2=0; t_buf=t_buf-1; if ( k340 ) k3=0; t_buf=t_buf+1; if (led_NO=10) / 加减 if ( k240 ) k2=0; t_buf3=t_buf3-1; if ( k340 ) k3=0; t_buf3=t_buf3+1; if ( t_buf32) t_buf3=1; / 加if (t_buf3=0) t_buf3=2; / 减 if (led_NO=11) /细调十位 if ( k240 ) k2=0; hms1=t_buf2/10%10 ; hms2=t_buf2%10 ; if (hms1=0) hms1=5; else hms1=hms1-1; t_buf2=hms1*10+hms2;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 幼儿/小学教育 > 小学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号