用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟.doc_第1页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟.doc_第2页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟.doc_第3页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟.doc_第4页
用STC12C2052AD及八位数码管(595)模块扩展模块组成的三键时钟.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

用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,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,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 ;/ 调快慢 细调 每隔五分钟增减几秒,由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一个下降沿 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 hc595(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 = 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 ) time_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,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; 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; if ( k340 ) k3=0; hms1=t_buf2/10%10 ; hms2=t_buf2%10 ; hms1=hms1+1; if (hms15) hms1=0; t_buf2=hms1*10+hms2; if (led_NO=12) /细调个位 if ( k240 ) k2=0; hms1=t_buf2/10%10 ; hms2=t_buf2%10 ; if (hms2=0) hms2=9; else hms2=hms2-1; t_buf2=hms1*10+hms2; if ( k340 ) k3=0; hms1=t_buf2/10%10 ; hms2=t_buf2%10 ; hms2=hms2+1; if (hms19) hms2=0; t_buf2=hms1*10+hms2; ndisplay2(0,12,2); ndisplay2(1,16,2); ii=t_buf/100%10; ndisplay2(2,ii,2); ii= t_buf/10%10 ; ndisplay2(3,ii,2); ii= t_buf%10 ; ndisplay2(4,ii,2); if ( t_buf3=1 ) ndisplay2(5,17,2); /加 if ( t_buf3=2 ) ndisplay2(5,16,2); /减 ii=t_buf2/10%10; ndisplay2(6,ii,2); ii= t_buf2%10 ; ndisplay2(7,ii,2);void delayms(void) /误差 0us50ms unsigned char a,b,c; for(c=7;c0;c-) for(b=16;b0;b-) for(a=110;a0;a-); void KEY_k() unsigned char hms1,hms2; if (key1 =0 ) delay(50); if (key1=0) k1=k1+1; if (key2 =0 ) delay(50); if (key2=0) k2=k2+1; if (key3 =0 ) delay(50); if (key3=0) k3=k3+1; if ( key4 =0 ) delay(25); if ( key4=0) k4=k4+1; if ( k150 ) led_NO=led_NO+1; k1=0; if (led_NO=2 ) | (led_NO =5 ) led_NO=led_NO+1; if ( k270 ) k2=0; switch (led_NO) case 0: led_NO=8 ; break; case 3: led_NO=led_NO-2;break; case 6: led_NO=led_NO-2;break; default:led_NO=led_NO-1;break; if ( led_NO 13 ) led_NO=0; if (k370) k3=0; if (led_NO != 8) switch (led_NO) case 0: hms1=time_buf0/10%10 ; hms2=time_buf0%10 ; hms1=hms1+1; if (hms12) hms1=0; time_buf0=hms1*10+hms2; break; case 1: hms1=time_buf0/10%10 ; hms2=time_buf0%10 ; hms2=hms2+1; if (hms29) hms2=0; time_buf0=hms1*10+hms2; break; case 3: hms1=time_buf1/10%10 ; hms2=time_buf1%10 ; hms1=hms1+1; if (hms15) hms1=0; time_buf1=hms1*10+hms2; break; case 4: hms1=time_buf1/10%10 ; hms2=time_buf1%10 ; hms2=hms2+1; if (hms29) hms2=0; time_buf1=hms1*10+hms2; break; case 6: hms1=time_buf2/10%10 ; hms2=time_buf2%10 ; hms1=hms1+1; if (hms15) hms1=0; time_buf2=hms1*10+hms2; break; void main() P24=0;Time0_Init();uTH0=uTH0-0; / 越大越慢 2ix=50;while(1) zz=zz+1;if ( zz=10 ) zz=0; delay(20); KEY_k(); / if ( ist = 5 ) & (time_buf2 = 59)/ 调快慢 每五分钟调减t_buf2: 秒 if ( ( t_buf2 0 ) & ( t_buf3 = 2 )

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论