欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: LCD1602顯示漢字 年月日 [打印本頁]

作者: Lukezhao    時間: 2016-4-13 19:43
標題: LCD1602顯示漢字 年月日
//***************************************************************************************
//硬件連接:1602VDD接5V,VO接地,BL1接5V,BL2接地,8根數據線接P0
//口,RS RW E分別接P2.0、P2.1、P.4口
//***************************************************************************************
#include <REG52.h>
#include <string.h>


#define Busy 0x80 //用于檢測LCM狀態字中的Busy標識
#define LCM_Data P0
sbit LCM_RS = P3^7;             //寄存器選擇
sbit LCM_RW = P3^6;          //讀/寫控制
sbit LCM_E = P3^5;             //讀/寫使能
int i,j;

//自定義字符列表
//=====================================================================================
unsigned char character0[8] = {0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02},   //年
                      character1[8] = {0x0f,0x09,0x0f,0x09,0x0f,0x09,0x0b,0x11}, //月
              character2[8] = {0x0f,0x09,0x09,0x09,0x0f,0x09,0x09,0x0f}, //日
                           characterN[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //日
//=====================================================================================

//=====================================================================================
//延時程序
//=====================================================================================
void Delay5Ms(void)
{
        unsigned long int TempCyc = 5552;
        while(TempCyc--);
}
//========================================第5頁========================================
void Delay400Ms(void)
{
        unsigned char TempCycA = 5;
        unsigned int TempCycB;
        while(TempCycA--)
        {
                TempCycB=7269;
                while(TempCycB--);
        };
}

//=====================================================================================
//讀寫子程序
//=====================================================================================
//讀數據
unsigned char ReadDataLCM(void)
{
        LCM_RS = 1;  
        LCM_RW = 1;
        LCM_E = 1;
        LCM_E = 0;
        for(i=0;i<100;i++);
                LCM_E = 1;
        return(LCM_Data);
}
//讀狀態
unsigned char ReadStatusLCM(void)
{
        LCM_Data = 0xFF;  
        LCM_RS = 0;
        LCM_RW = 1;
        LCM_E = 1;
        LCM_E = 0;
        for(i=0;i<100;i++);
                LCM_E = 1;
        while (LCM_Data & Busy); //檢測忙信號
        return(LCM_Data);
}
//寫數據
//========================================第6頁========================================
void WriteDataLCM(unsigned char WDLCM)
{
        ReadStatusLCM(); //檢測忙
        LCM_Data = WDLCM;
        LCM_RS = 1;
        LCM_RW = 0;
        LCM_E = 1;  
        LCM_E = 0; //若晶振速度太高可以在這后加小的延時
        for(i=0;i<100;i++);//延時
        LCM_E = 1;
}
//寫指令
void WriteCommandLCM(unsigned char WCLCM,BuysC) //BuysC為0時忽略忙檢測
{
        if (BuysC) ReadStatusLCM(); //根據需要檢測忙
        LCM_Data = WCLCM;
        LCM_RS = 0;
        LCM_RW = 0;  
        LCM_E = 1;
        LCM_E = 0;
        for(i=0;i<100;i++);
        LCM_E = 1;  
}
//=====================================================================================
//初始化子程序
//=====================================================================================
void LCMInit(void) //LCM初始化
{
        LCM_Data = 0;
        WriteCommandLCM(0x38,0); // 三次顯示模式設置,不檢測忙信號
        Delay5Ms();  
        WriteCommandLCM(0x38,0);
        Delay5Ms();  
        WriteCommandLCM(0x38,0);
        Delay5Ms();  
        WriteCommandLCM(0x38,1); // 顯示模式設置,開始要求每次檢測忙信號
        Delay5Ms();
        WriteCommandLCM(0x08,1); // 關閉顯示
//========================================第7頁========================================
        Delay5Ms();
        WriteCommandLCM(0x01,1); // 清屏
        Delay5Ms();
        WriteCommandLCM(0x06,1); // 顯示光標移動設置
        Delay5Ms();
        WriteCommandLCM(0x0c,1); // 顯示開及光標設置
        Delay5Ms();
}

//=====================================================================================
//按指定位置顯示一個字符
//=====================================================================================
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
        Y &= 0x1;
        X &= 0xF; //限制X不能大于15,Y不能大于1
        if (Y) X |= 0x40; //當要顯示第二行時地址碼+0x40;
        X |= 0x80; //算出指令碼
        WriteCommandLCM(X, 0); //這里不檢測忙信號,發送地址碼
        WriteDataLCM(DData);
}
//=====================================================================================
//按指定位置顯示一串字符
//void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
//說明: x(0-15):x參數 y(0-1):y參數 DData(字符串):要顯示的內容(英文、數字、符號)
//=====================================================================================

void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
        unsigned char ListLength,j;
        ListLength = strlen(DData);
        Y &= 0x1;
        X &= 0xF; //限制X不能大于15,Y不能大于1
//========================================第8頁========================================
    if (X <= 0xF) //X坐標應小于0xF
    {  
                for(j=0;j<ListLength;j++)
        {
                DisplayOneChar(X, Y, DData[j]); //顯示單個字符
            X++;
        }
    }
}
//=====================================================================================
//顯示自定義字符
//void mychar(char xx,char yy,unsigned char *character,unsigned char saveto)
//說明:xx(0-15):為x參數.yy(0-1):y參數.character:要顯示的字符的列表地址,在程序前面有定義
//saveto(1-7)為字符保存的RAM,每屏最多顯示7個自定義字符
//(0x00-0x0h是自定義字符)
//=====================================================================================
void mychar(char xx,char yy,unsigned char *character,unsigned char saveto)
{
        unsigned char add = (saveto<<3) | 0x40;
        unsigned char t;      //臨時變量,每一行的值
         
        t=*(character+0);
        WriteCommandLCM(add, 0);     //第1行
        WriteDataLCM(t);
        t=*(character+1);
        WriteCommandLCM(add+1, 0);     //第2行
        WriteDataLCM(t);
        t=*(character+2);
        WriteCommandLCM(add+2, 0);     //第3行
        WriteDataLCM(t);
        t=*(character+3);
        WriteCommandLCM(add+3, 0);     //第4行
        WriteDataLCM(t);
        t=*(character+4);
        WriteCommandLCM(add+4, 0);     //第5行
        //========================================第9頁========================================
        WriteDataLCM(t);
        t=*(character+5);
        WriteCommandLCM(add+5, 0);     //第6行
        WriteDataLCM(t);
        t=*(character+6);
        WriteCommandLCM(add+6, 0);     //第7行
        WriteDataLCM(t);
        t=*(character+7);
        WriteCommandLCM(add+7, 0);     //第8行
        WriteDataLCM(t);
         
        for(i = 0;i<8;i++)
        {
                   WriteCommandLCM(add+i, 0);  
                WriteDataLCM(*(character+i));
        }
        DisplayOneChar(xx,yy,saveto);    //顯示字符
}
//=====================================================================================
//主函數
//=====================================================================================
main()
{
        Delay400Ms();
    LCMInit();
        Delay400Ms();      //1602初始化
        while(1)
        {
                DisplayListChar(0,0,"This is ListChar");
                DisplayListChar(0,1,"!");
                for(j=0;j<30;j++)for(i=0;i<30000;i++);
                        WriteCommandLCM(0x01,1); //清屏
                Delay5Ms();
                DisplayListChar(0,0,"This is OneChar:");
                DisplayOneChar(0,1,0x4f);
                DisplayOneChar(1,1,0x6e);
                DisplayOneChar(2,1,0x65);
                //========================================第10頁========================================
                DisplayOneChar(3,1,0x21);
                for(j=0;j<30;j++)for(i=0;i<30000;i++);
                        WriteCommandLCM(0x01,1); //清屏
                Delay5Ms();
                DisplayListChar(0,0,"This is MyChar:");
                mychar(0,1, character0,1);
                mychar(1,1, character1,2);
                mychar(2,1, character2,3);
                for(j=0;j<30;j++)for(i=0;i<30000;i++);
                        WriteCommandLCM(0x01,1); //清屏
                Delay5Ms();
        }
}








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