#include <STC12C5A60S2.h> #include "LEDDisplay.h" #include "Temperature.h" #include "Pins.h" #define Delay_REF 12 //设置每一个点显示的时间长度(1~20) #define LED_PWDDEFAULT 9 // LED的调光值 1~9 #define DT_P2M0SET 0x00 // 0000 0000 #define DT_P2M1SET 0x00 // 0000 0000 #define DT_P0M0SET 0xf0 // 1111 0000 #define DT_P0M1SET 0x00 // 0000 0000 // 数码管 // 12 ~ 9 sbit DT_COM1 = P0 ^ 4; sbit DT_COM2 = P0 ^ 5; sbit DT_COM3 = P0 ^ 6; sbit DT_COM4 = P0 ^ 7; // 8 ~ 1 sbit DT_DpyA = P2 ^ 0; sbit DT_DpyB = P2 ^ 1; sbit DT_DpyC = P2 ^ 2; sbit DT_DpyD = P2 ^ 3; sbit DT_DpyE = P2 ^ 4; sbit DT_DpyF = P2 ^ 5; sbit DT_DpyG = P2 ^ 6; sbit DT_DpyDP = P2 ^ 7; sfr DT_Dpy = 0xA0; // P2 void Delay (unsigned int); void Dis_Off (void); void displayHH1 (unsigned char); void displayHH2 (unsigned char); void displayHH3 (unsigned char); void displayHH4 (unsigned char); data unsigned char Led_PWM; // 调光 1 ~ 9 unsigned char code NumData[]={ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, (None) E, R 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x00, 0x79, 0x77 }; unsigned int Sec = 0; void InitView(void){ P0M0 = DT_P0M0SET; P0M1 = DT_P0M1SET; P2M0 = DT_P2M0SET; P2M1 = DT_P2M1SET; //Dis_Off(); Led_PWM = LED_PWDDEFAULT; } void DisplayTemperature(unsigned int t){ // 无效温度显示 ERR 字样 if (t != VAL_ERRTEMPERATURE){ displayHH4(NumData[t / 1000]); displayHH3(NumData[t / 100 % 10] + 0x80); displayHH2(NumData[t / 10 % 10]); displayHH1(NumData[t % 10]); } else { // 无效温度显示 ERR 字样 //displayHH4(NumData[10]); displayHH3(NumData[11]); displayHH2(NumData[12]); displayHH1(NumData[12]); } } void Delay (unsigned int count){ unsigned int i; while( count-- != 0){ for(i = 0; i < Delay_REF; i++); } } void Dis_Off (void){ DT_COM1 = 0; DT_COM2 = 0; DT_COM3 = 0; DT_COM4 = 0; DT_Dpy = 0xFF; /* DT_DpyA = 1; DT_DpyB = 1; DT_DpyC = 1; DT_DpyD = 1; DT_DpyE = 1; DT_DpyF = 1; DT_DpyG = 1; DT_DpyG = 1; */ Delay(10-Led_PWM); } void displayHH1 (unsigned char d){ if(d & 0x01){ DT_COM1 = 1;DT_DpyA = 0;} Delay(Led_PWM); Dis_Off(); if(d & 0x02){ DT_COM1 = 1;DT_DpyB = 0;} Delay(Led_PWM); Dis_Off(); if(d & 0x04){ DT_COM1 = 1;DT_DpyC = 0;} Delay(Led_PWM); Dis_Off(); if(d & 0x08){ DT_COM1 = 1;DT_DpyD = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x10){ DT_COM1 = 1;DT_DpyE = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x20){ DT_COM1 = 1;DT_DpyF = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x40){ DT_COM1 = 1;DT_DpyG = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x80){ DT_COM1 = 1;DT_DpyDP = 0;}Delay(Led_PWM);Dis_Off(); } void displayHH2 (unsigned char d){ if(d & 0x01){ DT_COM2 = 1;DT_DpyA = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x02){ DT_COM2 = 1;DT_DpyB = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x04){ DT_COM2 = 1;DT_DpyC = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x08){ DT_COM2 = 1;DT_DpyD = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x10){ DT_COM2 = 1;DT_DpyE = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x20){ DT_COM2 = 1;DT_DpyF = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x40){ DT_COM2 = 1;DT_DpyG = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x80){ DT_COM2 = 1;DT_DpyDP = 0;}Delay(Led_PWM);Dis_Off(); } void displayHH3 (unsigned char d){ if(d & 0x01){ DT_COM3 = 1;DT_DpyA = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x02){ DT_COM3 = 1;DT_DpyB = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x04){ DT_COM3 = 1;DT_DpyC = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x08){ DT_COM3 = 1;DT_DpyD = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x10){ DT_COM3 = 1;DT_DpyE = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x20){ DT_COM3 = 1;DT_DpyF = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x40){ DT_COM3 = 1;DT_DpyG = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x80){ DT_COM3 = 1;DT_DpyDP = 0;}Delay(Led_PWM);Dis_Off(); } void displayHH4 (unsigned char d){ if(d & 0x01){ DT_COM4 = 1;DT_DpyA = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x02){ DT_COM4 = 1;DT_DpyB = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x04){ DT_COM4 = 1;DT_DpyC = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x08){ DT_COM4 = 1;DT_DpyD = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x10){ DT_COM4 = 1;DT_DpyE = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x20){ DT_COM4 = 1;DT_DpyF = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x40){ DT_COM4 = 1;DT_DpyG = 0;}Delay(Led_PWM);Dis_Off(); if(d & 0x80){ DT_COM4 = 1;DT_DpyDP = 0;}Delay(Led_PWM);Dis_Off(); }