小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

1602液晶屏字符串的顯示

 戶外驢行 2012-03-22

//改程序?qū)?shí)現(xiàn)靜態(tài)字符串在液晶屏上的顯示
//程序員:徐茂龍
//完成時(shí)間:2012.03.22

#include <reg52.h>
#include <intrins.h>
#include <stdio.h>

#define uchar unsigned char
#define Data P0

//管腳的定義
sbit RS = P2^1;
sbit RW = P1^5;
sbit E = P1^6;
sbit BF = P0^7;
sbit WEI = P2^7;
sbit DUAN = P2^6;

uchar code string[] = {"I love WangLele!"};

//函數(shù)聲明
void Delay(uchar);   //延時(shí)函數(shù)
void Init();         //初始化函數(shù)
void Busy();         //忙時(shí)檢測(cè)函數(shù)
void Write(uchar, bit);    //寫(xiě)入函數(shù)
void Display(uchar);


void main()
{
    uchar i;
 //關(guān)閉所有數(shù)碼管
 Data = 0x0;
 WEI = 1;
 WEI = 0;
 Data = 0xff;
 DUAN = 1;
 DUAN = 0;

 Init();
 Display(0x0);
 while(1)
 {
     Write(string[i], 1);
  i ++;
  if(i == '!')
      while(1);
 }
}

void Delay(uchar i)
{
    uchar j;
 for(; i > 0; i --)
     for(j = 155; j > 0; j --);      //最少延時(shí)1ms
}


void Busy()
{
    Delay(5);
 RS = 0;         //根據(jù)規(guī)定:當(dāng)RS = 0; RW = 1時(shí)才能讀取指令
 RW = 1;
 E = 1;          //E = 1才允許讀寫(xiě)
 _nop_();
 _nop_();        //兩個(gè)空操作,給硬件反應(yīng)時(shí)間
 while(BF);  //忙時(shí)檢測(cè)
 E = 0;
}

void Write(uchar i, bit flag)
{
    Delay(5);
 Busy();       //當(dāng)不是忙時(shí)時(shí),
 RS = flag;          //flag的值將決定是對(duì)數(shù)據(jù)操作還是對(duì)指令操作
 RW = 0;
 E = 0;              //在寫(xiě)指令或者數(shù)據(jù)時(shí),E要處于高脈沖,就是說(shuō)E要從0狀態(tài)轉(zhuǎn)為1
 _nop_();
 _nop_();        //兩個(gè)空操作,給硬件反應(yīng)時(shí)間
 Data = i;
 _nop_();
 _nop_();        //兩個(gè)空操作,給硬件反應(yīng)時(shí)間
 E = 1;
 _nop_();
 _nop_();        //兩個(gè)空操作,給硬件反應(yīng)時(shí)間
 E = 0;          //當(dāng)E由高電平轉(zhuǎn)為低電平時(shí),開(kāi)始執(zhí)行指令操作
}

void Init()          //初始化函數(shù)
{
    Delay(15);          //第一次進(jìn)行操作時(shí),延時(shí)時(shí)間稍長(zhǎng)一點(diǎn)
 Busy();
 Write(0x01, 0);     //清平指令
 Delay(5);
 Write(0x06, 0);     //【輸入方式設(shè)置命令】光標(biāo)從左向右移動(dòng),內(nèi)容不移動(dòng)
 Delay(5);
 Write(0x0f, 0);     //【顯示開(kāi)關(guān)設(shè)置命令】顯示開(kāi),光標(biāo)顯示,字符閃爍
 Delay(5);
 Write(0x38, 0);     //【功能設(shè)置命令】8位數(shù)據(jù),雙行顯示,5*7點(diǎn)陣
 Delay(5);
}

void Display(uchar temp)
{
    Write(temp | 0x80, 0);
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多