//引脚对应P5.0~5.7: BCEDFAGH #include "Include.h" static u8 DigNum = 0; static u8 const smgduan[16] = { /*0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F,*/ 0x3F,0x03,0xAD,0xAB,0x93,0xBA,0xBE,0x23,0xBF,0xBB,0xB7,0x9E,0x3C,0x8F,0xBC,0xB4 //0xC0,0xFC,0x52,0x54,0x6C,0x45,0x41,0xDC,0x40,0x44,0x48,0x61,0xC3,0x70,0x43,0x4B };//显示0~F的值 static u8 Smg_Arrary[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0xFF }; static u8 Smg_Arrary_i = 0; /******************************************************************************* * 函 数 名 : delay * 函数功能 : 延时函数,i=1时,大约延时10us *******************************************************************************/ void delay ( u16 i ) { while ( i-- ); } void Smg_Init ( void ) { } void Smg_Display(u8 Num) { DigNum = Num; } void Smg_Display_Next(void) { if(++Smg_Arrary_i >= ARRAY_SIZE(Smg_Arrary)) Smg_Arrary_i = 0; DigNum = Smg_Arrary[Smg_Arrary_i]; } void Smg_Display_OnOff(bool On) { Smg_Arrary_i = (On)?(0):(ARRAY_SIZE(Smg_Arrary)-1); DigNum = Smg_Arrary[Smg_Arrary_i]; } //pos:0~1 //Num:0~9, void Smg_PlayOne(u8 Pos, u8 Num) { Num = (Num<=9)?(~smgduan[Num]):(0xFF); switch ( Pos ) //位选,选择点亮的数码管, { case 0: LED_DATA = 0; LED_COM1(0); //低亮 LED_COM2(1); LED_DATA = Num; //发送段码 break;//显示第0位 case 1: LED_DATA = 0; LED_COM1(1); LED_COM2(0); //低亮 LED_DATA = Num; //发送段码 break;//显示第1位 } } void Smg_test(void) //10ms { static u8 time = 0; #if 0 static u8 Num = 0; if(time++>=100) { time = 0; LED_COM1(1); LED_COM2(1); //低亮 Num++; if(Num>7) Num=0; LED_DATA = ~(1<=50) { time = 0; DigNum += 11; if(DigNum%11 != 0) DigNum=0; if(DigNum>99) DigNum=0; } #endif } void Smg_Refrensh(void) //10ms { static u8 Step = 0; u8 units,tens; switch ( Step ) { case 0 : //个位 units = (DigNum<99)?(DigNum%10):(0xFF); Smg_PlayOne(0, units); Step = 1; break; case 1 : //十位 tens = (DigNum<99)?((DigNum/10)%10):(0xFF); Smg_PlayOne(1, tens); Step = 0; break; } //Smg_test(); } /******************************************************************************* * 函 数 名 : DigDisplay * 函数功能 : 数码管动态扫描函数,循环扫描8个数码管显示 *******************************************************************************/ void DigDisplay() { u8 i; for ( i = 0; i < 4; i++ ) { switch ( i ) //位选,选择点亮的数码管, { case ( 0 ) : LED_COM1(0); LED_COM2(1); break;//显示第0位 case ( 1 ) : LED_COM1(1); LED_COM2(0); break;//显示第1位 } LED_DATA = smgduan[i]; //发送段码 delay ( 100 ); //间隔一段时间扫描 LED_DATA = 0x00; //消隐 } }