標(biāo)題: 1602顯示程序 [打印本頁(yè)]

作者: maochunlei    時(shí)間: 2015-10-25 23:43
標(biāo)題: 1602顯示程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^5;
sbit wr=P3^6;
sbit lcden=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
uchar table1[]="nihao";
//uchar table2[]="WWW:51hei:COM";
void delay(uint x)
{
        uint a,b;
        for(a=x;a>0;a--)
                for(b=10;b>0;b--);
}

void write_com(uchar com)         //些命令,RS=0
{
        P0=com;
           wr=0;
        rs=0;
        lcden=0;
        delay(10);
        lcden=1;
        delay(10);
        lcden=0;
       
}

void write_data(uchar dat)           //寫(xiě)數(shù)據(jù),RS=1
{
        P0=dat;
        wr=0;
        rs=1;
        lcden=0;
        delay(10);
        lcden=1;
        delay(10);
        lcden=0;
       
}

void init()
{
        dula=0;
        wela=0;
        write_com(0x38);   //顯示模式設(shè)置:16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口
        delay(20);
        write_com(0x0f);   //顯示模式設(shè)置
        delay(20);
        write_com(0x06);   //顯示模式設(shè)置:光標(biāo)右移,字符不移
        delay(20);
        write_com(0x01);   //清屏幕指令,將以前的顯示內(nèi)容清除
        delay(20);       
}
void main()
{
        uchar a;
        init();                          //1602初始化
        write_com(0x80);  //設(shè)置所要顯示字符的位置為第一行第一列
        a=0;
        while(table1[a]!='\0')        //只要沒(méi)有寫(xiě)到結(jié)束標(biāo)志,就繼續(xù)寫(xiě)
                {                                        //這是寫(xiě)字符的第一種方法,用while循環(huán)。
                write_data(table1[a]);
                a++;
                }
//        write_com(0x80+0x40);  //設(shè)置第二行首字符顯示的位置,為第二行,第一列
//        a=0;
//        for(a=0;a<13;a++)           //總共要顯示13個(gè)字符,故循環(huán)十三次。
//        {                                           //這是寫(xiě)字符的第二種方法,用for循環(huán)
//        write_data(table2[a]);
//        delay(10);               
//        }
        while(1);
}

作者: 騰飛的龍    時(shí)間: 2015-10-27 18:25
不錯(cuò)的程序,簡(jiǎn)潔明了,
作者: 夏目什么賬    時(shí)間: 2016-3-8 17:22
為什么只顯示方塊?
作者: 15613875202    時(shí)間: 2017-6-17 13:53
給力666666




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