/*******************************************************************************
* Device      : AD18F06A
* Author      :
* Version     :
* Date        :
* Description :
* Note		  :
********************************************************************************/

/********************************INCLUDES*************************************/
#include <stdio.h>
#include "AD18F06A.h"

__CONFIG(1,_FINTOSC_DIV1_1L   & _LVREN_OFF_1L      & _LVR24V_1L                                                                                          );
__CONFIG(2,_FLASH_CP7_OFF_2L  & _FLASH_CP6_OFF_2L  & _FLASH_CP5_OFF_2L   & _FLASH_CP4_OFF_2L   & _FLASH_CP3_OFF_2L
         & _FLASH_CP2_OFF_2L  & _FLASH_CP1_OFF_2L  & _FLASH_CP0_OFF_2L   & _CRYLEN_OFF_2L      & _CRYHEN_OFF_2L
  	     & _IDIS_ON_2L        & _CKSUM_OFF_2L      & _CBP_OFF_2L         & _RESETE_OFF_2L      & _RSEL_LOW_2L     & _STV_ON_2L              	         );
__CONFIG(3,_DBG_OFF_3L        & _PSUT_8_3L         & _FCPU_2T_3L         & _WDTEN_OFF_3L       & _TWDT_011_3L                                            );
__CONFIG(4,_OSCM_HIRC_16M_4L  & _ENVDDL_ON_4L      & _EEDIS_OFF_4L       & _FLDIS_OFF_4L       & _FCMEN_OFF_4L    & _IESO_OFF_4L&  _DBGS_IOSEL_1_4L      );

static volatile unsigned char SEG0@0X400  = 0;
static volatile unsigned char SEG1@0X401  = 0;
static volatile unsigned char SEG2@0X402  = 0;
static volatile unsigned char SEG3@0X403  = 0;
static volatile unsigned char SEG4@0X404  = 0;
static volatile unsigned char SEG5@0X405  = 0;
static volatile unsigned char SEG6@0X406  = 0;
static volatile unsigned char SEG7@0X407  = 0;
static volatile unsigned char SEG8@0X408  = 0;
static volatile unsigned char SEG9@0X409  = 0;
static volatile unsigned char SEG10@0X40A = 0;
static volatile unsigned char SEG11@0X40B = 0;
static volatile unsigned char SEG12@0X40C = 0;
static volatile unsigned char SEG13@0X40D = 0;
static volatile unsigned char SEG14@0X40E = 0;
static volatile unsigned char SEG15@0X40F = 0;
static volatile unsigned char SEG16@0X410 = 0;
static volatile unsigned char SEG17@0X411 = 0;
static volatile unsigned char SEG18@0X412 = 0;

//GDC0689T(P)LCD
const unsigned char dis0[10]={0xBE,0x06,0x7C,0x5E,0xC6,0xDA,0xFA,0x0E,0xFE,0xDE};
const unsigned char dis1[10]={0xD7,0x06,0xE3,0xA7,0x36,0xB5,0xF5,0x07,0xF7,0xB7};


void display1_4(unsigned char a1,unsigned char a2,unsigned char a3,unsigned char a4)
{
	 unsigned char a1_H,a1_L;
     unsigned char a2_H,a2_L;
     unsigned char a3_H,a3_L;
     unsigned char a4_H,a4_L;

     a1_H = ((dis0[a1] & 0xf0) >> 4);
	 a1_L = ( dis0[a1] & 0x0f);

     a2_H = ((dis0[a2] & 0xf0) >> 4);
	 a2_L = ( dis0[a2] & 0x0f);

     a3_H = ((dis0[a3] & 0xf0) >> 4);
	 a3_L = ( dis0[a3] & 0x0f);

     a4_H = ((dis0[a4] & 0xf0) >> 4);
	 a4_L = ( dis0[a4] & 0x0f);


	SEG0  = a1_H;SEG1  = a1_L;
	SEG2  = a2_H;SEG3  = a2_L;
	SEG4  = a3_H;SEG5  = a3_L;
	SEG6  = a4_H;SEG7  = a4_L;
}

void display5_10(unsigned char a5,unsigned char a6,unsigned char a7,unsigned char a8)
{
	 unsigned char a5_H,a5_L;
	 unsigned char a6_H,a6_L;
	 unsigned char a7_H,a7_L;
	 unsigned char a8_H,a8_L;

	 a5_H = ((dis1[a5] & 0xf0) >> 4);
	 a5_L = ( dis1[a5] & 0x0f);

	 a6_H = ((dis1[a6] & 0xf0) >> 4);
	 a6_L = ( dis1[a6] & 0x0f);

	 a7_H = ((dis1[a7] & 0xf0) >> 4);
	 a7_L = ( dis1[a7] & 0x0f);

	 a8_H = ((dis1[a8] & 0xf0) >> 4);
	 a8_L = ( dis1[a8] & 0x0f);

	SEG11 = a5_H; SEG12 = a5_L;
	SEG13 = a6_H; SEG14 = a6_L;
	SEG15 = a7_H; SEG16 = a7_L;
	SEG17 = a8_H; SEG18 = a8_L;
}


void display_Symbol(unsigned char Sy2)
{
	switch(Sy2)
	{
		case 1:
		{
            SEG8 = 0x0C;SEG9  = 0x08;SEG10 = 0x08;
		}
		break;
		case 2:
		{
            SEG8 = 0x08;SEG9  = 0x0C;SEG10 = 0x0C;
		}
		break;
		case 3:
		{
            SEG8 = 0x0C;SEG9  = 0x0E;SEG10 = 0x0E;
		}
		break;
		case 4:
		{
            SEG8 = 0x08;SEG9  = 0x0F;SEG10 = 0x0F;
		}
		break;
		case 5:
		{
            SEG8 = 0x0C;SEG9  = 0x08;SEG10 = 0x08;
		}
		break;
		case 6:
		{
            SEG8 = 0x08;SEG9  = 0x0C;SEG10 = 0x0C;
		}
		break;
		case 7:
		{
            SEG8 = 0x0C;SEG9  = 0x0E;SEG10 = 0x0E;
		}
		break;
		case 8:
		{
            SEG8 = 0x08;SEG9  = 0x0F;SEG10 = 0x0F;
		}
		break;
		case 9:
		{
            SEG8 = 0x0C;SEG9  = 0x0A;SEG10 = 0x0A;
		}
		break;
		default :
		{
            SEG8 = 0x00;SEG9  = 0x00;SEG10 = 0x00;
		}
		break;
	}
}


void main(void)
{
	unsigned char Temp = 1;

	__delay_ms(20);
	//LCD初始化
	LCDCON0 = 0x01;
	LCDCON1 = 0x08;
	COMEN   = 0x0F;
	SEGEN0  = 0xFF;
    SEGEN1  = 0xFF;
    SEGEN2  = 0x37;

	SEG0  = 0x00;SEG1  = 0x00;
	SEG2  = 0x00;SEG3  = 0x00;
	SEG4  = 0x00;SEG5  = 0x00;
	SEG6  = 0x00;SEG7  = 0x00;
	SEG8  = 0x00;SEG9  = 0x00;
	SEG10 = 0x00;
	SEG11 = 0x00;SEG12 = 0x00;
	SEG13 = 0x00;SEG14 = 0x00;
	SEG15 = 0x00;SEG16 = 0x00;
	SEG17 = 0x00;SEG18 = 0x00;

	display1_4(0,0,0,0);
	display5_10(0,0,0,0);
	display_Symbol(0);

    T0CLKEN = 1;
	TMR0    = 0x00;
	PR0     = 249;
	T0CON0  = 0x26;
	T0CON1  = 0x00;

	while(1)
	{
	    //显示数据
	    if(TMR0IF == 1)
		{
		    TMR0IF = 0;
			display1_4(Temp,Temp,Temp,Temp);
			display5_10(Temp,Temp,Temp,Temp);
			display_Symbol(Temp);
			Temp ++;
			if(Temp>9)Temp = 0;
		}

	}
}

void interrupt ISR_h (void)
{

}

void interrupt low_priority ISR_l (void)
{

}
