微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机计数器计数数码管显示

51单片机计数器计数数码管显示

时间:11-28 来源:互联网 点击:
#include

#define uint unsigned int
#define uchar unsigned char

uchar code smg_tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//{0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60,0x30,0x25,0xa9,0x26,0xa1,0Xb1};
uchar code bit_tab[]={0x7f,0xbf};

uchar Counts=0;
uchar Display_Buffer[2]={0,0};

void _delay_ms(uint x)
{
uchar i;
while(x--)
for(i=0;i<120;i++);
}

void main(void)
{
uchar i;
TMOD=0x06;
ET0=1;
TR0=1;
EA=1;
TH0=255;
TL0=255;
while(1)
{Display_Buffer[0]=Counts;
Display_Buffer[1]=Counts/10;

///for(i=0;i<2;i++)
//{
P2=0x7f;
P0=smg_tab[Display_Buffer[0]];
_delay_ms(2);
//P2=0xbf;
//P0=smg_tab[Counts/10];
//_delay_ms(100);
//}
if(Counts==100)Counts=0;
}
}

void Int0_Count() interrupt 1
{
Counts++;

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top