Nokia 5110液晶駆動
6106 ワード
ハードウェアインタフェース:
ドライバ(中国語または画像の元の配列は提供されていません):
sbit LCD_RST=P0^0;
sbit LCD_CE=P0^1;
sbit LCD_DC=P0^2;
sbit LCD_BL=P0^6;
sbit SDIN=P0^3;
sbit SCLK=P0^4;
ドライバ(中国語または画像の元の配列は提供されていません):
void delay_1us(void);
void delay_1ms(void);
void delay_nms(unsigned int n);
void LCD_init(void);
void LCD_clear(void);
void LCD_set_XY(unsigned char X, unsigned char Y);
void LCD_write_char(unsigned char c);
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);
void LCD_write_chinese_string(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row,char (*s)[24]);
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y);
void LCD_write_byte(unsigned char dat, unsigned char command);
idata uchar itoc[50],operate;
void delay_1us(void) //1us
{
unsigned int i;
for(i=0;i<1000;i++);
}
void delay_1ms(void) //1ms
{
unsigned int i;
for (i=0;i<110;i++);
}
void delay_nms(unsigned int n) //N ms
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void LCD_init(void)
{
// LCD
LCD_RST = 0;
delay_1us();
LCD_RST = 1;
// LCD
LCD_CE = 0;
delay_1us();
// LCD
LCD_CE = 1;
delay_1us();
LCD_write_byte(0x21, 0); // LCD
LCD_write_byte(0xc8, 0); //
LCD_write_byte(0x06, 0); //
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); //
LCD_clear(); //
LCD_write_byte(0x0c, 0); // ,
// LCD
LCD_CE = 0;
}
/*-----------------------------------------------------------------------
LCD_clear :
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
/*-----------------------------------------------------------------------
LCD_set_XY : LCD
:X :0-83
Y :0-5
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*-----------------------------------------------------------------------
LCD_write_char :
:c : ;
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
LCD_write_byte(font6x8[c][line], 1);
}
/*-----------------------------------------------------------------------
LCD_write_english_String :
:*s : ;
X、Y : ,x 0-83 ,y 0-5
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/*-----------------------------------------------------------------------
LCD_write_chinese_string: LCD
:X、Y : X、Y ;
ch_with :
num : ;
line :
row :
:
LCD_write_chi(0,0,12,7,0,0);
LCD_write_chi(0,2,12,7,0,0);
LCD_write_chi(0,4,12,7,0,0);
-----------------------------------------------------------------------*/
void LCD_write_chinese_string(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row,char (*chinese)[24])
{
unsigned char i,n;
LCD_set_XY(X,Y); //
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //
{
if (n==ch_with) //
{
if (i==0) LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
LCD_write_byte(chinese[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/*-----------------------------------------------------------------------
LCD_draw_map :
:X、Y : X、Y ;
*map : ;
Pix_x : ( )
Pix_y : ( )
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8; //
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //
}
}
/*-----------------------------------------------------------------------
LCD_write_byte : SPI LCD
:data : ;
command : / ;
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
//PORTB &= ~LCD_CE ; // LCD
LCD_CE = 0;
if (command == 0)
// PORTB &= ~LCD_DC ; //
LCD_DC = 0;
else
// PORTB |= LCD_DC ; //
LCD_DC = 1;
for(i=0;i<8;i++)
{
if(dat&0x80)
SDIN = 1;
else
SDIN = 0;
SCLK = 0;
dat = dat << 1;
SCLK = 1;
}
// SPDR = data; // SPI
//while ((SPSR & 0x80) == 0); //
//PORTB |= LCD_CE ; // LCD
LCD_CE = 1;
}