#include "STC15F-15W.h"
#include "LCD16024L1.h"
/******** 数据定义 ******/
unsigned char code uctech[] = {"0123456789ABCDEF"};
unsigned char code net[] = {"www.51hei.com"};
void main(void)
{
delay_ms(300); //启动等待,等 LCD 讲入工作状态
LCD_init(); //初始化
delay_ms(5); //延时片刻 (可不要 )
LCD_str(0, 0, uctech);
LCD_str(0, 1, net);
while(1);
}
/*这两个程序通过了STC15W408AS单片机系统的验证,主频11.0592NHz时。请坛友指正!*/
#ifndef __LCD16024L1_H__
#define __LCD16024L1_H__
unsigned char bdata C; //在位寻址区定义字符变量C
sbit C7=C^7;
sbit C6=C^6;
sbit C5=C^5;
sbit C4=C^4;
sbit C3=C^3;
sbit C2=C^2;
sbit C1=C^1;
sbit C0=C^0;
sbit RS=P5^5;
//sbit RW=P1^2;
sbit EN=P5^4;
sbit I4=P3^4;
sbit I5=P3^5;
sbit I6=P3^6;
sbit I7=P3^7;
/****************延时***************/
void delay_ms(unsigned int i)
{
unsigned int t;
while(i--)
{
for(t=0;t<123;t++);
}
}
/***用LCD1602高四位数据线写入命令**/
void write_com(unsigned char command)
{
C=command;
RS=0;
//RW=0;
EN=0; //写命令
delay_ms(1);
I7=C7;
I6=C6;
I5=C5;
I4=C4;
EN=1;
delay_ms(6); //延时
EN=0; //下降沿将数据写入LCD1602
delay_ms(1);
I7=C3;
I6=C2;
I5=C1;
I4=C0;
EN=1;
delay_ms(1); //延时
EN=0; //下降沿将数据写入LCD1602
}
/**用LCD1602高四位数据线写入数据**/
void write_dat(unsigned char dat)
{
C=dat;
RS=1;
//RW=0;
EN=0;
delay_ms(1);
I7=C7;
I6=C6;
I5=C5;
I4=C4;
EN=1;
delay_ms(6); //延时
EN=0;
delay_ms(1);
I7=C3;
I6=C2;
I5=C1;
I4=C0;
EN=1;
delay_ms(1); //延时
EN=0;
}
/********LCD1602初始化*************/
void LCD_init(void)
{
write_com(0x02);
write_com(0x28);
write_com(0x0c);
write_com(0x80);
write_com(0x01); //清屏
}
/*******设置LCD1602列、行**********/
void LCD_sor(unsigned char x,unsigned y)
{
unsigned char address;
if(y==0)
address=0x80+x;
else
address=0xC0+x;
write_com(address);
}
/*******************/
void LCD_str(unsigned x,unsigned char y,unsigned char *str)
{
LCD_sor(x,y);
while((*str)!='