LCD1602.H
代码如下:
#ifndef __LCD1602_H_
#define __LCD1602_H_
#include <reg52.h>
typedef unsigned char uint8;
sbit RS = P1 ^ 0;
sbit RW = P1 ^ 1;
sbit EN = P2 ^ 5;
sbit STA7 = P0 ^ 7;
void Init_LCD1602 ( void );
void w_string ( uint8 addr_start, uint8 *p );
#endif
LCD1602.c
代码如下:
#include "LCD1602.h"
static void delay1ms ( uint8 i ) {
while ( i-- ) {
unsigned char a, b, c;
for ( c = 1; c > 0; c-- )
for ( b = 4; b > 0; b-- )
for ( a = 109; a > 0; a-- );
}
}
static void wait ( void ) {
P0 = 0xFF;
do {
RS = 0;
RW = 1;
EN = 1;
} while ( STA7 == 1 );
}
static void w_dat ( uint8 dat ) {
wait();
RS = 1;
RW = 0;
P0 = dat;
EN = 0;
EN = 1;
EN = 0;
}
static void w_cmd ( uint8 cmd ) {
wait();
P0 = cmd;
RS = 0;
RW = 0;
EN = 0;
EN = 1;
EN = 0;
}
void w_string ( uint8 addr_start, uint8 *p ) {
w_cmd ( addr_start );
while ( *p != '\0' ) {
w_dat ( *p++ );
}
}
void Init_LCD1602 ( void ) {
delay1ms ( 15 );
w_cmd ( 0x38 );
delay1ms ( 5 );
w_cmd ( 0x38 );
delay1ms ( 5 );
w_cmd ( 0x38 );
w_cmd ( 0x38 );
w_cmd ( 0x08 );
w_cmd ( 0x01 );
w_cmd ( 0x06 );
w_cmd ( 0x0C );
}
main.c
代码如下:
#include <reg52.h>
#include "LCD1602.h"
#include <intrins.h>
unsigned char code word1[] = {"Hello,111"};
unsigned char code word2[] = {"World,111"};
int main ( void ) {
Init_LCD1602();
w_string ( 0x80, word1 );
w_string ( 0xC0, word2 );
while ( 1 );
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)