玩轉(zhuǎn)單片機(jī)之四-點(diǎn)亮4個數(shù)碼管
#define uchar unsigned char //byte
#define uint unsigned int //word
sbit led1=P0^0;
sbit led2=P0^1;
sbit fir=P2^4; //fir=0;工作
sbit sec=P2^5; //sec=0;工作
sbit thi=P2^6; //thi=0;工作
sbit fot=P2^7; //fot=0;工作
uchar table[]={0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0};
//P1=table[i]; 0 1 2 3 4 5 6 7 8 9
/**************************************************/
/* 延時模塊 聲明:void delay(int); */
/**************************************************/
void delay(int x) //如 delay(1000),延時1s
{
int i,j;
for(i=0;i
}
void main(void)
{/*初始化數(shù)據(jù)*/
uchar a;
a=0x08;
/*串口初始化,波特率為9600*/
TMOD=0x20;
PCON=0x00;
SCON=0x50;
TL1=0xfd;
TH1=0xfd;
TR1=1;
while(1)
{/*點(diǎn)亮4個數(shù)碼管,P2為選擇數(shù)碼管編號,P1為選擇數(shù)字,同時點(diǎn)亮led燈*/
delay(800);P2=0x0F;P1=table[0];led1=0; led2=1;
delay(800);P2=0x0F;P1=table[1];led1=1; led2=0;
delay(800);P2=0x0F;P1=table[2];led1=0; led2=1;
delay(800);P2=0x0F;P1=table[3];led1=1; led2=0;
delay(800);P2=0x0F;P1=table[4];led1=0; led2=1;
delay(800);P2=0x0F;P1=table[5];led1=1; led2=0;
delay(800);P2=0x0F;P1=table[6];led1=0; led2=1;
delay(800);P2=0x0F;P1=table[7];led1=1; led2=0;
delay(800);P2=0x0F;P1=table[8];led1=0; led2=1;
delay(800);P2=0x0F;P1=table[9];led1=1; led2=0;
/*發(fā)送字節(jié)數(shù)據(jù)*/
SBUF=a;
while(TI==0) ;
TI=0;
}
}
評論