如题:
demo的代码有点问题。。看了手册写了新代码。。终于点亮了。。庆贺一下。。模拟的spi。。
void send_byte (unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
CLR_CLK;
if (temp & 0x80) SET_DATA;
else CLR_DATA;
temp <<= 1;
SET_CLK;
}
}
void lcd_send_command (unsigned char command)
{
CLR_CS;
CLR_RS;
send_byte (command);
SET_CS;
}
void lcd_send_data (unsigned char data)
{
CLR_CS;
SET_RS;
send_byte (data);
SET_CS;
}
void lcd_set_xy (unsigned char page,unsigned char column)
{
CLR_RS;
CLR_CS;
send_byte (0xb0 | page);
send_byte (0x10 | (column>>4));
send_byte (0x0f & column);
SET_RS;
}
void lcd_clr_page(unsigned char page)
{
unsigned char j=0, i = 0;
lcd_set_xy(page,0);
SET_RS;
send_byte (0xe8); //源代码里边你没有这两个。发现是串口的时候才要。
send_byte (0xff); //这是下边要写入的数据长度
for (i= 0;i<129;i++)
{
send_byte (0x00);
send_byte (0x00);
}
SET_CS;
}
void lcd_clr_all(void)
{
unsigned char i,j;
for (i=0;i<16;i++)
{
lcd_clr_page(i);
}
}
void lcd_init (void)
{
LCD_IO_INIT();
CLR_RST;
DelayMs (50);
SET_RST;
lcd_send_command (0xe2);
DelayMs (250);
lcd_send_command (0x48); //set display duty
lcd_send_command (0x00);
lcd_send_command (0xa1); //set ADC
lcd_send_command (0xc0); //set SHL
lcd_send_command (0x44); //set COM0
lcd_send_command (0x00);
lcd_send_command (0x40); //set start line
lcd_send_command (0x00);
lcd_send_command (0xab); //start oscillator
lcd_send_command (0x66); //DC-DC boost 5 times
lcd_send_command (0x27); //set regulator resistor
lcd_send_command (0x81); //set EV
lcd_send_command (0x20);
lcd_send_command (0x54); //set LCD bias resistor
lcd_send_command (0x94); //set FRC PWM
/**********************************************/
lcd_send_command (0x88); //set white gray
lcd_send_command (0x00);
lcd_send_command (0x89);
lcd_send_command (0x00);
lcd_send_command (0x8a); //set light gray
lcd_send_command (0x09);
lcd_send_command (0x8b);
lcd_send_command (0x00);
lcd_send_command (0x8C); //set dark gray
lcd_send_command (0x99);
lcd_send_command (0x8d);
lcd_send_command (0x00);
lcd_send_command (0x8e); //set black gray
lcd_send_command (0x99);
lcd_send_command (0x8f);
lcd_send_command (0x09);
lcd_send_command (0x10);
lcd_send_command (0x01);
lcd_send_command (0xd0);
/**********************************************/
lcd_send_command (0x2c); //power control, open VC
DelayMs (2);
lcd_send_command (0x2e); //open VR
DelayMs (2);
lcd_send_command (0x2f); //open VF
DelayMs (2);
lcd_send_command (0xaf); //display ON
DelayMs (2);
lcd_clr_all();
}
void lcd_put_char (unsigned char y,unsigned char x,unsigned char asc ,unsigned char size)
{
unsigned char i,dat;
lcd_set_xy(y,x);
asc -= 0x20;
SET_RS;
if(size==0)
{
send_byte (0xe8);
send_byte (0x12);
for (i=0;i<6;i++)
{
dat = font6x8[asc];
send_byte (0X00);
send_byte (dat);
}
SET_CS;
}
else
{
send_byte (0xe8);
send_byte (0x16);
for (i=0;i<8;i++)
{
dat = font8x16[asc];
send_byte (dat);
send_byte (0x00);
}
SET_CS;
lcd_set_xy(y+1,x);
send_byte (0xe8);
send_byte (0x16);
for (i=8;i<16;i++)
{
dat = font8x16[asc];
send_byte (dat);
send_byte (0x00);
}
SET_CS;
}
}
void lcd_put_str (unsigned char page,unsigned char column,unsigned char *str,unsigned char size)
{
while ( *str )
{
lcd_put_char (page,column,*str++,size);
if(size==0) column+=7;
else column+=9;
}
}
编辑原因 增加说明。。
说明:屏默认的是并口的。。要割2个线。飞一条线。。才能。。
|