?? led.c
字號:
#include"inc/config.h"
u08 LedData[11]; //各位顯存的初始化
u08 fLedDotMap=0x00 ; //對應WEI為1 則數碼管加“.”
BOOL fledalrm ; //主要是0-4位
/**共陰***/
const u08 PROGMEM LedSeg[29]=
{
0x3f,/*0*/
0x06,/*1*/
0x5b,/*2*/
0x4f,/*3*/
0x66,/*4*/
0x6d,/*5*/
0x7d,/*6*/
0x07,/*7*/
0x7f,/*8*/
0x6f,/*9*/
0x77,/*a*/ //10
0x7c,/*b*/ //11
0x39,/*c*/ //12
0x58,/*c*/ //13
0x5e,/*d*/ //14
0x79,/*e*/ //15
0x71,/*f*/ //16
0x76,/*h*/ //17
0x74,/*h*/ //18
0x38,/*l*/ //19
0x54,/*n*/ //20
0x37,/*n*/ //21
0x5c,/*o*/ //22
0x73,/*p*/ //23
0x50,/*r*/ //24
0x78,/*t*/ //25
0x3e,/*u*/ //26
0x40,/*-*/ //27
0x00/*消隱碼*/ //28
};
void DispSeperateShow( unit8 content,unit8 position )
{
DIG_RST();//共陰極。消隱,防止數據亂碼,可去,因ByteTo164中已經包含
ByteToHC164( content );
if(position == DIG1){ LED1 = LED_ON;}
else if(position == DIG2){ LED2 = LED_ON;}
else if(position == DIG3){ LED3 = LED_ON;}
else if(position == DIG4){ LED4 = LED_ON;}
else if(position == DIG5){ LED5 = LED_ON;}
else if(position == DIG6){ LED0 = LED_ON;}
else if(position == DIG7){ LED6 = LED_ON;}
else if(position == DIG8){ LED6 = LED_ON;}
else if(position == DIG9){ LED6 = LED_ON;}
}
void ByteToHC164(uint8 ledbuffer)
{
//DIG_RST(); //令所有位選置1
SEG_A = (ledbuffer&(1<<0))>>0;
SEG_B = (ledbuffer&(1<<1))>>1;
SEG_C = (ledbuffer&(1<<2))>>2;
SEG_D = (ledbuffer&(1<<3))>>3;
SEG_E = (ledbuffer&(1<<4))>>4;
SEG_F = (ledbuffer&(1<<5))>>5;
SEG_G = (ledbuffer&(1<<6))>>6;
SEG_DP= (ledbuffer&(1<<7))>>7;
}
void Hex2Bcd( uint16 bytevalue,uint8 bcdval[5] )
{
u08 j;
for ( j = 0; j < 5 ;j++)
{
bcdval[j]= 0;
}
//萬位處理
while( bytevalue >= 10000) //20060402 判斷中的>=不能寫成>,否則有錯,特別是會
//各位數為10,在顯示時顯示成“a”
{
bcdval[0]++;
bytevalue-=10000;
}
//千位處理
while( bytevalue >= 1000)
{
bcdval[1]++;
bytevalue-=1000;
}
//百位處理
while( bytevalue >= 100)
{
bcdval[2]++;
bytevalue-=100;
}
//十位處理
while(bytevalue >= 10)
{
bcdval[3]++;
bytevalue-=10;
}
//個位處理
bcdval[4]=bytevalue;
}
/**************************************************************
* functionname: signal(sig_overflow0)
***************************************************************/
static uint16 cnt = 0 ; /*軟定時器,用于設定時標 */
static uint8 LedCnt = 0 ; /*用于數碼管的刷新計數 */
static uint16 fLedFlashMap= 0 ; /*用于閃爍位的指示 */
static uint8 fFlashison = 0 ; /*指示閃爍中的明暗兩種狀態 */
static u08 tick_15ms = 0 ;
static u16 tick_500ms = 0 ;
static u16 tick_1s = 0 ;
static u16 tick_5s = 0 ;
static u16 tick_60s = 0 ;
/*********定時器2的中斷,來產生系統工作的基本時序**************/
//SIGNAL(SIG_OVERFLOW2)
SIGNAL(SIG_OVERFLOW0)
{
u08 ledbuffer = 0;
//TCNT2 = TIMER2_BGN_VAL;
TCNT0 = TIMER0_BGN_VAL;
if( tick_15ms++ >= 15/T0_TICK &&f_15ms==false ) { tick_15ms =0;f_15ms=true; }
if( tick_500ms++>= 1000/T0_TICK&&f_500ms==false ) { tick_500ms=0;f_500ms=true;}
if( tick_1s++ >= 2000/T0_TICK&&f_1s==false ) { tick_1s =0;f_1s=true; }
if( tick_5s++ >= 3000/T0_TICK&&f_5s==false ) { tick_5s =0;f_5s=true; }
if( tick_60s++ >= 20000/T0_TICK&&f_60s==false ) { tick_60s =0;f_60s=true; }
if( ++cnt > (200/T0_TICK) )
{
cnt =0;
fFlashison =~ fFlashison;
}
ledbuffer =LedData[LedCnt];
//--------------------------------------------------------------------------------
if( ( fLedFlashMap&(1<<LedCnt))!=0 )
{
ledbuffer =ledbuffer&fFlashison;//
}
//----------------------------------------------------------------
DispSeperateShow ( ledbuffer , LedCnt );
LedCnt ++ ;
if( DIGMAX == LedCnt ) LedCnt=1;
}
void FlashDigRst(void)
{
fLedFlashMap = 0;
}
void FlashDigOn(uint16 whichDig)
{
fLedFlashMap|= (1<<whichDig);
}
void FlashDigOff(uint16 whichDig)
{
fLedFlashMap&= ~(1<<whichDig);
}
/**************add num pot***************/
void RmvDotAll(void)
{
fLedDotMap = 0;
}
void AddDotOn(uint16 whichDig)
{
fLedDotMap|= (1<<whichDig);
}
void RmvDot(uint16 whichDig)
{
fLedDotMap&= ~(1<<whichDig);
}
/*******************************************************************
* subname: void Displayhumidity(uint8 humidity);
********************************************************************/
void DisplayHumidity(uint8 humidity)
{
if((humidity>100))
{
LedData[4] = 0x40 ; //directly pass the value to led buffer
LedData[5] = 0x40 ;
LedData[6] = 0x40 ;
}
else
{
if(humidity==100)
{
LedUpdateByDig(4,humidity/100 ) ;//也可用該函數
}
else
{
LedData[4] = 0x00 ;
}
LedUpdateByDig(5,humidity/10 ) ;//也可用該函數
LedUpdateByDig(6,humidity%10 ) ;//也可用該函數
}
}
void LedUpdateByDig(uint8 Dig_n,uint8 led_val )
{
if( ( (fLedDotMap&(1<<Dig_n)) !=0 )&& (led_val!=28))
//content!=0x00 消除發消隱時
{
LedData[Dig_n] =pgm_read_byte(LedSeg+led_val)|0x80;
//段碼最高位疊加小數點位
}
else
{
LedData[Dig_n] =pgm_read_byte(LedSeg+led_val);
}
}
/*
* 顯示溫度工作狀態,TH TL OR NO_ALARM
*/
void DisplayTemperatureAlarm( u08 on_off)
{
//根據報警狀態 點亮相應指示燈
LedData[DIG7] = on_off*SEGA;
}
/*
* 顯示適度報警,直接修改對應指示燈的顯存值
*/
void DisplayHumidityAlarm(u08 on_off)
{
LedData[DIG8] =on_off*SEGE;
}
void DisplayPower(u08 on_off)
{
LedData[DIG9] =on_off*SEGD;
}
/*
* 復位軟定時器
*/
void RstSoftTimer(u08 n)
{
if (n==_15MS) { tick_15ms = 0; f_15ms = false; }
else if (n==_500MS) { tick_500ms = 0; f_500ms = false; }
else if (n==_1S) { tick_1s = 0; f_1s = false; }
else if (n==_60S) { tick_60s = 0; f_60s = false; }
}
void DisplayTemperature(int16 temperature)
{
u08 offset;
if(SystemStatus==RUN)
{
offset =0;
}
else
{
offset =3;
}
RmvDot(2+offset);
if( ( temperature >1250) || (temperature<-400) )
{
RmvDot(2+offset);;
LedUpdateByDig(1+offset,27);
LedUpdateByDig(2+offset,27);
LedUpdateByDig(3+offset,27);
}
else
{
uint8 tempconvertbuffer[5]={0,0,0,0,0};
if (temperature >= 1000)
{
RmvDot(2+offset);;
Hex2Bcd(temperature,tempconvertbuffer);
LedUpdateByDig(1+offset,tempconvertbuffer[1]);
LedUpdateByDig(2+offset,tempconvertbuffer[2]);
LedUpdateByDig(3+offset,tempconvertbuffer[3]);
}
else if(temperature >= 100)
{
AddDotOn(2+offset);
Hex2Bcd(temperature,tempconvertbuffer);
LedUpdateByDig(1+offset,tempconvertbuffer[2]);
LedUpdateByDig(2+offset,tempconvertbuffer[3]);
LedUpdateByDig(3+offset,tempconvertbuffer[4]);
}
else if(temperature >= 0)
{
AddDotOn(2+offset);
LedUpdateByDig(1+offset,28);
LedUpdateByDig(2+offset,temperature/10);
LedUpdateByDig(3+offset,temperature%10);
}
else if(temperature > -100)
{
temperature=-temperature;
AddDotOn(2+offset);
LedUpdateByDig(1+offset,27);
LedUpdateByDig(2+offset,temperature/10);
LedUpdateByDig(3+offset,temperature%10);
}
else if(temperature >=-400)
{
temperature=-temperature;
RmvDot(2+offset);
LedUpdateByDig(1+offset,27);
LedUpdateByDig(2+offset,temperature/100);
LedUpdateByDig(3+offset,temperature%100/10);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -