標(biāo)題: 12864亂碼,重啟后顯示不一樣 [打印本頁(yè)]

作者: paomo113355    時(shí)間: 2016-4-1 10:52
標(biāo)題: 12864亂碼,重啟后顯示不一樣
本帖最后由 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測(cè)忙函數(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);//開(kāi)顯示 關(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);
}




[attach]20757[/attach]

[attach]20756[/attach]















作者: 編程愛(ài)好者i    時(shí)間: 2016-4-1 13:38
延時(shí)問(wèn)題
作者: paomo113355    時(shí)間: 2016-4-1 13:57
編程愛(ài)好者i 發(fā)表于 2016-4-1 13:38
延時(shí)問(wèn)題

能具體一點(diǎn)嗎,什么地方的延時(shí)
作者: wc86110    時(shí)間: 2016-4-1 15:38
不明白 LZ 粘貼的源代碼如何能顯示漢字。
作者: 騰飛的龍    時(shí)間: 2016-4-2 20:12
你把顯示地址那個(gè)函數(shù)不用直接用寫地址和寫數(shù)據(jù)函數(shù)試試。
作者: scdpj    時(shí)間: 2016-4-4 10:28
重新編寫程序
作者: jiajuntao    時(shí)間: 2016-4-4 15:57
可以修改時(shí)鐘
作者: liuyimao485812    時(shí)間: 2016-4-5 15:34
延時(shí)時(shí)間不夠長(zhǎng),再適當(dāng)加長(zhǎng)點(diǎn)。
作者: 走天涯    時(shí)間: 2016-4-5 23:51
單片機(jī)需要細(xì)心
作者: 1602670702    時(shí)間: 2016-4-6 13:36
不錯(cuò),學(xué)習(xí)到很多東西




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1