下列是LCD显示屏驱动程序及字符代码,希望大家指导!
//下列代码是字符代码,由于LA8的空间太小,将字符代码放入到FLASH中,FLASH空间太小。剩余的
//放入程序中。
unsigned short ascchr1[] @0x80={
/*0*/ 0x4c95,
/*1*/ 0x0c00,
/*2*/ 0x4419,
/*3*/ 0x4c09,
/*4*/ 0x0c0c,
/*5*/ 0x480d,
/*6*/ 0x481d,
/*7*/ 0x0c01,
/*8*/ 0x4c1d,
/*9*/ 0x4c0d,
/*A*/ 0x0C1D,
/*B*/ 0x481C,
/*C*/ 0x4015,
/*D*/ 0x4C18,
/*E*/ 0x401D,
/*F*/ 0x001D,
/*G*/ 0x4C29,
/*H*/ 0x0C1C,
/*I*/ 0x6101,
/*J*/ 0x4C00,
/*K*/ 0x3300,
/*L*/ 0x4014,
/*M*/ 0x0E16,
/*N*/ 0x1C16,
/*O*/ 0x4C95,
/*P*/ 0x041D,
/*Q*/ 0x0C0D,
/*R*/ 0x141D,
/*S*/ 0x482D,
/*T*/ 0x2101,
/*U*/ 0x4C14,
/*V*/ 0x2404
};
unsigned short ascchr2[]={
/*W*/ 0x1C34,
/*X*/ 0x1222,
/*Y*/ 0x2202,
/*Z*/ 0x4221
};
/**********LCD显示屏清除或全部显示***********
ON_OFF:1清除LCD显示,1:全部显示LCD
*********************************************/
void LCDclr(int ON_OFF){
int i;
unsigned char *p;
p = (char *)0x20;
if(ON_OFF==1){
for(i = 0; i < 29; i++) {
*p++ = 0x00;
}
}
if(ON_OFF==0)
{
for (i = 0; i < 29; i++){
*p++ = 0x00;
}
}
}
/********初始化LCD********/
void LCDINI(void){
unsigned int i;
unsigned char *p;
LCDC0_LCDEN = 0;
LCDC0 = LCDC0_SOURCE_MASK | LCDC0_LCLK0_MASK | LCDC0_DUTY_MASK;
LCDC1 = LCDC1_FCDEN_MASK;
LCDSUPPLY = LCDSUPPLY_VSUPPLY0_MASK;
LCDBCTL = 0;
LCDPEN0 = 0xFF;
LCDPEN1 = 0xFF;
LCDPEN2 = 0xFF;
LCDPEN3 = 0x1F;
LCDBPEN0 = 0x80;
LCDBPEN1 = 0x7F;
LCDBPEN2 = 0x00;
LCDBPEN3 = 0x00;
p = (char *)0x20;
for (i = 0; i < 29; i++) {
*p++ = 0x00;
}
LCDWF7 = 0x80;
LCDWF8 = 0x40;
LCDWF9 = 0x20;
LCDWF10 = 0x10;
LCDWF11 = 0x08;
LCDWF12 = 0x04;
LCDWF13 = 0x02;
LCDWF14 = 0x01;
LCDC0_LCDEN = 1;
}
/*********************************************************
num:从左往右数第num段显示;
data:显示代码
**********************************************************/
void LCD_Num(int num,unsigned short data){
switch(num){
case 1:
LCDWF6 = data >> 8;
LCDWF16 = (data & 0xFF)|0x80;
break;
case 2:
LCDWF5 = data >> 8;
LCDWF17 = data & 0xFF;
break;
case 3:
LCDWF4 = data >> 8;
LCDWF18 = data & 0xFF;
break;
case 4:
LCDWF3 = data >> 8;
LCDWF19 = data & 0xFF;
break;
case 5:
LCDWF2 = data >> 8;
LCDWF20 = data & 0xFF;
break;
case 6:
LCDWF1 = data >> 8;
LCDWF21 = data & 0xFF;
break;
case 7:
LCDWF0 = data >> 8;
LCDWF22 = data & 0xFF;
break;
case 8:
LCDWF28 = data >> 8;
LCDWF23 = data & 0xFF;
break;
case 9:
LCDWF27 = data >> 8;
LCDWF24 = data & 0xFF;
break;
default:break;
}
}
/*********************************************************
LCD从高到低依次显示LCD字符
**********************************************************/
void dpchr(void){
int i=0,j;
while(i<36){
for(j=1;j<10;j++){
if(i<32) LCD_Num(j,ascchr1);
else{
LCD_Num(j,ascchr2[i-32]);
if (i>36) j=10;
}
if(i<10) putch( i+0x30);
else putch(i+0x37);
i++;
}
putch(10);
delay(500);
}
}