具備程序移植功能的四位數(shù)碼管顯示
#define uint unsigned int
#define uchar unsigned char
uchar code num[]={0XC0,0XF9,0XA4,0XB0,0X99,
0X92,0X82,0XF8,0X80,0X90};
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
sbit p23=P2^3;
void delay(uint z)
{
while(z--);
}
void disp(uchar a,b,c,d)
{
P2=0x00;
p20=1;
P0=num[a];
delay(500);
p20=0;
p21=1;
P0=num[b];
delay(500);
p21=0;
p22=1;
P0=num[c];
delay(500);
p22=0;
p23=1;
P0=num[d];
delay(500);
p23=0;
}//以上程序可定義成7seg.h頭文件,需要時直接加載,具體格式為:#include"7seg.h"
void main()
{
while(1)
{
disp(2,0,1,5);
}
}
評論