您的位置 首页 IOT

LCD1602的驱动程序的代码编写

LCD1602的驱动程序的代码编写-lcd1602_write(0x38,LCD_WRITE_COM); //设置8位数据接口,两行指令,5*8点阵字符
delay_ms(5);
lcd1602_write(0x38,LCD_WRITE_COM)。

#include

#include “./delay/delay.h”

#define LCDPORT P0

#define LCD_WRITE_DATA 1

#define LCD_WRITE_COM 0

sbit RS = P2^4;

sbit RW = P2^5;

sbit E = P2^6;

unsigned char flag = 1;

unsigned char shi = 23, fen = 59, miao = 50;

void lcd1602_write(unsigned char byte, unsigned char flag)

{

if(flag)

{

RS = 1; //挑选输入的数据为数据

}

else

{

RS = 0; //挑选输入的数据为指令

}

RW = 0; //写

E = 1; //选中lcd

LCDPORT = byte;

delay_ms(5);

E = 0; //失能LCD 高电平有用

}

void lcd_init()

{

delay_ms(15);

lcd1602_write(0x38,LCD_WRITE_COM); //设置8位数据接口,两行指令,5*8点阵字符

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x08,LCD_WRITE_COM); //封闭显现,封闭光标和闪耀

delay_ms(5);

lcd1602_write(0x01,LCD_WRITE_COM); //清屏

delay_ms(5);

lcd1602_write(0x06,LCD_WRITE_COM); //设置指针方法,画面不平移

delay_ms(5);

lcd1602_write(0x0c,LCD_WRITE_COM); //设置指针方法,画面不平移

delay_ms(5);

}

void lcd_dis_char(unsigned char x, unsigned char y, unsigned char *s)

{

if(0 == x)

{

lcd1602_write(y + 0x80,LCD_WRITE_COM);

}

else if(1 == x)

{

lcd1602_write(y + 0xc0,LCD_WRITE_COM);

}

while(*s)

{

lcd1602_write(*s, LCD_WRITE_DATA);

s++;

}

}

void TIme0_init()

{

EA = 1;

TMOD |= 0x01;

TH0 = (65536 – 20000) / 255;

TL0 = (65536 – 20000) % 255;

ET0 = 1;

TR0 = 1;

}

void TIme0_isr() interrupt 1

{

staTIc unsigned char i = 0;

TH0 = (65536 – 20000) / 255;

TL0 = (65536 – 20000) % 255;

i++;

if(50 == i)

{

i = 0;

miao++;

if(60 == miao)

{

miao = 0;

fen++;

if(60 == fen)

{

fen = 0;

shi++;

if(24 == shi)

{

shi = 0;

}

}

}

}

}

void lcd_diaplay_TIme() //时刻的显现函数

{

lcd1602_write(0x80 + 7, LCD_WRITE_COM);

lcd1602_write((shi / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((shi % 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write(':',LCD_WRITE_DATA);

lcd1602_write((fen / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((fen % 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write(':',LCD_WRITE_DATA);

lcd1602_write((miao / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((miao % 10) + 0x30,LCD_WRITE_DATA);

}

void lcd_dis_hex() //显现字符或数字

{

unsigned char temp = 0x2b;

lcd1602_write(0x80,LCD_WRITE_COM);

lcd1602_write((temp / 16) + 0x30,LCD_WRITE_DATA);

lcd1602_write((temp % 16) + 0x37,LCD_WRITE_DATA);

}

void main()

{

time0_init();

lcd_init();

lcd_dis_hex();

lcd_dis_char(0,2,”time:”);

while(1)

{

lcd_diaplay_time();

}

}

#include

#include “./delay/delay.h”

#define LCDPORT P0

#define LCD_WRITE_DATA 1

#define LCD_WRITE_COM 0

sbit RS = P2^4;

sbit RW = P2^5;

sbit E = P2^6;

unsigned char flag = 1;

unsigned char shi = 23, fen = 59, miao = 50;

void lcd1602_write(unsigned char byte, unsigned char flag)

{

if(flag)

{

RS = 1; //挑选输入的数据为数据

}

else

{

RS = 0; //挑选输入的数据为指令

}

RW = 0; //写

E = 1; //选中lcd

LCDPORT = byte;

delay_ms(5);

E = 0; //失能LCD 高电平有用

}

void lcd_init()

{

delay_ms(15);

lcd1602_write(0x38,LCD_WRITE_COM); //设置8位数据接口,两行指令,5*8点阵字符

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x38,LCD_WRITE_COM);

delay_ms(5);

lcd1602_write(0x08,LCD_WRITE_COM); //封闭显现,封闭光标和闪耀

delay_ms(5);

lcd1602_write(0x01,LCD_WRITE_COM); //清屏

delay_ms(5);

lcd1602_write(0x06,LCD_WRITE_COM); //设置指针方法,画面不平移

delay_ms(5);

lcd1602_write(0x0c,LCD_WRITE_COM); //设置指针方法,画面不平移

delay_ms(5);

}

void lcd_dis_char(unsigned char x, unsigned char y, unsigned char *s)

{

if(0 == x)

{

lcd1602_write(y + 0x80,LCD_WRITE_COM);

}

else if(1 == x)

{

lcd1602_write(y + 0xc0,LCD_WRITE_COM);

}

while(*s)

{

lcd1602_write(*s, LCD_WRITE_DATA);

s++;

}

}

void time0_init()

{

EA = 1;

TMOD |= 0x01;

TH0 = (65536 – 20000) / 255;

TL0 = (65536 – 20000) % 255;

ET0 = 1;

TR0 = 1;

}

void time0_isr() interrupt 1

{

static unsigned char i = 0;

TH0 = (65536 – 20000) / 255;

TL0 = (65536 – 20000) % 255;

i++;

if(50 == i)

{

i = 0;

miao++;

if(60 == miao)

{

miao = 0;

fen++;

if(60 == fen)

{

fen = 0;

shi++;

if(24 == shi)

{

shi = 0;

}

}

}

}

}

void lcd_diaplay_time() //时刻的显现函数

{

lcd1602_write(0x80 + 7, LCD_WRITE_COM);

lcd1602_write((shi / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((shi % 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write(':',LCD_WRITE_DATA);

lcd1602_write((fen / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((fen % 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write(':',LCD_WRITE_DATA);

lcd1602_write((miao / 10) + 0x30,LCD_WRITE_DATA);

lcd1602_write((miao % 10) + 0x30,LCD_WRITE_DATA);

}

void lcd_dis_hex() //显现字符或数字

{

unsigned char temp = 0x2b;

lcd1602_write(0x80,LCD_WRITE_COM);

lcd1602_write((temp / 16) + 0x30,LCD_WRITE_DATA);

lcd1602_write((temp % 16) + 0x37,LCD_WRITE_DATA);

}

void main()

{

time0_init();

lcd_init();

lcd_dis_hex();

lcd_dis_char(0,2,”time:”);

while(1)

{

lcd_diaplay_time();

}

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/iot/347437.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部