找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3378|回复: 1
打印 上一主题 下一主题
收起左侧

1602程序修改

[复制链接]
跳转到指定楼层
楼主
ID:59106 发表于 2014-2-19 10:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问1602的代码如何写啊,这是我写的但是运行不了,怎么回事呢#include<reg52.h>sbit dula=P2^6;
sbit wela=P2^7;
sbit lcden=P3^4;
sbit lcdrs=P3^5;
unsigned char code table[]="I LOVE MCU!";
unsigned char code table1[]="WWW.TXMCU.COM";
unsigned char num;
void delay(unsigned int t);
void write_com(unsigned char com)
{
   lcdrs=0;
   P0=com;
   delay(5);
   lcden=1;
   delay(5);
   lcden=0;
}
void write_data(unsigned char date)
{
   lcdrs=1;
   P0=date;
   delay(5);
   lcden=1;
   delay(5);
   lcden=0;
}
void init()
{
  dula=0;
  wela=0;
  lcden=0;
  write_com(0x38);
  write_com(0x0c);
  write_com(0x06);
  write_com(0x01);
}
void main()
{


     init();
     write_com(0x80);
     for(num=0;num<11;num++)
        {
        write_data(table[num]);
        delay(5);
        }
     write_com(0x80+0x40);
     for(num=0;num<13;num++)
     {
       write_data(table1[num]);
       delay(5);
     }
    while(1);
}
void delay(unsigned int t)
{
  while(--t);
}


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2014-2-24 22:40 | 只看该作者
#include "at89x52.h"
#include "51hei.h"

#define LCM_RW  P2_7 //定义引脚
#define LCM_RS  P3_5
#define LCM_E   P3_4
#define LCM_Data  P0
#define Busy    0x80 //用于检测LCM状态字中的Busy标识




void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCM,BuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
void LCMInit(void);
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
void Delay5Ms(void);
void Delay400Ms(void);

unsigned char code uctech[] = {"    *51hei*    "};
unsigned char code net[] =    {" www.51Hei.com "};

void main(void)
{
  guandz();//关闭点阵
  guanled();//关闭led数码管

  Delay400Ms(); //启动等待,等LCM讲入工作状态
  LCMInit(); //LCM初始化
  Delay5Ms(); //延时片刻(可不要)

  DisplayListChar(0, 5, uctech);
  DisplayListChar(0, 0, net);
  ReadDataLCM();//测试用句无意义

while(1);
}

//写数据
void WriteDataLCM(unsigned char WDLCM)
{
ReadStatusLCM(); //检测忙
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0; //若晶振速度太高可以在这后加小的延时
LCM_E = 0; //延时
LCM_E = 1;
}

//写指令
void WriteCommandLCM(unsigned char WCLCM,BuysC) //BuysC为0时忽略忙检测
{
if (BuysC) ReadStatusLCM(); //根据需要检测忙
LCM_Data = WCLCM;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}

//读数据
unsigned char ReadDataLCM(void)
{
LCM_RS = 1;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
return(LCM_Data);
}

//读状态
unsigned char ReadStatusLCM(void)
{
LCM_Data = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
while (LCM_Data & Busy); //检测忙信号
return(LCM_Data);
}

void LCMInit(void) //LCM初始化
{
LCM_Data = 0;
WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();
WriteCommandLCM(0x38,0);
Delay5Ms();

WriteCommandLCM(0x38,1); //显示模式设置,开始要求每次检测忙信号
WriteCommandLCM(0x08,1); //关闭显示
WriteCommandLCM(0x01,1); //显示清屏
WriteCommandLCM(0x06,1); // 显示光标移动设置
WriteCommandLCM(0x0C,1); // 显示开及光标设置
}

//按指定位置显示一个字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; // 算出指令码
WriteCommandLCM(X, 0); //这里不检测忙信号,发送地址码
WriteDataLCM(DData);
}

//按指定位置显示一串字符
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength;

  ListLength = 0;
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
while (DData[ListLength]>0x19) //若到达字串尾则退出
  {
   if (X <= 0xF) //X坐标应小于0xF
    {
     DisplayOneChar(X, Y, DData[ListLength]); //显示单个字符
     ListLength++;
     X++;
    }
  }
}

//5ms延时
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}

//400ms延时
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
  TempCycB=7269;
  while(TempCycB--);
};





}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表