这样可以吗?
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define leddata P0
- sbit cs1=P3^0;sbit cs2=P3^1;sbit wr=P3^2;
- uchar c=0,t=8;
- uchar code ledcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- uchar buf[8];
- void delay(uint i){while(i--);}
- void display()
- {
- uchar i,j=0x7f;
- for(i=0;i<8;i++)
- {
- cs1=0;cs2=1;
- leddata=ledcode[buf[i]];wr=1;wr=0;
- cs1=1;cs2=0;
- leddata=j;wr=1;wr=0;
- delay(100);
- j=_cror_(j,1);
- leddata=0xff;wr=1;wr=0;
- }
- }
- void main()
- {
- //uchar t;
- TMOD=0x01;
- EA=TR0=ET0=1;
-
- while(1){
- buf[0]=t;
- buf[1]=buf[2]=buf[3]=buf[4]=buf[5]=buf[6]=buf[7]=0xff;
- display();
-
- }
- }
- time0() interrupt 1
- {
- TL0=(65536-50000)%0X100;
- TH0=(65536-50000)/0X100;
- c++;
- if(c>=20)
- {
- c=0;
- if(t>0)t--;
- delay(100);
- P1=0x3f;
- delay(50000);
- P1=0xcf;
- delay(50000);
- P1=0xf3;
- delay(50000);
- P1=0xfc;
- delay(50000);
- P1=0xff;
- }
- }
复制代码
|