|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
- #include <reg52.h>#include <intrins.h>#define ad_con P2#define addata P0#define disdata P1#define uchar unsigned char#define uint unsigned intuchar number=0x00;sbit ALE=P2^3;sbit START=P2^4;sbit OE=P2^5;sbit EOC=P3^7;sbit KEY1=P3^5;sbit KEY2=P3^6;sbit DISX=disdata^7;sbit FLAG=PSW^5;
- uchar code dis_7[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77}; uchar code scan_con[4]={0xfe,0xfd,0xfb,0xf7}; uchar data ad_data[8]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};uint data dis[5]={0x00,0x00,0x00,0x00,0x00};
- void delay1ms(uint t) { uint i,j; for (i=0;i<t;i++) for (j=0;j<120;j++); }
- void keytest() { if (KEY1==0) { FLAG=!FLAG; while(KEY1==0); } if(FLAG==1) { if(KEY2==0) { number++; if(number==8) { number=0; } while(KEY2==0); } } }
- void scan() { uchar k,n; int h; if(FLAG==0) { dis[3]=0x00; for(n=0;n<8;n++) { dis[2]=ad_data[n]/51; dis[4]=ad_data[n]%51; dis[4]=dis[4]*10; dis[1]=dis[4]/51; dis[4]=dis[4]%51; dis[4]=dis[4]*10; dis[0]=dis[4]/51; for(h=0;h<500;h++) { for(k=0;k<4;k++) { disdata=dis_7[dis[k]]; if(k==2) { DISX=1; } P3=scan_con[k]; delay1ms(1); P3=0xff; } } dis[3]++; keytest(); } } if(FLAG==1) { dis[3]=number; dis[2]=ad_data[n]/51; dis[4]=ad_data[n]%51; dis[4]=dis[4]*10; dis[1]=dis[4]/51; dis[4]=dis[4]%51; dis[4]=dis[4]*10; dis[0]=dis[4]/51; for(k=0;k<4;k++) { disdata=dis_7[dis[k]]; if(k==2) { DISX=0; } P3=scan_con[k];delay1ms(1);P3=0xff; } keytest(); } }
- void test() { uchar m; uchar s=0x00; ad_con=s; for(m=0;m<8;m++) { START=1;_nop_();_nop_();START=0; _nop_();_nop_();_nop_();_nop_(); while(EOC==0); OE=1;ad_data[m]=addata;OE=0; s++;ad_con=s; } ad_con=0x00; }
- main() { P0=0xff; P2=0x00; P1=0xff; P3=0xff; while(1) { test(); scan(); }}
复制代码 |
|