需要就拿去用吧
0071ba48cc02255d6bb58582f6b0269.jpg (153.22 KB, 下載次數: 76)
下載附件
2020-5-3 18:48 上傳
單片機源程序如下:
- #include "IIC.h"
- #define adress_1602 0x4e
- unsigned char LCD_data=0x08;
- //********************液晶屏使能*********************
- void Enable_LCD_write()
- {
- LCD_data|=(1<<(3-1));//E=1;
- Write_Random_Address_Byte(adress_1602,LCD_data); //
- Delay1us(2);
- LCD_data&=~(1<<(3-1));//E=0;
- Write_Random_Address_Byte(adress_1602,LCD_data);
- }
- /*------------------------------------------------
- 寫入命令函數
- ------------------------------------------------*/
- void LCD_write_command(unsigned char command)
- {
- Delay1us(16);
- LCD_data&=~(1<<(1-1));//RS=0;
- LCD_data&=~(1<<(2-1));//RW=0;
- //LCD_data&=~(1<<(4-1));
- Write_Random_Address_Byte(adress_1602,LCD_data);
-
- LCD_data&=0X0f; //清高四位
- LCD_data|=command & 0xf0; //寫高四位
- Write_Random_Address_Byte(adress_1602,LCD_data);
- Enable_LCD_write();
-
- command=command<<4; //低四位移到高四位
- LCD_data&=0x0f; //清高四位
- LCD_data|=command&0xf0; //寫低四位
- Write_Random_Address_Byte(adress_1602,LCD_data);
- Enable_LCD_write();
- }
- /*------------------------------------------------
- 寫入數據函數
- ------------------------------------------------*/
- void LCD_write_dat(unsigned char value)
- {
- Delay1us(16);
- LCD_data|=(1<<(1-1));//RS=1;
- LCD_data&=~(1<<(2-1));//RW=0;
- Write_Random_Address_Byte(adress_1602,LCD_data);
-
- LCD_data&=0X0f; //清高四位
- LCD_data|=value&0xf0; //寫高四位
- Write_Random_Address_Byte(adress_1602,LCD_data);
- Enable_LCD_write();
-
- value=value<<4; //低四位移到高四位
- LCD_data&=0x0f; //清高四位
- LCD_data|=value&0xf0; //寫低四位
- Write_Random_Address_Byte(adress_1602,LCD_data);
- Enable_LCD_write();
- }
- /*------------------------------------------------
- 清屏函數
- ------------------------------------------------*/
- void LCD_Clear(void)
- {
- LCD_write_command(0x01);
- Delay1ms(2);
- }
- /*------------------------------------------------
- 設置顯示位置
- ------------------------------------------------*/
- void LCD_set_xy( unsigned char x, unsigned char y )
- {
- unsigned char address;
- if (y == 1)
- address = 0x80 + x;
- else
- address =0xc0+ x;
- LCD_write_command(address);
- }
- /*------------------------------------------------
- 顯示一個字符
- ------------------------------------------------*/
- void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat)
- {
- LCD_set_xy( x, y );
- LCD_write_dat(dat);
- }
- /*------------------------------------------------
- 顯示字符串函數
- ------------------------------------------------*/
- void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s)
- {
- LCD_set_xy( X, Y );
- while (*s)
- {
- LCD_write_dat(*s);
- s ++;
- }
- }
- /*------------------------------------------------
- 把特殊字符數據寫入顯存
- ------------------------------------------------*/
- //void WriteCGRAM()
- //{
- // unsigned char i,j,k,tmp;
- // tmp=0x40;//設置CGRAM地址的格式字
- // k=0;
- //
- // for(j=0;j<8;j++)
- // {
- // for(i=0;i<8;i++)
- // {
- // LCD_write_command(tmp+i); // 設置自定義字符的 CGRAM 地址
- // Delay1us(50);
- // LCD_write_dat(table0[k]); // 向CGRAM寫入自定義字符表的數據
- // k++;
- // Delay1us(50);
- // }
- // tmp=tmp+8;
- // }
- //}
- /*------------------------------------------------
- 初始化函數
- ------------------------------------------------*/
- void LCD_Init(void)
- {
- LCD_write_command(0x02);
- Delay1us(40);
- LCD_write_command(0x28); //4位顯示!!!!!!!!!!!!!!!!!!
- LCD_write_command(0x0c); //顯示開
- LCD_write_command(0x01); //清屏
- Delay1ms(10);
- }
復制代碼
51hei.png (10.51 KB, 下載次數: 74)
下載附件
2020-5-4 00:53 上傳
所有資料51hei提供下載:
51單片機驅動IIC1602程序(4針).7z
(48.77 KB, 下載次數: 288)
2020-5-3 18:50 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|