www.pudn.com > mcudesign.rar > LCD.c, change:2005-06-24,size:16249b


#include <iom16v.h> 
#include <macros.h> 
 
#define EN  3 
#define RW  4 
#define DI  5 
#define CSA 6 
#define CSB 7 
 
unsigned char blank[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
unsigned char hzzhi[32]={0x10,0x14,0x13,0x92,0x7E,0x32,0x52,0x92,0x00,0x7C,0x44,0x44,0x44,0x7C,0x00,0x00, 
0x00,0x01,0x01,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00};//智 
unsigned char hznen[32]={0x10,0xB8,0x97,0x92,0x90,0x94,0xB8,0x10,0x00,0x7F,0x48,0x48,0x44,0x74,0x20,0x00, 
0x00,0xFF,0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x3F,0x44,0x44,0x42,0x72,0x20,0x00};//能 
unsigned char hzxin[32]={0x10,0x12,0x92,0x7E,0x12,0x12,0xFE,0x12,0x12,0x10,0xFC,0x00,0x00,0xFF,0x00,0x00, 
0x40,0x42,0x49,0x48,0x48,0x48,0x49,0x7E,0x48,0x48,0x48,0x4A,0x4C,0x4B,0x40,0x00};//型 
unsigned char hzchong[32]={0x00,0x04,0x84,0xC4,0xA4,0xB4,0x9D,0x96,0x84,0x94,0xA4,0xC4,0x84,0x04,0x00,0x00, 
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x3F,0x40,0x40,0x41,0x40,0x70,0x00,0x00};//充 
unsigned char hzdian[32]={0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, 
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00};//电 
unsigned char hzqi[32]={0x40,0x40,0x4F,0x49,0x49,0xC9,0xCF,0x70,0xC0,0xCF,0x49,0x59,0x69,0x4F,0x00,0x00, 
0x02,0x02,0x7E,0x45,0x45,0x44,0x7C,0x00,0x7C,0x44,0x45,0x45,0x7E,0x06,0x02,0x00};//器 
unsigned char hzchi[32]={0x10,0x60,0x02,0x8C,0x60,0x80,0xF8,0x40,0x40,0xFE,0x20,0x20,0x10,0xF0,0x00,0x00, 
0x08,0x08,0x7C,0x03,0x00,0x00,0x3F,0x40,0x40,0x5F,0x40,0x42,0x44,0x43,0x70,0x00};//池 
unsigned char hzzhuang[32]={0x08,0x30,0x00,0xFF,0x20,0x20,0x20,0x20,0xFF,0x20,0xE1,0x26,0x2C,0x20,0x20,0x00, 
0x04,0x02,0x01,0xFF,0x40,0x20,0x18,0x07,0x00,0x00,0x03,0x0C,0x30,0x60,0x20,0x00};//状 
unsigned char hztai[32]={0x00,0x04,0x04,0x04,0x84,0x44,0x34,0x4F,0x94,0x24,0x44,0x84,0x84,0x04,0x00,0x00, 
0x00,0x60,0x39,0x01,0x00,0x3C,0x40,0x42,0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00};//态 
unsigned char hzya[32]={0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00, 
0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00};//压 
unsigned char hzliu[32]={0x10,0x60,0x01,0x86,0x60,0x04,0x44,0x64,0x55,0x4E,0x44,0x64,0xC4,0x04,0x04,0x00, 
0x04,0x04,0xFC,0x03,0x40,0x30,0x0F,0x00,0x00,0x7F,0x00,0x3F,0x40,0x40,0x70,0x00};//流 
unsigned char hzwen[32]={0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, 
0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00};//温 
unsigned char hzdu[32]={0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, 
0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00};//度 
unsigned char hzman[32]={0x10,0x61,0x06,0xE0,0x04,0xA4,0xA4,0xEF,0xA4,0xA4,0xE4,0xAF,0xA4,0xA4,0x24,0x00, 
0x08,0xF8,0x07,0x00,0x00,0xFF,0x08,0x07,0x14,0x08,0x07,0x44,0x88,0x7F,0x00,0x00};//满 
unsigned char hzjuan[32]={0x08,0x30,0x01,0xC6,0x30,0xC0,0x5E,0x52,0x52,0x52,0x52,0x52,0x5E,0xC0,0x00,0x00, 
0x04,0x04,0xFF,0x00,0x00,0xFF,0x05,0x05,0x05,0x05,0x05,0x45,0x85,0x7F,0x00,0x00};//涓 
unsigned char hzkuai[32]={0x70,0x00,0xFF,0x08,0xB0,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0xF8,0x80,0x80,0x00, 
0x00,0x00,0xFF,0x00,0x80,0x40,0x30,0x0E,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00};//快 
unsigned char hzfang[32]={0x08,0x08,0xF8,0x49,0x4E,0xC8,0x88,0x40,0x38,0xCF,0x0A,0x08,0x88,0x78,0x08,0x00, 
0x40,0x30,0x0F,0x40,0x80,0x7F,0x00,0x40,0x20,0x10,0x0B,0x0E,0x31,0x60,0x20,0x00};//放 
unsigned char hznie[32]={0x40,0x30,0x2F,0xE4,0x24,0x24,0x00,0xFE,0xAA,0xAA,0xAB,0xAA,0xAA,0xFE,0x00,0x00, 
0x01,0x01,0x01,0x7F,0x21,0x11,0x42,0x22,0x1A,0x06,0xFF,0x0A,0x12,0x22,0x22,0x00};//镍 
unsigned char hzge[32]={0x40,0x30,0xEF,0x24,0x24,0x04,0x82,0xBA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBA,0x82,0x00, 
0x01,0x01,0xFF,0x41,0x21,0x00,0xFF,0x00,0x05,0x06,0x7C,0x06,0x45,0x80,0x7F,0x00};//镉 
//unsigned char hzqing[32]={0x00,0x10,0xA8,0xA6,0xAB,0xAA,0xAA,0xAA,0xAA,0xAA,0x2A,0xEA,0x0A,0x0A,0x00,0x00, 
//0x00,0x88,0x88,0x98,0x94,0x94,0xF2,0x92,0x95,0x94,0x88,0x9F,0x60,0x80,0xE0,0x00};//氢 
//unsigned char hzli[32]={0x40,0x30,0x2C,0xE7,0x24,0x24,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0xFE,0x00,0x00, 
//0x02,0x02,0x02,0xFF,0x42,0x22,0x92,0x84,0x84,0x84,0xFF,0x84,0x84,0x84,0x80,0x00};//锂 
unsigned char hzmh[32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//冒号 
//节 
unsigned char hzjie[32]={0x04,0x04,0x44,0x44,0x44,0x5F,0xC4,0x44,0x44,0x44,0x5F,0x44,0xC4,0x04,0x04,0x00, 
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x08,0x10,0x0F,0x00,0x00,0x00}; 
//数 
unsigned char hzshu[32]={0x10,0x92,0x54,0x38,0xFF,0x38,0x54,0x52,0x80,0xF0,0x1F,0x12,0x10,0xF0,0x10,0x00, 
0x42,0x42,0x2A,0x2E,0x13,0x1A,0x26,0x02,0x40,0x20,0x13,0x0C,0x33,0x60,0x20,0x00}; 
//下划线 
//unsigned char sym_xhx[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80}; 
//摄氏度 
//unsigned char sym_du[32]={0x00,0x02,0x05,0xE2,0x18,0x04,0x02,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00, 
//0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x40,0x40,0x40,0x40,0x40,0x20,0x18,0x00,0x00}; 
/*--  文字:  V  --*/ 
unsigned char chr_v[16]={0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00}; 
/*--  文字:  A  --*/ 
unsigned char chr_a[16]={0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20}; 
/*--  文字:  0  --*/ 
unsigned char num_0[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00}; 
/*--  文字:  1  --*/ 
unsigned char num_1[16]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00}; 
/*--  文字:  2  --*/ 
unsigned char num_2[16]={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00}; 
/*--  文字:  3  --*/ 
unsigned char num_3[16]={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00}; 
/*--  文字:  4  --*/ 
unsigned char num_4[16]={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00}; 
/*--  文字:  5  --*/ 
unsigned char num_5[16]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00}; 
/*--  文字:  6  --*/ 
unsigned char num_6[16]={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00}; 
/*--  文字:  7  --*/ 
unsigned char num_7[16]={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00}; 
/*--  文字:  8  --*/ 
unsigned char num_8[16]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00}; 
/*--  文字:  9  --*/ 
unsigned char num_9[16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00}; 
/*--  文字:  .  --*/ 
unsigned char num_p[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00}; 
 
 
//#define EN245 7 
/*(PORTC7)en245 : 0 enable245;1 disable245*/ 
//#define DIR245 6 
/*(PORTC6)dir245: 0 read; 1 write*/ 
 
unsigned char DATA; 
unsigned char tims1; 
unsigned char tims2; 
unsigned int  b_v; 
unsigned int  b_a; 
unsigned char b_t; 
unsigned char b_n; 
unsigned char b_s; 
//ICC-AVR application builder : 2005-6-21 23:10:06 
// Target : M16 
// Crystal: 7.3728Mhz 
 
 
void port_init(void) 
{ 
 PORTA = 0xF8; 
 DDRA  = 0xF8; 
 PORTB = 0xFF; 
 DDRB  = 0xFF;//output 
 PORTC = 0xFF; //m103 output only 
 DDRC  = 0xFF; 
 PORTD = 0xFF; 
 DDRD  = 0x37; 
} 
 
//Watchdog initialisation 
// prescale: 2048K cycles 
void watchdog_init(void) 
{ 
 WDR(); //this prevents a timout on enabling 
 WDTCR = 0x02; //WATCHDOG ENABLED - dont forget to issue WDRs 
} 
 
//TIMER0 initialisation - prescale:64 
// WGM: Normal 
// desired value: 1mSec 
// actual value:  0.998mSec (0.2%) 
void timer0_init(void) 
{ 
 TCCR0 = 0x00; //stop 
 TCNT0 = 0x8D; //set count 
 OCR0  = 0x73;  //set compare 
 TCCR0 = 0x03; //start timer 
} 
 
//TIMER1 initialisation - prescale:1 
// WGM: 11) PWM phz correct, TOP=OCRnA 
// desired value: 1KHz 
// actual value:  1.000KHz (0.0%) 
void timer1_init(void) 
{ 
 TCCR1B = 0x00; //stop 
 TCNT1H = 0x00; //setup 
 TCNT1L = 0x00; 
 OCR1AH = 0x0E; 
 OCR1AL = 0x66; 
 OCR1BH = 0x0E; 
 OCR1BL = 0x66; 
 ICR1H  = 0x0E; 
 ICR1L  = 0x66; 
 TCCR1A = 0xF3; 
 TCCR1B = 0x00; //start Timer 
} 
 
//TIMER2 initialisation - prescale:1024 
// WGM: Normal 
// desired value: 10mSec 
// actual value:  9.861mSec (1.4%) 
void timer2_init(void) 
{ 
 TCCR2 = 0x00; //stop 
 ASSR  = 0x00; //set async mode 
 TCNT2 = 0x04; //setup 
 OCR2  = 0xFC; 
 TCCR2 = 0x06; //start 
} 
 
 
//call this routine to initialise all peripherals 
void init_devices(void) 
{ 
 //stop errant interrupts until set up 
 CLI(); //disable all interrupts 
 port_init(); 
 watchdog_init(); 
 timer0_init(); 
 timer1_init(); 
 timer2_init(); 
 MCUCR = 0x00; 
 GICR  = 0x00; 
 //TIMSK = 0x41; //timer interrupt sources 
 TIMSK = 0x41; //timer interrupt sources 
 SEI(); //re-enable interrupts 
} 
 
/////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////// 
//PORTB-->data 
//PA3->EN;PA4->DI;PA5->CSA;PA6->CSB;PA7->RW; 
void WriteCom(unsigned char area,unsigned char com) 
{ 
  //area=0-->left;1-->mid;2-->right 
	//area=[csa,csb]00:L 01:M 10:R 
  unsigned char lcd_busy; 
	switch(area) 
	{ 
	  case 0: 
		  PORTA &=~ (1<<CSA); 
			PORTA &=~ (1<<CSB); 
		  break; 
		case 2: 
		  PORTA &=~ (1<<CSA); 
			PORTA |=  (1<<CSB); 
			break; 
		case 1: 
		  PORTA |=  (1<<CSA); 
			PORTA &=~ (1<<CSB); 
			break; 
	} 
	PORTA &=~ (1<<DI); 
	PORTA |=  (1<<RW); 
 
	do{ 
	  DDRB   =  0xFF; 
		PORTB  =  0xFF; 
	  PORTA |=  (1<<EN); 
		DDRB   =  0; 
		lcd_busy=PINB; 
	  PORTA &=~ (1<<EN); 
		lcd_busy=lcd_busy>>7; 
	}while(lcd_busy); 
	PORTA &=~ (1<<RW); 
  DDRB   =  0xFF; 
	PORTB  =  com; 
	PORTA |=  (1<<EN); 
	PORTA &=~ (1<<EN); 
} 
 
void WriteDat(unsigned char area,unsigned char dat) 
{ 
  //area=0-->left;1-->mid;2-->right 
	//area=[csa,csb]00:L 01:M 10:R 
//  unsigned char lcd_busy; 
	switch(area) 
	{ 
	  case 0: 
		  PORTA &=~ (1<<CSA); 
			PORTA &=~ (1<<CSB); 
		  break; 
		case 2: 
		  PORTA &=~ (1<<CSA); 
			PORTA |=  (1<<CSB); 
			break; 
		case 1: 
		  PORTA |=  (1<<CSA); 
			PORTA &=~ (1<<CSB); 
			break; 
	} 
	PORTA &=~ (1<<DI);//DI=0 
	PORTA |=  (1<<RW);//RW=1 
/*	do{ 
		DDRB   =  0xFF;    //PORT B AS OUTPUT 
	  PORTB  =  0xFF; 
	  PORTA |=  (1<<EN);//EN=1 
		DDRB   =  0;       //PORT B AS INPUT 
	  lcd_busy=PINB>>7; 
	  PORTA &=~ (1<<EN); 
		//PORTD &=~ (1<<0); 
	}while(lcd_busy);*/ 
  //PORTD |=  (1<<0); 
	PORTA |=  (1<<DI); 
	PORTA &=~ (1<<RW); 
	DDRB   =  0xFF;    //PORT B AS OUTPUT 
	PORTB  =  dat; 
	PORTA |=  (1<<EN); 
	PORTA &=~ (1<<EN); 
} 
 
void ini_lcd(void) 
{ 
  unsigned char i; 
	for(i=0;i<3;i++) 
	  WriteCom(i,0xC0); 
	for(i=0;i<3;i++) 
	  WriteCom(i,0x3F); 
} 
 
void delay_ms(unsigned int time) 
{ 
 unsigned int i; 
 unsigned int j; 
 for(i=0;i<=time;i++) 
 { 
   for(j=0;j<=1052;j++) 
	 { 
	 WDR(); 
	 } 
 } 
} 
 
void cls_lcd(void) 
{ 
 unsigned char R4; 
 unsigned char R3; 
 unsigned char A; 
 unsigned char i; 
 R4=0; 
 A=R4; 
 for(R4=0;R4<8;R4++) 
 { 
   A=0xB8+R4; 
   for(i=0;i<3;i++) 
     WriteCom(i,A); 
   for(i=0;i<3;i++) 
     WriteCom(i,0x40); 
   R3=0x40; 
   for(R3=0;R3<64;R3++) 
	 { 
	   for(i=0;i<3;i++) 
	     WriteDat(i,0x00); 
	 } 
 } 
} 
void w_hz(unsigned char lr,unsigned char x,unsigned char y,unsigned char s[32]) 
{ 
  //column-->y,code 
	//page-->x 
	unsigned char column; 
	unsigned char page; 
	unsigned char i; 
	 
	x=x+0xb8; 
	y=y+0x40; 
 
	page=x; 
	column=y; 
	WriteCom(lr,column); 
	for(i=0;i<16;i++) 
	{ 
	  WriteCom(lr,page); 
	  WriteDat(lr,s[i]); 
	}  
	page++; 
	column=y; 
		WriteCom(lr,column); 
	for(i=16;i<32;i++) 
	{ 
	  WriteCom(lr,page); 
		WriteDat(lr,s[i]); 
	} 
} 
void nw_hz(unsigned char lr,unsigned char x,unsigned char y,unsigned char s[32]) 
{ 
  //column-->y,code 
	//page-->x 
	unsigned char column; 
	unsigned char page; 
	unsigned char i; 
	//unsigned char t[32]; 
	x=x+0xb8; 
	y=y+0x40; 
 
	page=x; 
	column=y; 
	WriteCom(lr,column); 
	for(i=0;i<16;i++) 
	{ 
	  WriteCom(lr,page); 
	  WriteDat(lr,~s[i]); 
	}  
	page++; 
	column=y; 
		WriteCom(lr,column); 
	for(i=16;i<32;i++) 
	{ 
	  WriteCom(lr,page); 
		WriteDat(lr,~s[i]); 
	} 
} 
 
void w_fh(unsigned char lr,unsigned char x,unsigned char y,unsigned char s[16]) 
{ 
  //column-->y,code 
	//page-->x 
	unsigned char column; 
	unsigned char page; 
	unsigned char i; 
	 
	x=x+0xb8; 
	y=y+0x40; 
 
	page=x; 
	column=y; 
	WriteCom(lr,page); 
	WriteCom(lr,column); 
	 
	for(i=0;i<8;i++) 
	{ 
	  WriteDat(lr,s[i]); 
	}  
	page++; 
	column=y; 
	  WriteCom(lr,page); 
		WriteCom(lr,column); 
	for(i=8;i<16;i++) 
	{ 
		WriteDat(lr,s[i]); 
	} 
} 
void disp_fh(unsigned char a,unsigned char b,unsigned char c,unsigned char dat) 
{ 
  switch(dat) 
	{ 
	  case 0:w_fh(a,b,c,num_0);break; 
	  case 1:w_fh(a,b,c,num_1);break; 
	  case 2:w_fh(a,b,c,num_2);break; 
	  case 3:w_fh(a,b,c,num_3);break; 
	  case 4:w_fh(a,b,c,num_4);break; 
	  case 5:w_fh(a,b,c,num_5);break; 
	  case 6:w_fh(a,b,c,num_6);break; 
	  case 7:w_fh(a,b,c,num_7);break; 
	  case 8:w_fh(a,b,c,num_8);break; 
	  case 9:w_fh(a,b,c,num_9);break; 
	} 
} 
void disp_dy(unsigned int dy) 
{ 
  unsigned char y1,y2,y3,y4; 
	y1=dy/1000; 
	y2=(dy-y1*1000)/100; 
	y3=(dy-y1*1000-y2*100)/10; 
	y4= dy-y1*1000-y2*100-y3*10; 
	disp_fh(2,2,16,y1); 
	//   w_fh(2,2,24,num_p); 
	disp_fh(2,2,32,y2); 
	disp_fh(2,2,40,y3); 
	disp_fh(2,2,48,y4); 
		  
} 
void disp_dl(unsigned int dy) 
{ 
  unsigned char y1,y2,y3,y4; 
	y1=dy/1000; 
	y2=(dy-y1*1000)/100; 
	y3=(dy-y1*1000-y2*100)/10; 
	y4= dy-y1*1000-y2*100-y3*10; 
	disp_fh(2,4,16,y1); 
	//   w_fh(2,4,24,num_p); 
	disp_fh(2,4,32,y2); 
	disp_fh(2,4,40,y3); 
	disp_fh(2,4,48,y4); 
} 
 
void disp_wd(unsigned char wd) 
{ 
  unsigned char y1,y2; 
	y1=wd/10; 
	y2=wd-y1*10; 
	disp_fh(2,6,24,y1); 
	disp_fh(2,6,32,y2); 
 
} 
void disp_zt(unsigned char dat) 
{ 
  switch(dat) 
  { 
	  case 0: w_hz(0,6,48,hzfang);w_hz(1,6,0,hzdian);break; 
		case 1: w_hz(0,6,48,hzkuai);w_hz(1,6,0,hzchong);break; 
		case 2: w_hz(0,6,48,hzjuan);w_hz(1,6,0,hzchong);break; 
		case 3: w_hz(0,6,48,hzchong);w_hz(1,6,0,hzman);break; 
  } 
} 
 
void disp_js(unsigned char dat) 
{ 
if(dat<10) 
 	disp_fh(0,4,52,dat); 
 
} 
void disp_main(void) 
{ 
 /*w_hz(0,0,0,blank); w_hz(0,0,16,blank); w_hz(0,0,32,blank);*/w_hz(0,0,48,hzzhi); 
 w_hz(1,0,0,hznen); w_hz(1,0,16,hzxin); w_hz(1,0,32,hzchong); w_hz(1,0,48,hzdian);  
 w_hz(2,0,0,hzqi);/* w_hz(2,0,16,blank);w_hz(2,0,32,blank);w_hz(2,0,48,blank);*/ 
  
 w_hz(0,2,0,hzdian);w_hz(0,2,16,hzchi);w_hz(0,2,32,hzmh);w_hz(0,2,48,hznie); 
 w_hz(1,2,0,hzge);/* w_hz(1,2,16,blank);*/ w_hz(1,2,32,hzdian); w_hz(1,2,48,hzya);  
 w_hz(2,2,0,hzmh);/* w_hz(2,2,16,blank);w_hz(2,2,32,blank);*/w_fh(2,2,56,chr_v); 
  
 w_hz(0,4,0,hzjie);w_hz(0,4,16,hzshu);w_hz(0,4,32,hzmh);/*w_hz(0,4,48,blank);*/ 
 w_hz(1,4,0,hzjie);/* w_hz(1,4,16,blank);*/ w_hz(1,4,32,hzdian); w_hz(1,4,48,hzliu);  
 w_hz(2,4,0,hzmh);/* w_hz(2,4,16,blank);w_hz(2,4,32,blank);*/w_fh(2,4,56,chr_a); 
  
 w_hz(0,6,0,hzzhuang);w_hz(0,6,16,hztai);w_hz(0,6,32,hzmh);w_hz(0,6,48,hzkuai); 
 w_hz(1,6,0,hzchong); /*w_hz(1,6,16,blank);*/ w_hz(1,6,32,hzwen); w_hz(1,6,48,hzdu);  
 w_hz(2,6,0,hzmh);/* w_hz(2,6,16,blank);w_hz(2,6,32,blank);*/w_hz(2,6,48,hzdu); 
 w_fh(2,4,24,num_p); 
 w_fh(2,2,24,num_p); 
 
} 
void scan_key(void) 
{ 
  unsigned char keycode; 
	unsigned char n_key; 
	keycode=PIND&0xC8; 
	keycode=~keycode; 
	if(keycode!=0) 
	  PORTD &=~(1<<0); 
		//delay_ms(1); 
	n_key=PIND&0xC8; 
	n_key=~n_key; 
	if(keycode==n_key) 
	  disp_fh(2,0,32,keycode); 
} 
void main(void) 
{ 
 init_devices(); 
 WDR(); 
 b_n=1; 
 b_s=2; 
 b_v=1215; 
 b_a=20; 
 b_t=34; 
 tims1=0; 
 tims2=0; 
 PORTA=0x00; 
 ini_lcd(); 
 cls_lcd(); 
 disp_main();  
 disp_js(1); 
 disp_zt(4); 
 disp_dy(0); 
 disp_dl(0); 
 disp_wd(31); 
 do{ 
 WDR(); 
 scan_key(); 
  
 delay_ms(1); 
  }while(1); 
} 
#pragma interrupt_handler timer0_ovf_isr:10 
void timer0_ovf_isr(void) 
{ 
 WDR(); 
  
 TCNT0 = 0x8D;  
} 
#pragma interrupt_handler timer2_ovf_isr:5 
void timer2_ovf_isr(void) 
{ 
 WDR(); 
 TCNT2 = 0x04; /*INVALID SETTING*/; //reload counter value 
}