/************************************************************* 数码管头文件 实现功能:数码管的控制 补充说明: ***************************************************************/ #ifndef _SMG_H_ #define _SMG_H_ #include #define uchar unsigned char #define uint unsigned int /*****************数码管引脚定义*******************/ #define duan P0 sbit w1=P2^4; sbit w2=P2^5; sbit w3=P2^6; sbit w4=P2^7; /*****************数码管变量定义*******************/ uchar code wei1[]={0xa0,0xbb,0x62,0x2a,0x39,0x2c,0x24,0xba,0x20,0x28,0x7f,0x74}; //数码管显示段码 uchar code wei2[]={0x80,0x9b,0x42,0x0a,0x19,0x0c,0x04,0x9a,0x00,0x08,0x5f,0x74}; //数码管显示段码,带小数点 /*****************数码管函数定义*********************/ void Delay(unsigned int num); //延时函数 void display(uchar a,uchar b,uchar c,uchar d); //显示函数 /******************************************************** 函数名称:void Delay(unsigned int num) 函数作用:US延时函数 参数说明: ********************************************************/ void Delay(unsigned int num) { while( --num ) ; } /******************************************************** 函数名称:void display(uchar a,uchar b,uchar c,uchar d) 函数作用:数码管显示函数 参数说明:a:百位,b:十位,c:个位,d:十分位 ********************************************************/ void display(uchar a,uchar b,uchar c,uchar d) { duan=wei1[a];//不带小数点 w1=0; Delay(300); w1=1; duan=wei1[b];//不带小数点 w2=0; Delay(300); w2=1; duan=wei1[c];//带小数点 w3=0; Delay(300); w3=1; duan=wei1[d];//不带小数点 w4=0; Delay(300); w4=1; } #endif