需要就拿去用吧
单片机源程序如下:
- #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提供下载:
51单片机驱动IIC1602程序(4针).7z
(48.77 KB, 下载次数: 288)
|