單片機源程序如下:- #include "sys.h"
- #include "delay.h"
- #include "lcd1602.h"
- const u8 table1[] = "Hello Everyone!";
- const u8 table2[] = "Welcome to hear!";
- /////////////////////////////////////////////////////////
- //本程序只供學習使用,未經作者許可,不得用于其它任何用途
- //LCD1602液晶顯示測試
- //液晶控制芯片HD44780及兼容芯片
- //驅動方式:并口驅動
- //作者;jia
- //創建日期:2016年3月19日
- //部分程序引用@正點原子
- //對此程序如有疑問或建議
- /////////////////////////////////////////////////////////
- u8 i;
- int main(void)
- {
- delay_init();
- lcd1602_init();
- while(1)
- {
- // lcd1602_write_byte(0x01,write_cmd);
- lcd1602_write_byte(0x80+0x10,write_cmd);
- for(i=0;i<15;i++)
- {
- lcd1602_write_byte(table1[i],write_dat);
- delay_ms(20);
- }
- lcd1602_write_byte(0x80+0x50,write_cmd);//必須用寫命令來指定在GRAM哪個地址上寫內容
- for(i=0;i<16;i++)
- {
- lcd1602_write_byte(table2[i],write_dat);
- delay_ms(20);
- }
-
- for(i=0;i<16;i++)
- {
- lcd1602_write_byte(0x18,write_cmd);
- delay_ms(500);
- }
- while(1);
- }
- }
復制代碼
- #include "lcd1602.h"
- #include "delay.h"
- /////////////////////////////////////////////////////////
- //本程序只供學習使用,未經作者許可,不得用于其它任何用途
- //LCD1602液晶顯示測試
- //液晶控制芯片HD44780及兼容芯片
- //驅動方式:并口驅動
- //作者;jia
- //創建日期:2016年3月19日
- //部分程序引用@正點原子
- //對此程序如有疑問或建議
- /////////////////////////////////////////////////////////
- //mode:0 寫命令 1 寫數據
- //dat 寫入液晶數據口的數據
- void lcd1602_write_byte(u8 dat,u8 mode)
- {
- // GPIO_Write(GPIOB,dat<<8); //ok
- lcd1602_port_dat(dat) //ok
- lcd1602_rs = mode;
- // lcd1602_en = 0;
- // delay_ms(10);
- lcd1602_en = 1;
- delay_ms(10);
- lcd1602_en = 0;
- }
- //LCD1602初始化函數
- void lcd1602_init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
-
- GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStruct.GPIO_Pin=GPIO_Pin_All;
- GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_Write(GPIOB, 0XFF);
-
- lcd1602_write_byte(0x38,write_cmd);//16*2顯示,5*7點陣,8位數據接口
- // delay_ms(100);
- lcd1602_write_byte(0x0f,write_cmd);//開顯示,開光標,光標閃爍
- //delay_ms(100);
- lcd1602_write_byte(0x06,write_cmd);//字符指針加1,光標加1;寫一個字符整屏不移動
- //delay_ms(100);
- lcd1602_write_byte(0x01,write_cmd);//清屏
- }
復制代碼
Keil代碼下載:
庫函數-LCD1602.7z
(176.83 KB, 下載次數: 18)
2022-5-3 03:43 上傳
點擊文件名下載附件
STM32 下載積分: 黑幣 -5
|