?? upsd3300_lcd.c
字號:
}
}
else
{
if(i%2==0)
{
dot_buffer[i] = pic[i+1];
}
if(i%2==1)
{
dot_buffer[i] = pic[i-1];
}
}
}
}
void disp_one_asc3(unsigned char width,unsigned char length,unsigned char *pic)
{
unsigned long i;
for (i=0;i<width*length;i++)
{
if(mode)
{
if(i%3==0)
{
dot_buffer[i] = ~pic[i+2];
}
if(i%3==1)
{
dot_buffer[i] = ~pic[i];
}
if(i%3==2)
{
dot_buffer[i] = ~pic[i-2];
}
}
else
{
if(i%3==0)
{
dot_buffer[i] = pic[i+2];
}
if(i%3==1)
{
dot_buffer[i] = pic[i];
}
if(i%3==2)
{
dot_buffer[i] = pic[i-2];
}
}
}
}
void disp_one_asc4(unsigned char width, unsigned char *pic)
{
unsigned long i;
for (i=0;i<width*4;i++)
{
if(mode)
{
if(i%4==0)
{
dot_buffer[i] = ~pic[i+3];
}
if(i%4==1)
{
dot_buffer[i] = ~pic[i+1];
}
if(i%4==2)
{
dot_buffer[i] = ~pic[i-1];
}
if(i%4==3)
{
dot_buffer[i] = ~pic[i-3];
}
}
else
{
if(i%4==0)
{
dot_buffer[i] = *(pic+i+3);
}
if(i%4==1)
{
dot_buffer[i] = *(pic+i+1);
}
if(i%4==2)
{
dot_buffer[i] = *(pic+i-1);
}
if(i%4==3)
{
dot_buffer[i] = *(pic+i-3);
}
}
}
}
void DrawPic ( unsigned char x0,unsigned char y0,unsigned char width,unsigned char length,unsigned char *bmp)
{
unsigned char x, address;
unsigned char * dat;
unsigned char m;
unsigned long i=0;
unsigned char page =0; // if layer = 0;page = 0,so it will disply the first line Chinese word
bit window = 0; //display on master LCD
unsigned char orig_buscon;
orig_buscon = BUSCON; // Save buscon value
BUSCON |= 0x3C; // Set Xdata Read/Write to max wait states
if(length%8==0)
m = length/8;
else
m = length/8 + 1;
if(m==2)
disp_one_asc2(width, length, bmp);
if(m==3)
disp_one_asc3(width, length, bmp);
if(m==4)
disp_one_asc4(width, bmp);
dat = dot_buffer;
OutMasterCom( 0X00 ); //display column address
OutMasterCom ( 0XC0|y0 );//display start line
OutSlaveCom ( 0X00 );
OutSlaveCom ( 0XC0|y0);
for(x=x0;x<x0+width;x++)
{
if(x>121)
return; //the column exceeded 121 will be ignored
if (x>60)
{
window =1; //disply on slave LCD
address = x%61;
}
else
address = x; //display on master LCD
SetPage (page,page); //disply the upper part of a Chinese word
SetAddress(address,address);
if (window)
PutChar0(dat[i]);
else
PutChar1(dat[i]);
i+=1;
if(m>=2)
{
SetPage (page+1,page+1); //disply the lower part of a Chinese word
SetAddress(address,address);
if (window)
PutChar0(dat[i]);
else
PutChar1(dat[i]);
i+=1;
}
if(m>=3)
{
SetPage (page+2,page+2); //disply the lower part of a Chinese word
SetAddress(address,address);
if (window)
PutChar0(dat[i]);
else
PutChar1(dat[i]);
i+=1;
}
if(m>=4)
{
SetPage (page+3,page+3); //disply the lower part of a Chinese word
SetAddress(address,address);
if (window)
PutChar0(dat[i]);
else
PutChar1(dat[i]);
i+=1;
}
}
BUSCON = orig_buscon; // Restore buscon value
}
/*---------------------------------------------------------------------------------------
Function:
this function is used to display a Chinese word.
Parameters:
x0: start column address.
layer: if layer = 0,display the first line Chinese word,otherwise display the second line.
width: the number of column of a Chinese word dot matrix.
bmp: the pointer of the dot matrix data.
Note:
the LCD can only display two line Chinese word,so page 0 and 1 is to display the first line,page2
and page 3 is to display the second line.
----------------------------------------------------------------------------------------*/
void disp_one_ch(unsigned char col,unsigned char layer,unsigned int ch_code,unsigned char mode)
{
unsigned char i,j,c2,c1;
extern PSD_REGS PSD_reg;
unsigned char xdata *ptr;
j = PSD_reg.PAGE ; //reserve page number first
PSD_reg.PAGE = CHINESE_FONT_PAGE;
c2 = (unsigned char)((ch_code&0xff00)>>8);
c1 = (unsigned char)(ch_code&0x00ff);
for(i=0;i<159;i++) //check index table to get the specific location
{
if ((c2 == index[i])&&(c1 == index[i+1]))
{
ptr = (unsigned char xdata *)((index[i+2])*32);
break;
}
}
for(i=0;i<32;i++)
{
dot_buffer[i] = *(FONT_BASE_ADDRESS+ptr+i); //fetch font data from internal flash directly
}
if (mode)
{
for(i=0;i<32;i++)
{
dot_buffer[i] = ~ dot_buffer[i];
}
}
DrawBmp(col,layer,16,dot_buffer);//display the Chinese word after get the data from flash
PSD_reg.PAGE = j; //restore page number
}
#endif
/*---------------------------------------------------------------------------------------
Function:
this function is used to converts low nibble of unsigned byte.
Parameters:
byte: this unsigned byte is ready to converting.
Note:
none
----------------------------------------------------------------------------------------*/
char htoa_lo(unsigned char byte)
// (0-F hex) to ascii
{
{
byte = byte & 0x0F; // keep lower nibble only
if (byte <= 0x09)
return(byte + 0x30);
else
return (byte + 0x37);
}
}
/*---------------------------------------------------------------------------------------
Function:
this function is used to converts low nibble of unsigned byte.
Parameters:
byte: this unsigned byte is ready to converting.
Note:
none
----------------------------------------------------------------------------------------*/
char htoa_hi(unsigned char byte) // converts hi nibble of unsigned byte
// (0-F hex) to ascii
{
{
byte = byte & 0xF0; // keep upper nibble only
byte = byte >> 4;
if (byte <= 0x09)
return(byte + 0x30);
else
return (byte + 0x37);
}
}
/*---------------------------------------------------------------------------------------
printfLCD(chr_ptr)
This function is used to display a string of Chinese words and standard ASCII codes on
the LCD display.
chr_ptr - unsigned char*
- pointer to string to display on LCD.
----------------------------------------------------------------------------------------*/
void printfLCD(unsigned char *ptr, ...)
{
unsigned char c1,c2;
unsigned int c3;
//unsigned char *var_ptr=&ptr+1;
unsigned char var;
unsigned char orig_buscon;
#ifdef __RC51__ //use ANSI stdarg
va_list var_ptr;
va_start(var_ptr,0);
#else
unsigned char *var_ptr=&ptr+1;
#endif
orig_buscon = BUSCON; // Save buscon value
BUSCON |= 0x3C; // Set Xdata Read/Write to max wait states
if(ulayer >3) //if page exceed the range 0 to 3,force it to 0.
ulayer = 0;
while (*ptr != NULL)
{
c1 = *ptr;
c2 = *(ptr+1);
c3 = c1;
c3 = (c3<<8)|c2;
if(c1 <= 128) // deal with asc code , if c1<=128 ,it will deal with asc code,otherwise Chinese word.
{
if ( *ptr == '\r')
{
ptr++;
ucol = 0;
}
else if( *ptr == '\n')
{
ptr++;
ucol = 0;
ulayer++;
}
else if( *ptr == '%')
{
ptr++;
if (*ptr == 'd')
{
ptr++;
#ifdef __RC51__ //use ANSI stdarg
var = *var_ptr--;
var_ptr--;
#else
var = *var_ptr++;
#endif
c1 = (var & 0x0F)+'0';
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
}
else if (*ptr == 'x')
{
#ifdef __RC51__ //use ANSI stdarg
var = *var_ptr--;
var_ptr--;
#else
var = *var_ptr++;
#endif
c1 = htoa_hi(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
c1 = htoa_lo(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
ptr++;
}
else if (*ptr == 'w')
{
ptr++;
#ifdef __RC51__ //use ANSI stdarg
var_ptr--;
var = *var_ptr;
#else
var = *var_ptr++;
#endif
c1 = htoa_hi(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
c1 = htoa_lo(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
#ifdef __RC51__ //use ANSI stdarg
var_ptr++;
var = *var_ptr;
var_ptr-=2;
#else
var = *var_ptr++;
#endif
c1 = htoa_hi(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
c1 = htoa_lo(var);
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
}
else
{
c1 = *ptr;
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
ptr++;
}
}
else
{
disp_one_asc(ucol,ulayer,c1,mode);
ucol+=7;
ptr++; // one asc need one byte in computer system
}
}
#ifdef ENGLISH_CHINESE_FONT
else //deal with Chinese, if c1<=128 ,it will deal with asc code, otherwise Chinese word.
{
if(mode)
disp_one_ch(ucol,ulayer,c3,1);
else
disp_one_ch(ucol,ulayer,c3,0);
ucol+=16; //16*16 Chinese dot matrix
ptr += 2; //one Chinese word need two byte in computer system
}
#endif
}
BUSCON = orig_buscon; // Restore buscon value
}
unsigned char font_detection(void)
{
unsigned char xdata j,a,b;
unsigned char xdata *ascii;
#ifdef ENGLISH_CHINESE_FONT
unsigned char xdata c,d;
unsigned char xdata *chchar;
#endif
extern xdata PSD_REGS PSD_reg;
j = PSD_reg.PAGE; // page number will be changed in fetching ASC font data,so reserve page number first
#ifndef ENGLISH_CHINESE_FONT
ascii = (unsigned char xdata *)(FONT_BASE_ADDRESS);
PSD_reg.PAGE =ENGLISH_FONT_PAGE;
a = ascii[0];
b = ascii[1];
#else
ascii = (unsigned char xdata *)(FONT_BASE_ADDRESS);
chchar = (unsigned char xdata *)(FONT_BASE_ADDRESS);
PSD_reg.PAGE =ENGLISH_FONT_PAGE;
a = ascii[0];
b = ascii[1];
PSD_reg.PAGE =CHINESE_FONT_PAGE;
c = chchar[0];
d = chchar[1];
#endif
// If the font is not detected in the flash
// then display a bitmapped "no font" message on the LCD
#ifndef ENGLISH_CHINESE_FONT
if ((a == E_FONT_DETECT_BYTE_0) && (b == E_FONT_DETECT_BYTE_1))
#else
if ( (a == E_FONT_DETECT_BYTE_0) && (b == E_FONT_DETECT_BYTE_1) &&
(c == C_FONT_DETECT_BYTE_0) && (d == C_FONT_DETECT_BYTE_1) )
#endif
{
return(0); // Indicate the font was detected.
}
else // Font not detected, so display bitmapped messaged.
{
DrawBmp(0,0,7,nn); // n
DrawBmp(8,0,7,oo); // o
DrawBmp(24,0,7,ff); // f
DrawBmp(32,0,7,oo); // o
DrawBmp(40,0,7,nn); // n
DrawBmp(48,0,7,tt); // t
return(1); // Indicate the font was not detected.
}
}
/*---------------------------------------------------------------------------------------
Function:
this function is used to merge LCD initialization and set display start line and column address.
Parameters:
ptr: none
Note:
this function only used once just before user start using void printfLCD(unsigned char *ptr, ...).
----------------------------------------------------------------------------------------*/
void lcd_init(void)
{
unsigned char orig_buscon;
orig_buscon = BUSCON; // Save buscon value
BUSCON |= 0x3C; // Set Xdata Read/Write to max wait states
///////////////////////LCD initialization/////////
BusyCheck();
LcdConfig ( );
lcd_clear ( );
//////////////////////////set display start line and column address/////////
OutMasterCom ( 0xC0 );
OutSlaveCom ( 0xC0 );
OutMasterCom ( 0x00 );
OutSlaveCom ( 0x00 );
if (font_detection()) // If font not detected,
{
while(1); // wait here forever.
}
BUSCON = orig_buscon; // Restore buscon value
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -