#include "include.h"
void System_Int(void)
{
	Ram_Int();   ///RAM清零  
	
	Gpio_Int();		//IO初始化
}

void LCD_Int(void)
{
	TRISB = 0x0F;		//0 = 输入		1 = 输出
	ANSELB = 0x00;		//0 = 模拟模式	1 = 数字模式	
			
	TRISC = 0x0F;		//0 = 输入		1 = 输出	
	ANSELB = 0x00;		//0 = 模拟模式	1 = 数字模式	
				
	RLCD1 = 0;			//00 = 偏置电阻总和 600K	01 = 偏置电阻总和 300K
	RLCD0 = 0;			//10 = 偏置电阻总和 100K	11 = 偏置电阻总和 50K	
		
	FRAME = 0;			//0 = Frame0	1 = Frame1	
	BIAS = 0;			//0 = 1/2BIAS	1 = 1/3BIAS
	
	COMPCEN = 0x0F;     //  COM  PC0  PC1  PC2  PC3
	SEGPBEN = 0x0F;		//  SEG  PB0  PB1  PB2  PB3	
	
	PORTA = 0x00;
	PORTB = 0x00;
	PORTC = 0x00;
	
	LCDEN =	1;			//使能LCD模块
}

void Gpio_Int(void)
{
	////数字模拟模式：   1：数字    0：模拟
	ANSELA = 0x00;
	ANSELB = 0x00;
	ANSELC = 0x00;
	
	////输入输出模式：   1：输出    0：输入
	TRISA = 0x00;
	TRISB = 0x00;
	TRISC = 0x00;
	
	////IO数据寄存器：   1：高电平    0：低电平
	PORTA = 0x00;
	PORTB = 0x00;
	PORTC = 0x00;
	
	////输入上拉控制：   1：使能上拉   0：关闭上拉
	WPUA = 0x00;
	WPUB = 0x00;
	WPUC = 0x00;
	
	////输入下拉控制：   1：使能下拉   0：关闭下拉
	WPDA = 0x00;
	WPDB = 0x00;
	WPDC = 0x00;
	
	////GPIO唤醒控制：   1：使能唤醒   0：关闭唤醒
	IOCA = 0x00;
	IOCB = 0x00;
	IOCC = 0x00;	
}

void Delay_ms(unsigned int fui_i)
{
	unsigned int fui_j;
	for(;fui_i > 0;fui_i --)
	for(fui_j = 205;fui_j > 0;fui_j --);
}

void Ram_Int(void)
{
	IRP = 0;
	FSR = 0x60;
	do{
		INDF = 0;
		FSR++;
	}while(FSR != 0x80);//BANK0 60H~7FH 地址清0
      
	FSR = 0xD0;
	do{
		INDF = 0;
		FSR++;
	}while(FSR != 0xF0);//BANK1 D0H~EFH 地址清0
	
	IRP = 1;
	FSR = 0x10;
	do{
		INDF = 0;
		FSR++;
	}while(FSR != 0x70);//BANK2 110H~16FH 地址清0
      
	FSR = 0x90;
	do{
		INDF = 0;
		FSR++;
	}while(FSR != 0xF0);//BANK3 190H~1EFH 地址清0

	IRP = 0;
}