#include "bsp_lcd.h"
unsigned char shuzi[]={
0x00,0xFC,0x02,0x02,0x02,0xFC,0x00,0x00,0x01,0x01,0x01,0x00, // -0-
0x00,0x00,0x02,0xFE,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01, // -1-
0x00,0x84,0x42,0x22,0x12,0x8C,0x00,0x01,0x01,0x01,0x01,0x01, // -2-
0x00,0x84,0x02,0x12,0x12,0xEC,0x00,0x00,0x01,0x01,0x01,0x00, // -3-
0x00,0x60,0x50,0x4C,0x42,0xFE,0x00,0x00,0x00,0x00,0x01,0x01, // -4-
0x00,0x80,0x1E,0x12,0x12,0xE2,0x00,0x00,0x01,0x01,0x01,0x00, // -5-
0x00,0xF8,0x14,0x12,0x12,0xE2,0x00,0x00,0x01,0x01,0x01,0x00, // -6-
0x00,0x06,0x02,0x82,0x72,0x0E,0x00,0x00,0x00,0x01,0x00,0x00, // -7-
0x00,0xEC,0x12,0x12,0x12,0xEC,0x00,0x00,0x01,0x01,0x01,0x00, // -8-
0x00,0x1C,0x22,0x22,0xA2,0x7C,0x00,0x01,0x01,0x01,0x00,0x00, // -9-
};
unsigned char hanzi[]={
0x90,0x8C,0x84,0xAC,0xD4,0x85,0xF6,0x84,0x84,0x84,0xD4,0x8C,
0x00,0x08,0x08,0x08,0x04,0x02,0x01,0x02,0x02,0x04,0x08,0x00,
0xFC,0x24,0x24,0x24,0xFC,0x08,0x28,0xC8,0x08,0xFF,0x08,0x08,
0x03,0x01,0x01,0x01,0x03,0x00,0x00,0x04,0x08,0x0F,0x00,0x00,
0x08,0x08,0x88,0x68,0x18,0x00,0xFF,0x20,0xD0,0x08,0x04,0x00,
0x04,0x02,0x01,0x00,0x04,0x08,0x07,0x00,0x00,0x01,0x06,0x02,
0x20,0x10,0xFC,0x03,0x04,0x34,0xC5,0x06,0x04,0xF6,0x04,0x04,
0x00,0x00,0x0F,0x00,0x08,0x08,0x0B,0x08,0x0F,0x08,0x08,0x08
};
void LCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;//定义GPIO口的输出结构体
RCC_APB2PeriphClockCmd(GPIO_RCC,ENABLE);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_All;//设置要控制的GPIO口
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_2MHz; //设置输出速度
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;//设置成推挽输出
GPIO_Init(LCD_GPIO_PORT,&GPIO_InitStruct); //初始化GPIO口
LCD_init();
}
void delay_1ms(void)
{
unsigned int i;
for(i=0;i<12000;i++)
{
}
}
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
LCD_CE_L;
if (command == 0)
{
LCD_DC_L;
}
else
{
LCD_DC_H;
}
for(i=0;i<8;i++)
{
if(dat&0x80)
{
LCD_Din_H;
}
else
LCD_Din_L;
dat = dat << 1;
LCD_CLK_L;
LCD_CLK_H;
}
LCD_DC_H;
LCD_CE_H;
LCD_Din_H;
}
void LCD_init(void)
{
LCD_RST_L;
delay_1ms();
LCD_RST_H;
LCD_CE_H;
delay_1ms();
LCD_CE_L;
LCD_write_byte(0x21, 0);
LCD_write_byte(0xc6, 0);
LCD_write_byte(0x06, 0);
LCD_write_byte(0x13, 0);
LCD_write_byte(0x20, 0);
LCD_write_byte(0x0c, 0);
LCD5110_SetContrast(68);
}
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);
LCD_write_byte(0x80 | X, 0);
}
void LCD_clear(void)
{
unsigned char t,k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
void LCD_write_char(unsigned char row,unsigned char page,unsigned char c)
{
unsigned char i;
LCD_set_XY(row*6,page);
for(i=0;i<6;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
LCD_set_XY(row*6,page+1);
for(i=6;i<12;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
}
void LCD_write_chinese_string(unsigned char row,unsigned char page,unsigned char c)
{
unsigned char i;
LCD_set_XY(row*12,page);
for(i=0;i<12;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
LCD_set_XY(row*12,page+1);
for(i=12;i<24;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
}
void LCD5110_SetContrast(uint8_t contrast)
{
LCD_write_byte(0x21,0);
LCD_write_byte(0x80|contrast,0);
LCD_write_byte(0x20,0);
}
void display11(void)
{
LCD_write_chinese_string(0,2,0);
LCD_write_chinese_string(1,2,1);
LCD_write_chinese_string(2,2,2);
LCD_write_chinese_string(3,2,3);
} |