程序源码
/*-----------------------包含头文件区域-------------------------*/
#include<reg52.h> //单片机头文件
/*-----------------------数据类型定义区域-----------------------*/
typedef unsigned char u8; //定义类型unsigned char别名为u8
typedef unsigned int u16; //定义类型unsigned int别名为u16
/*-----------------------用户自定义数据区域---------------------*/
//共阳数码管显示字符数组,分别对应的字符为“0123456789ABCDEF-”
u8 code LED_Table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xBF};
/*-----------------------函数声明区域---------------------------*/
void delay(u16 xms); //延时函数声明
/*-----------------------主函数区域-----------------------------*/
void main()
{
u8 i;
while(1)
{
for(i=0;i<16;i++) //循环显示0~F
{
P2=LED_Table[i]; //显示字符
delay(1000); //延时1000ms
}
}
}
/*----------------------------------------------------------------
函数名称:delay()
函数功能:延时
函数形参:ms为延时时间,延时范围0~65535
返 回 值:无
----------------------------------------------------------------*/
void delay(u16 ms)
{
u8 i;
while(ms--) //循环延时1ms的次数
{
for(i=115;i>0;i--); //延时1ms
}
}