单片机课程设计---基于51单片机的电子钟设计内容摘要:

示变量组 unsigned char data timer=0,second=0,minute=0,hour=0。 unsigned char data second_bell=59,minute_bell=59,hour_bell=23。 unsigned code tab_high[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}。 unsigned code tab_low[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}。 unsigned code tab_position[6]={0x3e,0x3d,0x3b,0x37,0x2f,0x1f}。 unsigned char tab2[6]={0x00,0x00,0x00,0x00,0x00,0x00}。 unsigned char key_down。 unsigned char key_value。 unsigned char flag,tab,pp=1。 unsigned char data position=0。 unsigned int val。 unsigned char i。 unsigned char number=100。 //响铃函数变量组 define Clk 0x070000 sbit P17 = P1^7。 //扬声器控制引脚 unsigned char data val_H。 //计数器高字节 unsigned char data val_L。 //计数器低字节 //响铃音乐频率表 unsigned int code freq_list[] = {371,495,495,495,624,556,495,556,624, 495,495,624,742,833,833,833,742,624, 624,495,556,495,556,624,495,416,416, 371,495,833,742,624,624,495,556,495, 556,833,742,624,624,742,833,990,742, 624,624,495,556,495,556,624,495,416, 416,371,495,0}。 //响铃音乐频率对应时间表 unsigned char code time_list[]= { 4, 6, 2, 4, 4, 6, 2, 4, 4, 6, 2, 4, 4,12, 1, 3, 6, 2, 4, 4, 6, 2, 4, 4, 6, 2, 4, 4,12, 4, 6, 2, 4, 4, 6, 2, 4, 4, 6, 2, 4, 4,12, 4, 6, 2, 4, 4, 6, 2, 4, 4, 6, 2, 4, 4,12}。 微型计算机原理与应用 11 //延时函数 void delay_short(void) { int i=0。 for(i=0。 i=255。 i++){} } //清除函数 void clear() { timer=0。 second=0。 minute=0。 hour=0。 pp=0。 } //***********************************// //键盘函数组 (包括按键扫描函数、得到按键值函数和键盘情况函数) //按键扫描函数 void keyscan() { unsigned char cc。 P1= 0x00。 cc = C8255_C。 key_down = (~cc) amp。 0x0f。 } //得到按键值函数 void getkey() { unsigned char value。 unsigned char i, j = 0x0e。 for(i=0。 i4。 i++) { P1 = j。 value = C8255_C amp。 0x0f。 if(!(value amp。 0x01)) { key_value = i + 0。 return。 } if(!(value amp。 0x02)) { key_value = i + 4。 return。 } if(!(value amp。 0x04)) 微型计算机原理与应用 12 { key_value = i + 8。 return。 } if(!(value amp。 0x08)) { key_value = i + 12。 return。 } j = 1。 } } //键盘情况函数 void keycondition() { keyscan()。 if(key_down) { delay_short()。 keyscan()。 if(key_down) { getkey()。 } } } //***********************************// //显示函数组(包括数码管显示函数和显示光标函数 ) //数码管显示函数 void display( unsigned char V ,unsigned char M) { if(M==0) { tab2[5] = hour/10%10。 tab2[4] = hour%10。 tab2[3] = minute/10%10。 tab2[2] = minute%10。 tab2[1] = second/10%10。 tab2[0] = second%10。 } if(M==1) { tab2[5。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。