/* 实验名:动态数码管显示实验
* 实验说明:8位数码管显示4036
*****************************/
#include<reg51.h>
#define GPIO_DIG P0 //段选
#define GPIO_PLACE P1 //位选
unsigned char code DIG_PLACE[] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f }; //位选控制
unsigned char code DIG_CODE[] = {0x66,0x3f,0x4f,0x7}; //4036
unsigned char DisplayDate[8]; //用来存放要显示的8位数的值
void DigDisplay(); //动态显示函数
//主函数
void main(void)
{
unsigned char i;
for(i=0;i<8;i++)
{
DisplayDate[i] = DIG_CODE[i];
}
while(1)
{
DigDisplay();
}
}
//使用数码管显示
void DigDisplay()
{
unsigned char i;
unsigned int j;
for(i=0;i<8;i++)
{
GPIO_PLACE = DIG_PLACE[i]; //发送位选
GPIO_DIG = DisplayDate[i]; //发送段码
j = 10;
while(j--) //扫描间隔时间设定
GPIO_DIG = 0x00; //消隐
}
}
|