#include<reg51.h> #include<AT24C02.h> #define uchar unsigned char #define uint unsigned int sbit P3_2=P3^2; uchar code led_mod[]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f,0x00}; uchar code BitCode[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; uchar huanchong[]={10,10,10,10,10,10,10,10}; uchar convert[]={10,10,10,10,10,10,10,10}; uchar a=0; void int0() interrupt 0 { uchar code RowCode[]={0xfe,0xfd,0xfb,0xf7}; uchar temp,row,column,i,y,z; uchar m,n; P1=0xf0; temp = P1 & 0xf0; if (temp != 0xf0) { P2=0xff; switch (temp) { case 0x70: column = 3; break; case 0xb0: column = 2; break; case 0xd0: column = 1; break; case 0xe0: column = 0; break; default: break; } for (i=0;i<4;i++) { P1 = RowCode[i]; temp = P1 & 0xf0; if (temp !=0xf0) { row = i;break; } } y= row *4 + column; if(y<10) { if(a<8) { huanchong[a++]=y; m=a; for(n=0;n<a;n++) { convert[n]=huanchong[--m]; } } } if(y>=10) { P2=0xff; a=0; for(z=0;z<8;z++) { huanchong[z]=10; convert[z]=10; } } while((P1 & 0xf0) !=0xf0); } } void BufToSeg(void) { uchar i=0; for(;i<8;i++) { P0=led_mod[10]; P2= BitCode[i]; P0=led_mod[convert[i]]; } } void main(void) { EA=1; EX0=1; IT0=1; while(1) { P1=0x0f; BufToSeg(); } } |
前面的程序图不完整C:\Users\19429\Desktop |