学习板上带有字符型LCD显现,特点是24段4位,驱动方法是复用1/4占空比,1/3基准,作业电压3V,如下图所示
咱们先剖析下官方给的典范关于LCD的驱动函数
void LCD_GLASS_Init(void)//使能LCD时钟,并设置相应参数
void LCD_contrast()//经过按键调理对比度
void LCD_bar()//将bar值写道LCD缓存中
static void LCD_Conv_Char_Seg(uint8_t* c,bool point,bool column, uint8_t* digit)//将ASCII码转换为LCD显现,第一个参数是要显现的字符比方‘c’,第二个参数是设置POINT是否显现,第三个参数是设置COLUMN是否显现,第四个参数不是很懂
void LCD_GLASS_WriteChar(uint8_t* ch, bool point, bool column, uint8_t position)//将字符写入LCD缓存,和上面参数大体一致
void LCD_GLASS_DisplayString(uint8_t* ptr)//显现字符串,最大只能显现7个,典范:LCD_GLASS_DisplayString(“Error”);
void LCD_GLASS_DisplayStrDeci(uint16_t* ptr)//可以显现有小数点的字符串
void LCD_GLASS_Clear(void)//铲除LCD缓冲区
void LCD_GLASS_ScrollSentence(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed)//字符串语句移动形式显现,运用前需求铲除LCD缓冲区,第一个参数是显现的字符串,第二个参数是显现几回,第三个是速度,单位是毫秒,典范:LCD_GLASS_ScrollSentence(“** STM8L-DISCOVERY **”,1,SCROLL_SPEED);
还有一些常用字符声明,比方A-Z,0-9,一些其他特别字符比方:
/* code for ? character */
#define C_UMAP 0x6081
/* code for m character */
#define C_mMap 0xb210
/* code for n character */
#define C_nMap 0x2210
/* constant code for * character */
#define star 0xA0D7
/* constant code for – character */
#define C_minus 0xA000
#define DOT 0x8000 /* for add decimal point in string */也便是小数点.
#define DOUBLE_DOT 0x4000 /* for add decimal point in string */冒号
/* Macros used for set/reset bar LCD bar */四个BAR宏界说
#define BAR0_ONt_bar[0] |= 0x80
#define BAR0_OFF t_bar[0] &= ~0x80
#define BAR1_ONt_bar[1] |= 0x08
#define BAR1_OFF t_bar[1] &= ~0x08
#define BAR2_ONt_bar[0] |= 0x20
#define BAR2_OFF t_bar[0] &= ~0x20
#define BAR3_ON t_bar[1] |= 0x02
#define BAR3_OFF t_bar[1] &= ~0x02
咱们编写下面一个LCD测试函数
void main(void)
{
uint16_t tab1[3],tab2[5];
/*初始化*/
LCD_GLASS_Init();
//翻滚显现字符串
LCD_GLASS_ScrollSentence(“**STM8L LCD TEST** EEFOCUS”,1,100);
//显现小数
delay_ms(0XFFF);
//LCD_GLASS_Clear();
BAR0_ON;
tab1[0]=1;
tab1[0] |= DOT;
tab1[1]=2;
tab1[2]=V;
LCD_GLASS_DisplayStrDeci(tab1);
//显现:
delay_ms(0XFFFF);
//LCD_GLASS_Clear();
BAR1_ON;
tab2[0]=1;
tab2[1]=7;
tab2[1] |= DOUBLE_DOT;
tab2[2]=0;
tab2[3]=2;
tab2[4]= ;
LCD_GLASS_DisplayStrDeci(tab2);
while (1)
{
}
}