




免费预览已结束,剩余7页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/*本程序只是为了应付课程设计而用据我所知其中至少含有3处bug使用环境c8051f020使用通过*/#include #include /*软件仿真I2C总线与HD7279A连接的两根并行口线*/sbit HD7279_DAT=P17;sbit HD7279_CLK=P16;/*宏定义,HD7279A片选信号、数据信号和时钟信号定义*/#define NOSELECT7279 P5 |= 0x80 /P57接片选信号,选种#define SELECT7279 P5 &= (0x80) /未选种#define Set7279DAT HD7279_DAT=1 /数据线置1#define Clr7279DAT HD7279_DAT=0 /数据线置0#define Set7279CLK HD7279_CLK=1 /时钟高电平#define Clr7279CLK HD7279_CLK=0 /时钟底电平unsigned char Count1ms;unsigned char xdata NowTime3; /当前时间,用于当前时间的设置unsigned char xdata HourH,HourL,MinuteH,MinuteL,SecondH,SecondL;unsigned char xdata mHourH,mHourL,mMinuteH,mMinuteL,mSecondH,mSecondL;unsigned char xdata setHourH,setHourL,setMinuteH,setMinuteL,setSecondH,setSecondL;/*对所调用其它文件中函数的声明*/void Delay1ms(unsigned char T); /延时T毫秒void Delay1s(unsigned char T); /延时T秒void Delay1us(unsigned char T); /延时T微秒/*仿真I2C总线时序发送一字节*/void SYSCLK_Init (void) int i; OSCXCN = 0x67; /外部晶振22.1184MHz for (i=0; i 8; /定时1ms的时间常数 TL0 = -SYSCLK/1000; TR0 = 1; /启动T0 IE|= 0x2; /开T0中断/*定时器T0中断服务程序(每隔1ms中断1次) */void Timer0_ISR (void) interrupt 1TH0 = (-SYSCLK/1000) 8; /重新装入初值 TL0 = -SYSCLK/1000;if (Count1ms) Count1ms-; /定时时间减1/*延时Ts(软件实现)*/void Delay1us(unsigned char T)while (T) _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); -T;/*延时Tms(定时器T0实现)*/void Delay1ms(unsigned char T)Count1ms=T; while (Count1ms); /在T0中断服务程序中减1/*延时Ts(定时器T0实现)*/void Delay1s(unsigned char T) while (T)Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);T-;void Send7279Byte(unsigned char ch)char i;SELECT7279; /置CS低电平 Delay1us(50);/延时50for (i=0;i8;i+)if (ch&0x80)/输出1位到HD7279A的DATA端 Set7279DAT;elseClr7279DAT;Set7279CLK;ch=ch1;/待发数据左移 Delay1us(8);Clr7279CLK; Delay1us(8);Clr7279DAT;/发送完毕,DATA端置低,返回 /*仿真I2C总线时序接收一字节*/unsigned char Receive7279Byte(void)unsigned char i,ch=0;Set7279DAT;/DATA端置为高电平(输入状态)Delay1us(50);for (i=0;i8;i+)Set7279CLK;Delay1us(8);ch=ch1;/接收数据左移1位if (HD7279_DAT) ch+=1;/接收1位数据Clr7279CLK;Delay1us(8);Clr7279DAT;/接收完毕,DATA端重新置成低电平(输出状态)return ch;/*让第No(0到5)位LED闪烁*/void FlashLED(unsigned char No)unsigned char i;Send7279Byte(0x88);/发闪烁指令 i=0x01;while (No) /将1移到第No位i=i1;No-;Send7279Byte(i); /0闪烁、1不闪烁NOSELECT7279; /*HD7279A左移命令*/void MoveLeft(void)Send7279Byte(0xA1);/发左移指令 NOSELECT7279; /*采用不译码方式显示时数字0到F的段码*/unsigned char code BdSeg=0x7e,0x30,0x6d,0x79, / 0 1 2 3 0x33,0x5b,0x5f,0x70, / 4 5 6 7 0x7f,0x7b,0x77,0x1f, / 8 9 a b 0x4e,0x3d,0x4f,0x47, / c d e f 0x00,0x01; /*显示指针DispBuf所指6个单元数据,点亮第ShowDot(1到6)个LED的小数点*/void DispLED(unsigned char *DispBuf,unsigned char ShowDot) char i,ch;ShowDot-;for (i=0;i=a) & (ch=A) & (ch=0) & (KeyValue=9) /只接收十进制的0到9 i+;Send7279Byte(0xC8); /发送键码值,按方式1译码下载显示 Send7279Byte(KeyValue);MoveLeft(); /显示并左移一位,仍使低位显示并闪烁。Send7279Byte(0x90); Send7279Byte(0x01); NOSELECT7279; WaitKeyOff();Num*=10; /转换成十进制 Num+=KeyValue; Delay1ms(500); void DispTime(void) Send7279Byte(0x85); /在最高位(第5位)LED显示小时的高位 Send7279Byte(HourH);Send7279Byte(0x84); /在第4位LED显示小时的低位Send7279Byte(HourL);Send7279Byte(0x83); /在第3位LED显示分钟的高位Send7279Byte(MinuteH);Send7279Byte(0x82); /在第2位LED显示分钟的低位Send7279Byte(MinuteL);Send7279Byte(0x81); /在第1位LED显示秒钟的高位Send7279Byte(SecondH);Send7279Byte(0x80); /在第0位LED显示秒钟的低位Send7279Byte(SecondL);void mDispTime(void) Send7279Byte(0x85); /在最高位(第5位)LED显示小时的高位 Send7279Byte(mHourH);Send7279Byte(0x84); /在第4位LED显示小时的低位Send7279Byte(mHourL);Send7279Byte(0x83); /在第3位LED显示分钟的高位Send7279Byte(mMinuteH);Send7279Byte(0x82); /在第2位LED显示分钟的低位Send7279Byte(mMinuteL);Send7279Byte(0x81); /在第1位LED显示秒钟的高位Send7279Byte(mSecondH);Send7279Byte(0x80); /在第0位LED显示秒钟的低位Send7279Byte(mSecondL);void set_time()unsigned long CurrentTime=0;do /从键盘输入时间,格式HHMMSS CurrentTime=InputNum(); DispValue(CurrentTime); NowTime0=(unsigned char)(CurrentTime/100000)4);/时 CurrentTime=CurrentTime%100000;NowTime0=NowTime0|(CurrentTime/10000);CurrentTime=CurrentTime%10000;NowTime1=(unsigned char)(CurrentTime/1000)4);/分 CurrentTime=CurrentTime%1000;NowTime1=NowTime1|(CurrentTime/100);CurrentTime=CurrentTime%100; NowTime2=(unsigned char)(CurrentTime/10)0x24)|(NowTime10x59)|(NowTime20x59); HourH=NowTime0/16;/转换成10进制 HourL=NowTime0%16; MinuteH=NowTime1/16; MinuteL=NowTime1%16; SecondH=NowTime2/16; SecondL=NowTime2%16;unsigned long set_InputNum(void)unsigned long Num=0;unsigned char i=0, KeyValue;int c=0; DispLED( -,0);/输入提示FlashLED(0); /第一位闪烁 while(1) KeyValue=GetKeyValue(); if (i=6) /6位数据输入完,返回 FlashLED(8);/关闪烁 return Num; if(KeyValue=0) & (KeyValue9) SecondH+,SecondL=0; if(SecondH5)SecondH=0,MinuteL+; if (MinuteL9) MinuteH+,MinuteL=0;if(MinuteH5)MinuteH=0,HourL+; if(HourL9) HourH+;HourL=0;if(HourH2) HourH=0;if(HourH=2)&(HourL3)HourH=0;HourL=0;c+;Delay1ms(500);if(c%2=0)SecondL+; void set_ring()unsigned long CurrentTime=0;do /从键盘输入时间,格式HHMMSS CurrentTime=set_InputNum(); DispValue(CurrentTime); NowTime0=(unsigned char)(CurrentTime/100000)4);/时 CurrentTime=CurrentTime%100000;NowTime0=NowTime0|(CurrentTime/10000);CurrentTime=CurrentTime%10000;NowTime1=(unsigned char)(CurrentTime/1000)4);/分 CurrentTime=CurrentTime%1000;NowTime1=NowTime1|(CurrentTime/100);CurrentTime=CurrentTime%100; NowTime2=(unsigned char)(CurrentTime/10)0x24)|(NowTime10x59)|(NowTime20x59); setHourH=NowTime0/16;/转换成10进制setHourL=NowTime0%16; setMinuteH=NowTime1/16; setMinuteL=NowTime1%16; setSecondH=NowTime2/16; setSecondL=NowTime2%16; void m()unsigned long CurrentTime=0;unsigned char control_keyvalue;int ma=0;int a=1; DispValue(CurrentTime); NowTime0=(unsigned char)(CurrentTime/100000)4);/时 CurrentTime=CurrentTime%100000;NowTime0=NowTime0|(CurrentTime/10000);CurrentTime=CurrentTime%10000;NowTime1=(unsigned char)(CurrentTime/1000)4);/分 CurrentTime=CurrentTime%1000;NowTime1=NowTime1|(CurrentTime/100);CurrentTime=CurrentTime%100; NowTime2=(unsigned char)(CurrentTime/10)9) mSecondH+,mSecondL=0; if(mSecondH5)mSecondH=0,mMinuteL+; if (mMinuteL9) mMinuteH+,mMinuteL=0;if(mMinuteH5)mMinuteH=0,mHourL+; if(mHourL9) mHourH+;mHourL=0;if(mHourH2) mHourH=0;if(mHourH=2)&(mHourL3)mHourH=0;mHourL=0; control_keyvalue=GetKeyValue();if(control_keyvalue=14)break;if(control_keyvalue=10)a=-a;if(a=-1&ma%5=0)mSecondL-;mDispTime(); if (SecondL9) SecondH+,SecondL=0; if(SecondH5)SecondH=0,MinuteL+; if (MinuteL9) MinuteH+,MinuteL=0;if(MinuteH5)MinuteH=0,HourL+; if(HourL9) HourH+;HourL=0;if(HourH2) HourH=0;if(HourH=2)&(HourL3)HourH=0;HourL=0;SecondL+;void main(void) unsigned char control_keyvalue;int control_key=1;int a=0;int count; WDTCN = 0xde; /关看门狗 WDTCN = 0xad; SYSCLK_Init(); /初始化系统时钟 PORT_Init(); /初始化I/O口 Timer0_Init(); /初始化定时器 CPT1CN|=0x80; /使能比较器1 ET0 =1; /开定时器0中断 EA=1; /开总体中断 Delay1ms(25); /7279上电复位的延时时间 Send7279Byte(0xA4); /7279复位 set_time(); while(1) Delay1ms(200); a+; if(a%5=0) SecondL+; control_keyvalue=GetKeyValue();if(control_keyvalue=10)SecondH=0;SecondL=0;else if(control_keyvalue=15)set_time(); else if(control_keyvalue=12) count=0;control_key=1;else if(control_keyvalue=11) co
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 韩语五级试题及答案
- 物业案场培训
- 木牍教育数学课程体系
- 血透室肌肉痉挛护理查房
- 脑血管病变病人的护理
- 2025年中国母乳喂养乳头罩行业市场全景分析及前景机遇研判报告
- 会计总账业务流程规范
- 餐饮企业租赁及品牌输出服务合同
- 航空公司新员工入职培训
- 车辆无偿租赁与品牌形象展示协议
- 疑难病例讨论课件
- 部编本小学语文六年级下册毕业总复习教案
- JB∕T 11864-2014 长期堵转力矩电动机式电缆卷筒
- 小儿氨酚黄那敏颗粒的药动学研究
- 生态环境行政处罚自由裁量基准
- 长沙市开福区2024届六年级下学期小升初数学试卷含解析
- 2024年安徽普通高中学业水平选择性考试化学试题及答案
- DZ/T 0462.3-2023 矿产资源“三率”指标要求 第3部分:铁、锰、铬、钒、钛(正式版)
- 2024年昆明巫家坝建设发展有限责任公司招聘笔试冲刺题(带答案解析)
- 《取水许可核验报告编制导则(试行)(征求意见稿)》
- 2023年国开(中央电大)04114《会计学概论》题库及标准答案
评论
0/150
提交评论