- #include<reg51.h>
- #define uchar unsigned char
- sbit S1=P3^4;
- sbit dula=P2^6;
- sbit wela=P2^7;
- uchar code table[9][8]={
- 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x06,0x30,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,
- 0x00,0x00,0x06,0x36,0x36,0x30,0x00,0x00,
- 0x00,0x00,0x36,0x36,0x36,0x36,0x00,0x00,
- 0x00,0x06,0x36,0x36,0x36,0x36,0x30,0x00,
- 0x00,0x36,0x36,0x36,0x36,0x36,0x36,0x00,
- 0x06,0x36,0x36,0x36,0x36,0x36,0x36,0x30,
- 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36};
- uchar code weia[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- uchar i,j,k;
- void delay_ms(uchar z)
- {
- uchar i,j;
- for(i=z;i>0;i--)
- for(j=110;j>0;j--);
- }
- void keyscan()
- {
- if(S1==0)
- {
- if(++j>10)
- j=11;
- if(j==10)
- {
- k++;
- if(k>8)
- k=0;
- }
- }
- else j=0;
- }
- void display()
- {
- P0=0x00;dula=1;dula=0;
- P0=weia[i];wela=1;wela=0;
- P0=table[k][i];dula=1;dula=0;
- i++;i%=8;
- }
- void main()
- {
- while(1)
- {
- keyscan();
- display();
- delay_ms(1);
- }
- }
复制代码
|