完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
#include
#define uint unsigned int #define uchar unsigned char ***it dula=P2^6; ***it wela=P2^7; ***it kaishi=P3^4; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; uchar code tablemin[]={ 0xbf,0x86,0xdb,0xcf, 0xe6,0xed,0xfd,0x87, 0xff,0xef}; uchar t0,t1,SEC,sec1,sec2,min1,min2,temp,num,a,b; uchar keyscan(); void init(); void putin(); void display1(uchar bb,uchar aa); void display(uchar sec1,uchar sec2,uchar min1,uchar min2); void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void main() { init(); putin(); while(1) { if(t0==3) { t0=0; SEC--; if(SEC==-1) { SEC=59; min1--; if(min1==-1) { min2--; min1=9; } } sec1=SEC%10; sec2=SEC/10; } display(sec1,sec2,min1,min2); } } void init() { dula=1; P0=0x3f; dula=0; P0=0xff; wela=1; P0=0x0f; wela=0; TMOD=0x11; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TH1=(65536-5000)/256; TL1=(65536-5000)%256; EA=1; ET0=1; TR0=1; ET1=1; TR1=1; SEC=0; } void display1(uchar bb,uchar aa) { dula=1; P0=tablemin[bb]; dula=0; P0=0xff; wela=1; P0=0xdf; wela=0; delay(10); dula=1; P0=table[aa]; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delay(10); } void display(uchar sec1,uchar sec2,uchar min1,uchar min2) { dula=1; P0=table[sec1]; dula=0; P0=0xff; wela=1; P0=0x7f; wela=0; delay(2); dula=1; P0=table[sec2]; dula=0; P0=0xff; wela=1; P0=0xbf; wela=0; delay(2); dula=1; P0=tablemin[min1]; dula=0; P0=0xff; wela=1; P0=0xdf; wela=0; delay(2); dula=1; P0=table[min2]; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delay(2); } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; t0++; } void timer1() interrupt 3 { TH1=(65536-5000)/256; TL1=(65536-5000)%256; t1++; } uchar keyscan() { P3=0xfe; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xee:num=1; break; case 0xde:num=2; break; case 0xbe:num=3; break; } while(temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfd; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xed:num=4; break; case 0xdd:num=5; break; case 0xbd:num=6; break; } while(temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfb; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xeb:num=7; break; case 0xdb:num=8; break; case 0xbb:num=9; break; } while(temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xf7; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; if(temp==0xd7) num=0; while(temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } return num; } void putin() { while(kaishi==1) { a=keyscan(); display1(0,a); } if(t1==3) { t1=0; TR1=0; } TR1=1; min2=a; while(kaishi==0); if(t1==3) { t1=0; TR1=0; } while(kaishi==1) { b=keyscan(); display1(b,a); } min1=b; TR1=1; if(t1==3) { t1=0; TR1=0; } } ======================================================================= 我的目的是为了 设置min的十位---->确认---->设置min的个位---->确认,并开始计时 遇到的问题: 1)在设置完min的十位按确认之后,min的个位在未确认的情况下显示的是跟十位相同的数字,我本来是想它在设置min个位前显示的是0; 2)在分的十位和个位设计完之后,按了确认键,它不能立即进行计时,会延时一段时间,这是为什么? 是不是因为按键抖动的问题? |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
528 浏览 0 评论
654 浏览 0 评论
858 浏览 0 评论
837 浏览 0 评论
RT-Thread与英飞凌(infineon)合作得板子PSOC 6 板子学习
770 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
17060 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-14 18:06 , Processed in 0.607230 second(s), Total 72, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
5390