找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3496|回復(fù): 9
打印 上一主題 下一主題
收起左側(cè)

12864亂碼,重啟后顯示不一樣

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
本帖最后由 paomo113355 于 2016-4-1 10:55 編輯

#include<reg51.h>
#define uint  unsigned int
#define uchar unsigned char

sbit RW=P2^6;        
sbit RS=P2^5;
sbit EN=P2^7;
sbit PSB=P3^2;
sbit RST=P3^4;
sbit date=P0;
uchar code shu[]="0123456789";
uchar code name[]="1234";
uchar code qq[]="1257570344";
uchar code tel[]="18483662440";
//********************************************
void busy()//12864測忙函數(shù)
{
        while(1)
        {
                RS=0;
                RW=1;
                EN=1;
                if((date&0x80)==0)
                {
                        EN=0;
                        break;
                }               
        }                        
}

//******************************************
void delayms(uint time)//毫秒延時(shí)
{
        uint x,y;
        for(x=time;x;x--)
                for(y=110;y;y--);
}
//*********************************************
void write_com(uchar com) //寫指令
{
        busy();
        RS=0;
        RW=0;
        EN=1;
        delayms(2);
        P0=com;        
        delayms(2);
        EN=0;
}
//**********************************************
void write_date(uchar date)//寫數(shù)據(jù)
{
        busy();
        RS=1;
        RW=0;
        EN=1;
        delayms(2);
        P0=date;
        delayms(2);        
        EN=0;
}
//********************************************
void lcdpos(uchar x,uchar y)//顯示地址
{
        if(x==0)
                x=0x80;        
        else
        if(x==1)
                x=0x90;
        else
        if(x==2)
                x=0x88;
        else
                if(x==3)
        x=0x98;
        write_com(x+y);
}        
//***********************************************
void init()//初始化
{        
        delayms(50);
        PSB=1;
        RST=0;
        RST=1;
        write_com(0x30);//基本指令操作
        delayms(5);
        write_com(0x30);
        delayms(5);               
        write_com(0x06);
        delayms(5);
        write_com(0x01);//清除內(nèi)容
        delayms(5);
        write_com(0x0c);//開顯示 關(guān)光標(biāo)               
}
//************************************************
void display()
{        uchar i;
        lcdpos(0,0);//第一行
        for(i=0;name!=0;i++)
        {
                write_date(name);
                delayms(5);        
        }

        lcdpos(1,0);
        for(i=0;qq!=0;i++)
        {
                write_date(qq);
                delayms(5);        
        }

        lcdpos(2,0);        
        write_com(0x88);//第三行
        for(i=0;tel!=0;i++)
        {
                write_date(tel);
                delayms(5);        
        }        
}
//**************************************************
void main(void)
{
        init();
        init();
        display();
        while(1);
}





















分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:107657 發(fā)表于 2016-4-1 13:38 | 只看該作者
延時(shí)問題
回復(fù)

使用道具 舉報(bào)

板凳
ID:91424 發(fā)表于 2016-4-1 13:57 | 只看該作者

能具體一點(diǎn)嗎,什么地方的延時(shí)
回復(fù)

使用道具 舉報(bào)

地板
ID:96682 發(fā)表于 2016-4-1 15:38 | 只看該作者
不明白 LZ 粘貼的源代碼如何能顯示漢字。
回復(fù)

使用道具 舉報(bào)

5#
ID:79544 發(fā)表于 2016-4-2 20:12 | 只看該作者
你把顯示地址那個(gè)函數(shù)不用直接用寫地址和寫數(shù)據(jù)函數(shù)試試。
回復(fù)

使用道具 舉報(bào)

6#
ID:109833 發(fā)表于 2016-4-4 10:28 | 只看該作者
重新編寫程序
回復(fù)

使用道具 舉報(bào)

7#
ID:104472 發(fā)表于 2016-4-4 15:57 | 只看該作者
可以修改時(shí)鐘
回復(fù)

使用道具 舉報(bào)

8#
ID:110895 發(fā)表于 2016-4-5 15:34 | 只看該作者
延時(shí)時(shí)間不夠長,再適當(dāng)加長點(diǎn)。
回復(fù)

使用道具 舉報(bào)

9#
ID:111947 發(fā)表于 2016-4-5 23:51 | 只看該作者
單片機(jī)需要細(xì)心
回復(fù)

使用道具 舉報(bào)

10#
ID:112485 發(fā)表于 2016-4-6 13:36 | 只看該作者
不錯(cuò),學(xué)習(xí)到很多東西
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表