完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include
#include #define uchar unsigned char #define uint unsigned int ***it sda = P2^0; ***it scl = P2^1; ***it dula = P2^6; ***it wela = P2^7; uchar code tabledu[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0}; uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; uint x,num,temp,yi,wan,qian,bai,shi,ge; void delay1() {;;} void delay(uint z) { uint x, y; for(x=z; x>0; x--) for(y=110; y>0; y--); } void start() { sda = 1; delay1(); scl = 1; delay1(); sda = 0; delay1(); } void stop() { sda = 0; delay1(); scl = 1; delay1(); sda = 1; delay1(); } void response() { uchar i; scl = 1; delay1(); while((sda == 1) && (i<250)) i++; scl = 0; delay1(); } void init() { sda = 1; delay1(); scl = 1; delay1(); } void write_byte(uchar date) { uchar i, temp; temp = date; for(i=0; i<8; i++) { temp = temp << 1; scl = 0; delay1(); sda = CY; delay1(); scl = 1; delay1(); } scl = 0; delay1(); sda = 1; delay1(); } uchar read_byte() { uchar i, k; scl = 0; delay1(); sda = 1; delay1(); for(i=0; i<8; i++) { scl = 1; delay1(); k = (k<<1) | sda; scl = 0; delay1(); } return k; } void write_add(uchar address, uchar date) { start(); write_byte(0xa0); response(); write_byte(address); response(); write_byte(date); response(); stop(); } uchar read_add(uchar address) { uchar date; start(); write_byte(0xa0); response(); write_byte(address); response(); start(); write_byte(0xa1); response(); date = read_byte(); stop(); return date; } void keyscan() { P3=0xfe; temp=P3; temp=temp&0xf0; if(temp!=0xf0) //按下第一排的按键 { delay(10); if(temp!=0xf0) { switch(temp) { case 0xe0: num=1; break; case 0xd0: num=2; break; case 0xb0: num=3; break; case 0x70: break; } x++; while(P3!=0xfe); delay(5); while(P3!=0xfe); } } P3=0xfd; temp=P3; temp=temp&0xf0; if(temp!=0xf0) //按下第二排的按键 { delay(10); if(temp!=0xf0) { switch(temp) { case 0xe0: num=4; break; case 0xd0: num=5; break; case 0xb0: num=6;break; case 0x70: break; } x++; while(P3!=0xfd); delay(5); while(P3!=0xfd); } } P3=0xfb; temp=P3; temp=temp&0xf0; if(temp!=0xf0) //按下第三排的按键 { delay(10); if(temp!=0xf0) { switch(temp) { case 0xe0: num=7; break; case 0xd0: num=8; break; case 0xb0: num=9; break; case 0x70: break; } x++; while(P3!=0xfb); delay(5); while(P3!=0xfb); } } P3=0xf7; temp=P3; temp=temp&0xf0; if(temp!=0xf0) //按下第四排按键 { delay(10); if(temp!=0xf0) { switch(temp) { case 0xe0: wela=1;P0=0xff;wela=0;x=0;break; //0键 case 0xd0: num=0; x++; break; //清零 } while(P3!=0xf7); } } } void answer() { if(x==1) { yi=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; } if(x==2) { wan=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; delay(1); dula=1; P0=tabledu[wan]; dula=0; P0=0xff; wela=1; P0=tablewe[1]; wela=0; delay(1); } if(x==3) { qian=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; delay(1); dula=1; P0=tabledu[wan]; dula=0; P0=0xff; wela=1; P0=tablewe[1]; wela=0; delay(1); dula=1; P0=tabledu[qian]; dula=0; P0=0xff; wela=1; P0=tablewe[2]; wela=0; delay(1); } if(x==4) { bai=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; delay(1); dula=1; P0=tabledu[wan]; dula=0; P0=0xff; wela=1; P0=tablewe[1]; wela=0; delay(1); dula=1; P0=tabledu[qian]; dula=0; P0=0xff; wela=1; P0=tablewe[2]; wela=0; delay(1); dula=1; P0=tabledu[bai]; dula=0; P0=0xff; wela=1; P0=tablewe[3]; wela=0; delay(1); } if(x==5) { shi=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; delay(1); dula=1; P0=tabledu[wan]; dula=0; P0=0xff; wela=1; P0=tablewe[1]; wela=0; delay(1); dula=1; P0=tabledu[qian]; dula=0; P0=0xff; wela=1; P0=tablewe[2]; wela=0; delay(1); dula=1; P0=tabledu[bai]; dula=0; P0=0xff; wela=1; P0=tablewe[3]; wela=0; delay(1); dula=1; P0=tabledu[shi]; dula=0; P0=0xff; wela=1; P0=tablewe[4]; wela=0; delay(1); } if(x==6) { ge=num; dula=1; P0=tabledu[yi]; dula=0; P0=0xff; wela=1; P0=tablewe[0]; wela=0; delay(1); dula=1; P0=tabledu[wan]; dula=0; P0=0xff; wela=1; P0=tablewe[1]; wela=0; delay(1); dula=1; P0=tabledu[qian]; dula=0; P0=0xff; wela=1; P0=tablewe[2]; wela=0; delay(1); dula=1; P0=tabledu[bai]; dula=0; P0=0xff; wela=1; P0=tablewe[3]; wela=0; delay(1); dula=1; P0=tabledu[shi]; dula=0; P0=0xff; wela=1; P0=tablewe[4]; wela=0; delay(1); dula=1; P0=tabledu[ge]; dula=0; P0=0xff; wela=1; P0=tablewe[5]; wela=0; delay(1); } } void main() { init(); x=read_add(2); delay(100); while(1) { write_add(2,x); keyscan(); answer(); } } |
|
相关推荐
1个回答
|
|
用郭天祥的板子做的STC89C52
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】(第三篇)ADC采集+PWM输出
489 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十五章 人脸识别实验
498 浏览 0 评论
655 浏览 0 评论
如何用OpenCV的相机捕捉视频进行人脸检测--基于米尔NXP i.MX93开发板
1329 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十章 YOLO2人手检测实验
558 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11752 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 14:40 , Processed in 0.531353 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号