


#include "main.h"
#include "Set_Disp.h"






/***********************************************************
函数名称：Set_Disp
函数功能：显示处理 
入口参数：无
出口参数：无          
备    注：1.LCD数码管编码：afbgce_d  
            LCD数码管缺失(从display,1到display,4)："1"/":"/"2"/"加热图标"     
	      2.LED数码管编码：befad_cg
            LED数码管缺失(从display,1到display,4)："."/":" 	  
		    LED灯排序(从SEG2到SEG7)：L1~L8
***********************************************************/
void Set_Disp_Lcd()
{
	if(Flag_Onoff == 0)
	{		
		display[0] = 0x00;	
		display[1] = 0x00;		
		display[2] = 0x00;	
		display[3] = 0x00;	
		display[4] = 0x00;
	
		P_GBLED = 1;  //背光灯关		
	}
	else
	{
		switch(work_mode)
		{
			case 1: Lcd_disp_time(); break;
			case 2:	Lcd_disp_temper(); break;
			default:break;
		}
	}
}
	
		
void Lcd_disp_time()	//设置显示时间数据
{
	P_GBLED = 1;  //背光灯点亮
	
	Hex_To_Bcd(ds_hour);	
	smg_data1 = LCDCode[BCD_H];
	smg_data2 = LCDCode[BCD_L];	
	
	Hex_To_Bcd(ds_min);	
	smg_data3 = LCDCode[BCD_H];
	smg_data4 = LCDCode[BCD_L];			

	if(smg_data1 == LCDCode[0])		//如果最高位显示“0”则不显示
	{
		smg_data1=0;
	}

	ON_LCD_ONE;
	if(	Flag_SS == 0)
		ON_LCD_MH;		
}


void Lcd_disp_temper()  //设置显示温度数据	
{
	P_GBLED = 1;  //背光灯点亮	
	smg_data4 = LCDCode[0x10];	 //显示C
	
	if(Temperature <=0)		//<=0度，显示0度
	{
		smg_data1=0x10;		//显示“-”
		smg_data2=LCDCode[0];
		smg_data3=LCDCode[0];				
	}	
	else if(Temperature >= 100)	//>=100显示100度
	{
		smg_data1=LCDCode[1];		
		smg_data2=LCDCode[0];
		smg_data3=LCDCode[0];		
	}
	else 
	{
		smg_data1 = LCDCode[0];
		Hex_To_Bcd(Temperature);	
		smg_data2 = LCDCode[BCD_H];
		smg_data3 = LCDCode[BCD_L];				
	}
	
		
	if(smg_data1 == LCDCode[0])		//如果最高位显示“0”则不显示
	{
		smg_data1=0;
	}
		
	ON_LCD_TWO;	
}	
	
	
	
	

/***********************************************************
函数名称：Set_Disp
函数功能：显示处理 
入口参数：无
出口参数：无          
备    注：1.LCD数码管编码：afbgce_d  
            LCD数码管缺失(从display,1到display,4)："1"/":"/"2"/"加热图标"     
	      2.LED数码管编码：befad_cg
            LED数码管缺失(从display,1到display,4)："."/":" 	  
		    LED灯排序(从SEG2到SEG7)：L1~L8
***********************************************************/
void Set_Disp_Led()
{
	if(Flag_Onoff == 0)
	{		
		display[0] = 0x00;	
		display[1] = 0x00;		
		display[2] = 0x00;	
		display[3] = 0x00;	
		display[4] = 0x00;
		
		if(	Flag_SS == 1)
		P_GBLED = 0 ;  //背光闪烁
		else
		P_GBLED = 1 ;  
	}
	else
	{
		P_GBLED = 1 ;  
		display[0] = 0x00;
		
		switch(work_mode)
		{
			case 1: Led_disp_time(); break;
			case 2:	Led_disp_temper(); break;
			default:break;
		}
	}
}
	
		
void Led_disp_time()	//设置显示时间数据
{
	ON_LED_1 ;
		
	Hex_To_Bcd(ds_hour);	
	smg_data1 = LEDCode[BCD_H];
	smg_data2 = LEDCode[BCD_L];	
	
	Hex_To_Bcd(ds_min);	
	smg_data3 = LEDCode[BCD_H];
	smg_data4 = LEDCode[BCD_L];			

	if(smg_data1 == LEDCode[0])		//如果最高位显示“0”则不显示
	{
		smg_data1=0;
	}

	if(	Flag_SS == 0)
		ON_LED_MH;		
}


void Led_disp_temper()  //设置显示温度数据	
{
	ON_LED_2 ;
	
	smg_data4 = LEDCode[0x10];	 //显示C
	
	if(Temperature <=0)		//<=0度，显示0度
	{
		smg_data1=0x10;		//显示“-”
		smg_data2=LEDCode[0];
		smg_data3=LEDCode[0];				
	}	
	else if(Temperature >= 100)	//>=100显示100度
	{
		smg_data1=LEDCode[1];		
		smg_data2=LEDCode[0];
		smg_data3=LEDCode[0];		
	}
	else 
	{
		smg_data1 = LEDCode[0];
		Hex_To_Bcd(Temperature);	
		smg_data2 = LEDCode[BCD_H];
		smg_data3 = LEDCode[BCD_L];				
	}
	
		
	if(smg_data1 == LEDCode[0])		//如果最高位显示“0”则不显示
	{
		smg_data1=0;
	}
		
}		
	
	
	
	
	
	
	
	
	
	
	
		
	
	
	

/***********************************************************
函数名称：Disp_Lcd
函数功能：LCD处理
入口参数：无
出口参数：无
备    注：无
***********************************************************/
void Disp_Lcd() 
{	
			LEDCON0 = 0B10000000;  //使能LCD模块、关闭LED模块 
			COMEN = 0B00001111;  //对应IO口为LED功能的COM口(COM0-COM3)		
			TRISC = 0B00001111;	 //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
		
			P_COM_LED = 1;			
		
			if(dcount & 0x01)
			{
				P_SEG1 = 1;
				P_SEG2 = 1;
				P_SEG3 = 1;
				P_SEG4 = 1;
				P_SEG5 = 1;
				P_SEG6 = 1;												
				P_SEG7 = 1;
				P_SEG8 = 1;
			}
			else
			{
				P_SEG1 = 0;
				P_SEG2 = 0;
				P_SEG3 = 0;
				P_SEG4 = 0;
				P_SEG5 = 0;
				P_SEG6 = 0;												
				P_SEG7 = 0;
				P_SEG8 = 0;		
			}	
			

		
			switch(dcount)
			{	
			case 0:	
				P_COM1 = 0;			
				COMEN = 0B00001110;  //使能对应IO口为LED功能的COM口(COM0-COM3)	
				TRISC = 0B00001110;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	 	
				P_COM1 = 0;	
						
				if(display[1] & 0x01)  {P_SEG8 = 1;}			 
				if(display[2] & 0x01)  {P_SEG6 = 1;}							 
				if(display[3] & 0x01)  {P_SEG4 = 1;}
				if(display[4] & 0x01)  {P_SEG2 = 1;}					
				if(display[1] & 0x02)  {P_SEG7 = 1;}
				if(display[2] & 0x02)  {P_SEG5 = 1;}
				if(display[3] & 0x02)  {P_SEG3 = 1;}
				if(display[4] & 0x02)  {P_SEG1 = 1;}																				 
				break;		
			case 1:
				P_COM1 = 1;	
				COMEN = 0B00001110;  //使能对应IO口为LED功能的COM口(COM0-COM3)	
				TRISC = 0B00001110;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM1 = 1;		
			
				if(display[1] & 0x01)  {P_SEG8 = 0;}	
				if(display[2] & 0x01)  {P_SEG6 = 0;}	 
				if(display[3] & 0x01)  {P_SEG4 = 0;}					 
				if(display[4] & 0x01)  {P_SEG2 = 0;}
				if(display[1] & 0x02)  {P_SEG7 = 0;}				
				if(display[2] & 0x02)  {P_SEG5 = 0;}
				if(display[3] & 0x02)  {P_SEG3 = 0;}
				if(display[4] & 0x02)  {P_SEG1 = 0;}			
				break;
				
			case 2:
				P_COM2 = 0;	
				COMEN = 0B00001101;  //使能对应IO口为LED功能的COM口(COM0-COM3) 	
				TRISC = 0B00001101;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口		
				P_COM2 = 0;	
						
				if(display[1] & 0x04)  {P_SEG8 = 1;}				
				if(display[2] & 0x04)  {P_SEG6 = 1;}			 
				if(display[3] & 0x04)  {P_SEG4 = 1;}							 
				if(display[4] & 0x04)  {P_SEG2 = 1;}
				if(display[1] & 0x08)  {P_SEG7 = 1;}				
				if(display[2] & 0x08)  {P_SEG5 = 1;}
				if(display[3] & 0x08)  {P_SEG3 = 1;}
				if(display[4] & 0x08)  {P_SEG1 = 1;}
				break;
			case 3:
				P_COM2 = 1;	
				COMEN = 0B00001101;  //使能对应IO口为LED功能的COM口(COM0-COM3) 		
				TRISC = 0B00001101;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM2 = 1;	
					
				if(display[1] & 0x04)  {P_SEG8 = 0;}				
				if(display[2] & 0x04)  {P_SEG6 = 0;}			 
				if(display[3] & 0x04)  {P_SEG4 = 0;}							 
				if(display[4] & 0x04)  {P_SEG2 = 0;}
				if(display[1] & 0x08)  {P_SEG7 = 0;}				
				if(display[2] & 0x08)  {P_SEG5 = 0;}
				if(display[3] & 0x08)  {P_SEG3 = 0;}
				if(display[4] & 0x08)  {P_SEG1 = 0;}
				break;
			
			case 4:	
				P_COM3 = 0;
				COMEN = 0B00001011;  //使能对应IO口为LED功能的COM口(COM0-COM3) 		
				TRISC = 0B00001011;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM3 = 0;	
						
				if(display[1] & 0x10)  {P_SEG8 = 1;}				
				if(display[2] & 0x10)  {P_SEG6 = 1;}			 
				if(display[3] & 0x10)  {P_SEG4 = 1;}							 
				if(display[4] & 0x10)  {P_SEG2 = 1;}
				if(display[1] & 0x20)  {P_SEG7 = 1;}				
				if(display[2] & 0x20)  {P_SEG5 = 1;}
				if(display[3] & 0x20)  {P_SEG3 = 1;}
				if(display[4] & 0x20)  {P_SEG1 = 1;}
				break;
			case 5:
				P_COM3 = 1;	
				COMEN = 0B00001011;  //使能对应IO口为LED功能的COM口(COM0-COM3) 		
				TRISC = 0B00001011;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM3 = 1;	
						
				if(display[1] & 0x10)  {P_SEG8 = 0;}				
				if(display[2] & 0x10)  {P_SEG6 = 0;}			 
				if(display[3] & 0x10)  {P_SEG4 = 0;}							 
				if(display[4] & 0x10)  {P_SEG2 = 0;}
				if(display[1] & 0x20)  {P_SEG7 = 0;}				
				if(display[2] & 0x20)  {P_SEG5 = 0;}
				if(display[3] & 0x20)  {P_SEG3 = 0;}
				if(display[4] & 0x20)  {P_SEG1 = 0;}
				break;
				
			case 6:
				P_COM4 = 0;	
				COMEN = 0B00000111;  //使能对应IO口为LED功能的COM口(COM0-COM3) 		
				TRISC = 0B00000111;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM4 = 0;	
						
				if(display[1] & 0x40)  {P_SEG8 = 1;}				
				if(display[2] & 0x40)  {P_SEG6 = 1;}			 
				if(display[3] & 0x40)  {P_SEG4 = 1;}							 
				if(display[4] & 0x40)  {P_SEG2 = 1;}
				if(display[1] & 0x80)  {P_SEG7 = 1;}				
				if(display[2] & 0x80)  {P_SEG5 = 1;}
				if(display[3] & 0x80)  {P_SEG3 = 1;}
				if(display[4] & 0x80)  {P_SEG1 = 1;}
				break;
			default:
				P_COM4 = 1;	
				COMEN = 0B00000111;  //使能对应IO口为LED功能的COM口(COM0-COM3) 		
				TRISC = 0B00000111;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
				P_COM4 = 1;	
						
				if(display[1] & 0x40)  {P_SEG8 = 0;}				
				if(display[2] & 0x40)  {P_SEG6 = 0;}			 
				if(display[3] & 0x40)  {P_SEG4 = 0;}							 
				if(display[4] & 0x40)  {P_SEG2 = 0;}
				if(display[1] & 0x80)  {P_SEG7 = 0;}				
				if(display[2] & 0x80)  {P_SEG5 = 0;}
				if(display[3] & 0x80)  {P_SEG3 = 0;}
				if(display[4] & 0x80)  {P_SEG1 = 0;}
				break;			     					
			}
			dcount++; 	if(8 == dcount)  {dcount = 0;}	
}	


/***********************************************************
函数名称：Disp_Led
函数功能：LED处理
入口参数：无
出口参数：无
备    注：无
***********************************************************/
void Disp_Led() 
{	
		TRISC = 0B00000000;  //PORTC,0~PORTC,3--LCD-COM口 ;PORTC,4--LED-COM口	
		
			
		unsigned char data;		
		data = 0;
		if(display[4] & 0x01)  {data |= 0x01;}				
		if(display[3] & 0x01)  {data |= 0x02;}			 
		if(display[2] & 0x01)  {data |= 0x04;}
		if(display[1] & 0x01)  {data |= 0x08;}									 
		if(display[0] & 0x01)  {data |= 0x10;}
		LEDADD = 0x82;
		LEDDATA = data;    
			
		data = 0;
		if(display[4] & 0x02)  {data |= 0x01;}				
		if(display[3] & 0x02)  {data |= 0x02;}			 
		if(display[2] & 0x02)  {data |= 0x04;}
		if(display[1] & 0x02)  {data |= 0x08;}									 
		if(display[0] & 0x02)  {data |= 0x10;}
		LEDADD = 0x83;
		LEDDATA = data;  

		data = 0;
		if(display[4] & 0x04)  {data |= 0x01;}				
		if(display[3] & 0x04)  {data |= 0x02;}			 
		if(display[2] & 0x04)  {data |= 0x04;}
		if(display[1] & 0x04)  {data |= 0x08;}									 
		if(display[0] & 0x04)  {data |= 0x10;}
		LEDADD = 0x84;
		LEDDATA = data; 
		
		data = 0;
		if(display[4] & 0x08)  {data |= 0x01;}				
		if(display[3] & 0x08)  {data |= 0x02;}			 
		if(display[2] & 0x08)  {data |= 0x04;}
		if(display[1] & 0x08)  {data |= 0x08;}									 
		if(display[0] & 0x08)  {data |= 0x10;}
		LEDADD = 0x85;
		LEDDATA = data; 
		
		data = 0;
		if(display[4] & 0x10)  {data |= 0x01;}				
		if(display[3] & 0x10)  {data |= 0x02;}			 
		if(display[2] & 0x10)  {data |= 0x04;}
		if(display[1] & 0x10)  {data |= 0x08;}									 
		if(display[0] & 0x10)  {data |= 0x10;}
		LEDADD = 0x86;
		LEDDATA = data; 
			
		data = 0;
		if(display[4] & 0x20)  {data |= 0x01;}				
		if(display[3] & 0x20)  {data |= 0x02;}			 
		if(display[2] & 0x20)  {data |= 0x04;}
		if(display[1] & 0x20)  {data |= 0x08;}									 
		if(display[0] & 0x20)  {data |= 0x10;}
		LEDADD = 0x87;
		LEDDATA = data; 
				 
		data = 0;
		if(display[4] & 0x40)  {data |= 0x01;}				
		if(display[3] & 0x40)  {data |= 0x02;}			 
		if(display[2] & 0x40)  {data |= 0x04;}
		if(display[1] & 0x40)  {data |= 0x08;}									 
		if(display[0] & 0x40)  {data |= 0x10;}
		LEDADD = 0x89;
		LEDDATA = data; 
		
		data = 0;
		if(display[4] & 0x80)  {data |= 0x01;}				
		if(display[3] & 0x80)  {data |= 0x02;}			 
		if(display[2] & 0x80)  {data |= 0x04;}
		if(display[1] & 0x80)  {data |= 0x08;}									 
		if(display[0] & 0x80)  {data |= 0x10;}
		LEDADD = 0x8A;
		LEDDATA = data; 
		
		LEDCON0 = 0B01110111;  //使能LED模块、COM0~COM4作为LED模块的COM口	
		LEDCON1 = 0B00100000;  //SEG口输出为LEDDATA中的数据	
			
		COMEN = 0B00011111;//0B00010000;//  //对应IO口为LED功能的COM口(COM0~COM4)  
			
		SEGEN0 = 0B11111100;  //对应IO口为LED功能的SEG口(SEG2~SEG7)			
		SEGEN1 = 0B00000110;  //对应IO口为LED功能的SEG口(SEG9/SEG10)		
		SEGEN2 = 0B01001000;  //SEG口驱动电流为4mA	,电流允许LED功能		

}
