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

作者: kjl    時(shí)間: 2018-1-22 09:48
標(biāo)題: 1602液晶顯示程序
#include<reg52.h>
typedef unsigned char uint8;//數(shù)據(jù)類型宏定義
sbit BF = P0^7;//BF代表P0的最高位
sbit EN = P2^5;//LCD使能端---隨電路設(shè)計(jì)調(diào)整
sbit RS = P1^0;//指令/數(shù)據(jù)
sbit RW = P1^1;//讀/寫
sbit s1=P3^4;
void wait(void)//讀狀態(tài),如果忙就繼續(xù)檢查;如果閑,就執(zhí)行后續(xù)語句
{
         P0=0xFF;
       
         do
                 {
                 RS=0;
                 RW=1;
                 EN=0;
                 EN=1;
                 }
         while (BF==1);        //(bit)()
         EN=0;
}

//寫數(shù)據(jù)函數(shù)---顯示
void w_dat(uint8 dat)
{
        wait();
        EN=0;
        P0=dat;
        RS=1;
        RW=0;
        EN=1;
        EN=0;
}

void w_cmd(uint8 cmd)//寫指令函數(shù)--執(zhí)行cmd代碼
{
        wait();//等待函數(shù)
        EN=0;
        P0=cmd;
        RS=0;
        RW=0;
        EN=1;
        EN=0;
}

void Init_LCD1602(void)
{
        w_cmd(0x38);//寫指令0x38--顯示模式
        w_cmd(0x0c);//0000 1100--打開顯示
        w_cmd(0x06);
        w_cmd(0x01);
}
main()
{
        Init_LCD1602();//調(diào)用LCD函數(shù)
        if(s1==0)
        w_cmd(0x80+0x31);  //確定顯示的位置--寫指令
        //代碼為具體的地址值  0x80=0x80+0x00
        w_dat('A'); //顯示一個(gè)字符 A   'A'
        while(1);
}






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