电子钟+按键+12864.docx
- 文档编号:7585541
- 上传时间:2023-01-25
- 格式:DOCX
- 页数:16
- 大小:15.79KB
电子钟+按键+12864.docx
《电子钟+按键+12864.docx》由会员分享,可在线阅读,更多相关《电子钟+按键+12864.docx(16页珍藏版)》请在冰豆网上搜索。
电子钟+按键+12864
#include
#include
//#include
#defineuintunsignedint
#defineucharunsignedchar
#defineLCD_dataP0;
ucharcodetable[]="2000年00月00日";
ucharcodetime[]="时间00:
00:
00";
ucharcodetime1[]="每天好心情!
!
!
!
";
ucharcodexi1[]="星期一monday";
ucharcodexi2[]="星期二tuesday";
ucharcodexi3[]="星期三wedesnday";
ucharcodexi4[]="星期四thursday";
ucharcodexi5[]="星期五friday";
ucharcodexi6[]="星期六saturday";
ucharcodexi7[]="星期天sunday";
sbitLCD_PSB=P2^3;
sbitLCD_RS=P2^0;
sbitLCD_RW=P2^1;
sbitLCD_EN=P2^2;
sbitk1=P1^0;
sbitk2=P1^1;
sbitk3=P1^2;
sbitk4=P1^3;
uinti,shi,fen,miao,nian,yue,ri,count,num,x;
voiddelay_1ms(uintx)/*******延时程序**********/
{
uinti,j;
for(j=0;j for(i=0;i<110;i++); } voidwrite_cmd(ucharcmd)/*****写命令*******/ { LCD_RS=0; LCD_RW=0; LCD_EN=0; P0=cmd; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; } voidwrite_dat(uchardat)/******写数据*****/ { LCD_RS=1; LCD_RW=0; LCD_EN=0; P0=dat; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; } voidlcd_pos(ucharX,ucharY)/*****光标显示位置******/ { ucharpos; if(X==0) {X=0x80;} elseif(X==1) {X=0x90;} elseif(X==2) {X=0x88;} elseif(X==3) {X=0x98;} pos=X+Y; write_cmd(pos); } voidwritesfm(ucharadd,uchardat)/*********显示时间程序*******/ { uchars,g; s=dat/10; g=dat%10; lcd_pos(2,0+add); write_dat(0x30+s); write_dat(0x30+g); } voidwritenyr(ucharadd,uchardat)/*******显示**年**月**日****/ { uchars,g; s=dat/10; g=dat%10; lcd_pos(0,0+add); write_dat(0x30+s); write_dat(0x30+g); } /***********星期显示******************/ voidxi(uchara) { if(a==1) { lcd_pos(1,0); for(i=0;i<14;i++) { write_dat(xi1[i]); delay_1ms(5); } } if(a==2) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi2[i]); delay_1ms(5); } } if(a==3) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi3[i]); delay_1ms(5); } } if(a==4) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi4[i]); delay_1ms(5); } } if(a==5) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi5[i]); delay_1ms(5); } } if(a==6) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi6[i]); delay_1ms(5); } } if(a==7) { lcd_pos(1,0); for(i=0;i<16;i++) { write_dat(xi7[i]); delay_1ms(5); } } } /*********************按键*****************/ voidkey() { if(k1==0) {delay_1ms(10); if(k1==0) { num++; while(! k1); if(num==1) {write_cmd(0x0f); lcd_pos(2,6); TR0=0; } if(num==2) { lcd_pos(2,4); } if(num==3) { lcd_pos(2,2); } if(num==4) { lcd_pos(0,5); } if(num==5) { lcd_pos(0,3); } if(num==6) { lcd_pos(0,1); } if(num==7) { lcd_pos(1,0); } if(num==8) { num=0; write_cmd(0x0c); TR0=1; } } } if(k2==0) { delay_1ms(10); if(k2==0) { while(! k2); if(num==1) { miao++; if(miao==60) { miao=0; } writesfm(6,miao); lcd_pos(2,6); } if(num==2) { fen++; if(fen==60) { fen=0; } writesfm(4,fen); lcd_pos(2,4); } if(num==3) { shi++; if(shi==24) { shi=0; } writesfm(2,shi); lcd_pos(2,2); } if(num==4) { ri++; if(ri==30) { ri=0; } writenyr(5,ri); lcd_pos(0,5); } if(num==5) { yue++; if(yue==13) { yue=1; } writenyr(3,yue); lcd_pos(0,3); } if(num==6) { nian++; if(nian==100) { nian=0; } writenyr(1,nian); lcd_pos(0,1); } if(num==7) { x++; xi(x); if(x==7) { x=0; } } } } if(k3==0) { delay_1ms(10); if(k3==0) { while(! k3); if(num==1) { miao--; if(miao==-1) { miao=59; } writesfm(6,miao); lcd_pos(2,6); } if(num==2) { fen--; if(fen==-1) { fen=59; } writesfm(4,fen); lcd_pos(2,4); } if(num==3) { shi--; if(shi==-1) { shi=23; } writesfm(2,shi); lcd_pos(2,2); } if(num==4) { ri--; if(ri==-1) { ri=30; } writenyr(5,ri); lcd_pos(0,5); } if(num==5) { yue--; if(yue==-1) { yue=12; } writenyr(3,yue); lcd_pos(0,3); } if(num==6) { nian--; if(nian==-1) { nian=99; } writenyr(1,nian); lcd_pos(0,1); } if(num==7) { x--; xi(x); if(x==1) { x=8; } } } } } /*********************************************/ voidlcd_init()/********初始化********/ { LCD_PSB=1; write_cmd(0x30); delay_1ms (1); write_cmd(0x0c); delay_1ms (1); write_cmd(0x01); delay_1ms (1); lcd_pos(0,0); for(i=0;i<14;i++) { write_dat(table[i]); delay_1ms (1); } lcd_pos(1,0); for(i=0;i<15;i++) { write_dat(xi7[i]); delay_1ms (1); } lcd_pos(2,0); for(i=0;i<13;i++) { write_dat(time[i]); delay_1ms (1); } lcd_pos(3,0); for(i=0;i<15;i++) { write_dat(time1[i]); delay_1ms (1); } } voidmain()/********主函数*******/ { lcd_init(); TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; while (1) { key(); if(count==20) { count=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; ri++; x++; xi(x); if(x==7) { x=0; } if(ri==31) { ri=0; yue++; if(yue==13) { yue=0; nian++; if(nian==100) { nian=0; } writenyr(1,nian); } writenyr(3,yue); } writenyr(5,ri); } writesfm(2,shi); } writesfm(4,fen); } writesfm(6,miao); } } } voidt()interrupt1/********中断子函数********/ { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电子钟 按键 12864
![提示](https://static.bdocx.com/images/bang_tan.gif)