51單片機程序——按鍵控制數(shù)碼管程序0-999遞增
#define DataPort P0 //定義數(shù)據(jù)端口 程序中遇到DataPort 則用P0 替換
#define CtrlPort P1 //定義控制端口
#define uint unsigned int
unsigned char code DuanMa[10]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x90};// 顯示段碼值0~9
unsigned char code WeiMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//分別對應相應的數(shù)碼管點亮,即位碼
unsigned char TempData[8]; //存儲顯示值的全局變量
sbit key=P3^1; //對應于s18按鍵
void Delay(unsigned int t); //函數(shù)聲明
void Display(unsigned char FirstBit,unsigned char Num);
void delay1(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main (void)
{
// DuanMa=0xff;
while(1)
{
if(key==0)
{
delay1(5);
if(key==0)
{
a++;
while(!key);
}
}
TempData[0]=DuanMa[a]; //分解顯示信息,
Display(0,3);
}
void Delay(unsigned int t)
{
}
void Display(unsigned char FirstBit,unsigned char Num)
{
}
關鍵詞:
51單片機按鍵控制數(shù)碼
評論