標(biāo)題: LCD1602字母流動(dòng)顯示 [打印本頁(yè)]

作者: 1679911655    時(shí)間: 2018-3-27 21:52
標(biāo)題: LCD1602字母流動(dòng)顯示
基于51單片機(jī)的LCD1602字母流動(dòng)顯示
C程序源碼:
#include"lcd.h"
/*******************************************************************************
* 函 數(shù) 名         : Lcd1602_Delay1ms
* 函數(shù)功能     : 延時(shí)函數(shù),延時(shí)1ms
* 輸    入         : c
* 輸    出         : 無(wú)
* 說(shuō)    名         : 該函數(shù)是在12MHZ晶振下,12分頻單片機(jī)的延時(shí)。
*******************************************************************************/
void Lcd1602_Delay1ms(uint c)   //誤差 0us
{
    uchar a,b;
for (; c>0; c--)
{
   for (b=199;b>0;b--)
   {
     for(a=1;a>0;a--);
   }      
}
     
}
/*******************************************************************************
* 函 數(shù) 名         : LcdWriteCom
* 函數(shù)功能     : 向LCD寫(xiě)入一個(gè)字節(jié)的命令
* 輸    入         : com
* 輸    出         : 無(wú)
*******************************************************************************/
#ifndef  LCD1602_4PINS  //當(dāng)沒(méi)有定義這個(gè)LCD1602_4PINS時(shí)
void LcdWriteCom(uchar com)   //寫(xiě)入命令
{
LCD1602_E = 0;     //使能
LCD1602_RS = 0;    //選擇發(fā)送命令
LCD1602_RW = 0;    //選擇寫(xiě)入

LCD1602_DATAPINS = com;     //放入命令
Lcd1602_Delay1ms(1);  //等待數(shù)據(jù)穩(wěn)定
LCD1602_E = 1;           //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);   //保持時(shí)間
LCD1602_E = 0;
}
#else
void LcdWriteCom(uchar com)   //寫(xiě)入命令
{
LCD1602_E = 0;  //使能清零
LCD1602_RS = 0;  //選擇寫(xiě)入命令
LCD1602_RW = 0;  //選擇寫(xiě)入
LCD1602_DATAPINS = com; //由于4位的接線是接到P0口的高四位,所以傳送高四位不用改
Lcd1602_Delay1ms(1);
LCD1602_E = 1;  //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
// Lcd1602_Delay1ms(1);
LCD1602_DATAPINS = com << 4; //發(fā)送低四位
Lcd1602_Delay1ms(1);
LCD1602_E = 1;  //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* 函 數(shù) 名         : LcdWriteData
* 函數(shù)功能     : 向LCD寫(xiě)入一個(gè)字節(jié)的數(shù)據(jù)
* 輸    入         : dat
* 輸    出         : 無(wú)
*******************************************************************************/     
#ifndef  LCD1602_4PINS     
void LcdWriteData(uchar dat)   //寫(xiě)入數(shù)據(jù)
{
LCD1602_E = 0; //使能清零
LCD1602_RS = 1; //選擇輸入數(shù)據(jù)
LCD1602_RW = 0; //選擇寫(xiě)入
LCD1602_DATAPINS = dat; //寫(xiě)入數(shù)據(jù)
Lcd1602_Delay1ms(1);
LCD1602_E = 1;   //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);   //保持時(shí)間
LCD1602_E = 0;
}
#else
void LcdWriteData(uchar dat)   //寫(xiě)入數(shù)據(jù)
{
LCD1602_E = 0;   //使能清零
LCD1602_RS = 1;   //選擇寫(xiě)入數(shù)據(jù)
LCD1602_RW = 0;   //選擇寫(xiě)入
LCD1602_DATAPINS = dat; //由于4位的接線是接到P0口的高四位,所以傳送高四位不用改
Lcd1602_Delay1ms(1);
LCD1602_E = 1;   //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
LCD1602_DATAPINS = dat << 4; //寫(xiě)入低四位
Lcd1602_Delay1ms(1);
LCD1602_E = 1;   //寫(xiě)入時(shí)序
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
#endif
/*******************************************************************************
* 函 數(shù) 名       : LcdInit()
* 函數(shù)功能   : 初始化LCD屏
* 輸    入       : 無(wú)
* 輸    出       : 無(wú)
*******************************************************************************/     
#ifndef  LCD1602_4PINS
void LcdInit()        //LCD初始化子程序
{
  LcdWriteCom(0x38);  //開(kāi)顯示
LcdWriteCom(0x0c);  //開(kāi)顯示不顯示光標(biāo)
LcdWriteCom(0x06);  //寫(xiě)一個(gè)指針加1
LcdWriteCom(0x01);  //清屏
LcdWriteCom(0x80);  //設(shè)置數(shù)據(jù)指針起點(diǎn)
}
#else
void LcdInit()        //LCD初始化子程序
{
LcdWriteCom(0x32);  //將8位總線轉(zhuǎn)為4位總線
LcdWriteCom(0x28);  //在四位線下的初始化
LcdWriteCom(0x0c);  //開(kāi)顯示不顯示光標(biāo)
LcdWriteCom(0x06);  //寫(xiě)一個(gè)指針加1
LcdWriteCom(0x01);  //清屏
LcdWriteCom(0x80);  //設(shè)置數(shù)據(jù)指針起點(diǎn)
}
#endif







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