完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include //#include #include ***it R=P2^3; /****it p5=P2^4; ***it p6=P2^5; ***it p7=P2^6; ***it p8=P2^7; */ ***it lcdrs=P2^0; ***it lcdrw=P2^1; ***it lcden=P2^2; //***it led=P3^7; void init(); void delay(unsigned int z); void write_com(unsigned char com); void write_data(unsigned char dat); void display(); unsigned int num,a,b,c,s; unsigned int sum,miao,fen,shi,second,min,hour; unsigned char code table[]={"0123456789:'c"}; unsigned char code table1[]={"SunMonTueWedThuFriSat"}; void main() { s=second=min=hour=0; init(); // SCON=0x00; TH1=(65536-5000)/256; TL1=(65536-5000)%256; TMOD=0X10; EA=1; ET1=1; TR1=1; // R=0; _nop_(); _nop_(); R=1; while(1) display(); } void init() { lcden=0; lcdrw=0; write_com(0x01); //清除显示 write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x80); } void delay(unsigned int z) { unsigned int x,y; for(x=z;x>0;x--) for(y=70;y>0;y--); } void write_com(unsigned char com) { lcdrs=0; P1=com; // SBUF=com; // while(ti==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } void write_data(unsigned char dat) { lcdrs=1; P1=dat; // SBUF=dat; // while(TI==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } /*void show(unsigned long x) { unsigned int num,c,j; unsigned long a=1,k; unsigned char table[]={ 0x30,0x31,0x32,0x33,0x34, 0x35,0x36,0x37,0x38,0x39}; unsigned char y; write_com(0x80+0x40); write_data('='); k=x; while(k!=0) { num++; k=k/10; } for(j=1;j a=a*10; } while(num) { c=x/a; x=x%a; a=a/10; y=table[c]; num--; write_data(y); delay(50); } } */ void show1(void) interrupt 3 { unsigned int q; TH1=(65536-5000)/256; TL1=(65536-5000)%256; q++ ; if(q==200) { q=0; second++; if(second==60) { second=0; min++; if(min==60) { min=0; hour++; if(hour==24) { hour=0; s++; if(s==7) s=0; } } } } } void display(void) { unsigned int a1,a2,b1,b2,c1,c2; write_com(0x80); a1=hour/10;write_data(table[a1]); a2=hour%10;write_data(table[a2]); write_data(table[10]); b1=min/10; write_data(table[b1]); b2=min%10; write_data(table[b2]); write_data(table[10]); c1=second/10; write_data(table[c1]); c2=second%10; write_data(table[c2]); write_com(0xc5); write_data(table1[3*s]); write_data(table1[3*s+1]);write_data(table1[3*s+2]); } 这是可以出结果的 并联 。 下面是改过后的串联程序,就是显示不开 #include //#include #include ***it R=P2^3; /****it p5=P2^4; ***it p6=P2^5; ***it p7=P2^6; ***it p8=P2^7; */ ***it lcdrs=P2^0; ***it lcdrw=P2^1; ***it lcden=P2^2; //***it led=P3^7; void init(); void delay(unsigned int z); void write_com(unsigned char com); void write_data(unsigned char dat); void display(); unsigned int num,a,b,c,s; unsigned int sum,miao,fen,shi,second,min,hour; unsigned char code table[]={"0123456789:'c"}; unsigned char code table1[]={"SunMonTueWedThuFriSat"}; void main() { s=second=min=hour=0; init(); SCON=0x00; TH1=(65536-5000)/256; TL1=(65536-5000)%256; TMOD=0X10; EA=1; ET1=1; TR1=1; R=0; _nop_(); _nop_(); R=1; while(1) display(); } void init() { lcden=0; lcdrw=0; write_com(0x01); //清除显示 write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x80); } void delay(unsigned int z) { unsigned int x,y; for(x=z;x>0;x--) for(y=70;y>0;y--); } void write_com(unsigned char com) { lcdrs=0; SBUF=com; while(TI==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } void write_data(unsigned char dat) { lcdrs=1; SBUF=dat; while(TI==0);TI=0; delay(5); lcden=1; delay(5); lcden=0; } /*void show(unsigned long x) { unsigned int num,c,j; unsigned long a=1,k; unsigned char table[]={ 0x30,0x31,0x32,0x33,0x34, 0x35,0x36,0x37,0x38,0x39}; unsigned char y; write_com(0x80+0x40); write_data('='); k=x; while(k!=0) { num++; k=k/10; } for(j=1;j a=a*10; } while(num) { c=x/a; x=x%a; a=a/10; y=table[c]; num--; write_data(y); delay(50); } } */ void show1(void) interrupt 3 { unsigned int q; TH1=(65536-5000)/256; TL1=(65536-5000)%256; q++ ; if(q==200) { q=0; second++; if(second==60) { second=0; min++; if(min==60) { min=0; hour++; if(hour==24) { hour=0; s++; if(s==7) s=0; } } } } } void display(void) { unsigned int a1,a2,b1,b2,c1,c2; write_com(0x80); a1=hour/10;write_data(table[a1]); a2=hour%10;write_data(table[a2]); write_data(table[10]); b1=min/10; write_data(table[b1]); b2=min%10; write_data(table[b2]); write_data(table[10]); c1=second/10; write_data(table[c1]); c2=second%10; write_data(table[c2]); write_com(0xc5); write_data(table1[3*s]); write_data(table1[3*s+1]);write_data(table1[3*s+2]); } |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
199 浏览 0 评论
使用Keil建立完整的工程,并使用外部中断0触发数码管显示903
748 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
1122 浏览 0 评论
874 浏览 0 评论
910 浏览 1 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11835 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-1 12:46 , Processed in 0.549798 second(s), Total 69, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号