新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 串行1602的四位數(shù)據(jù)線程序-avr單片機(jī)

串行1602的四位數(shù)據(jù)線程序-avr單片機(jī)

作者: 時間:2016-11-30 來源:網(wǎng)絡(luò) 收藏

Command_Temp=Command_Temp << 4;
Data_Temp=Data_Temp << 4;

LCD_DATA_PORT &= 0X0F; //數(shù)據(jù)口清零
if (Command==0) //再送低4位
{
LCD_DATA_PORT |= Data_Temp&0xf0;
}
else
{
LCD_DATA_PORT |= Command_Temp&0xf0;
}

Write_Enable();
}

本文引用地址:http://butianyuan.cn/article/201611/323784.htm


/***********LCD模塊初始化**************/
void LCD_Init(void)
{
Delay_nms(5);

LCD_Write_Char(0x28,0); //4位數(shù)據(jù)線格式
Delay_nus(10);
LCD_Write_Char(0x0d,0); //顯示開,光標(biāo)閃爍
Delay_nus(10);
LCD_Write_Char(0x01,0); //清屏
Delay_nms(1);
LCD_Write_Char(0x06,0); //光標(biāo)模式設(shè)置
}

/*-----------------------------------------------------------------------
* Locate : 設(shè)置LCD顯示的起始位置
*
* 輸入?yún)?shù):x、y : 顯示字符串的位置,X:0-1,Y:0-15
* LCD第一行顯示寄存器地址:0X80-0X8F
* LCD第一行顯示寄存器地址:0XC0-0XCF
-----------------------------------------------------------------------*/
void Locate( unsigned char x, unsigned char y )
{
unsigned char Address;
if (x == 0)
Address = 0x80 + y; //第一行顯示的地址
else
Address = 0xc0 + y; //第二行顯示的地址
LCD_Write_Char(Address,0);
}


/*-----------------------------------------------------------------------
* LCD_Write_String : 英文字符串顯示函數(shù)
*
* 輸入?yún)?shù):*s :英文字符串指針
* X、Y :顯示字符串的位置
-----------------------------------------------------------------------*/
void LCD_Write_String(unsigned char X,unsigned char Y,unsigned char *String)
{
Locate( X, Y); //先送顯示起始坐標(biāo)

while (*String) //再依次送顯示字符
{
LCD_Write_Char( 0, *String );
String ++;
}

}


/*-----------------------------------------------------------------------
* DEC_Num_Disp :10進(jìn)制數(shù)值顯示函數(shù)
*
* 輸入?yún)?shù) :X 字符起始顯示行坐標(biāo)2
* Y 字符起始顯示列坐標(biāo)
* Num 需要顯示的數(shù)值(最長8位)
* Bit 有效顯示的位數(shù)
* 輸出 :
-----------------------------------------------------------------------*/
void DEC_Num_Disp(unsigned char X,unsigned char Y,unsignedlongNum,char Bit)
{
unsigned char i = 0;
Locate( X, Y );
for (i=0 ; i {
LCD_Buff[i] = CHR[Num%10];
Num = Num/10;
}
for (i=0 ; i {
LCD_Write_Char(0,LCD_Buff[Bit-i-1]); //先寫高位再寫低位
}
}


/*-----------------------------------------------------------------------
* HEX_Num_Disp :16進(jìn)制數(shù)值顯示函數(shù)
*
* 輸入?yún)?shù) :X 字符起始顯示行坐標(biāo)
* Y 字符起始顯示列坐標(biāo)
* Num 需要顯示的數(shù)值(最長8位)
* Bit 有效顯示的位數(shù)
* 輸出 :
-----------------------------------------------------------------------*/
void HEX_Num_Disp(unsigned char X,unsigned char Y,unsignedlongNum,char Bit)
{
char a = 0;
Locate( X, Y );
for(a=8-Bit ; a<8 ; a++)
{
LCD_Write_Char(0,CHR[(Num<< (a << 2)) >>28]);
}
}


1602測試程序LCD.c


/*********************************************
* "1602Driver.h"庫測試程序
*********************************************/


#include
#include "1602Driver.h"

void Port_Init(void)
{
DDRD = 0xff;
DDRC = 0xff;
}
void main (void)
{
int counter;
OSCCAL="0XA5";
Port_Init();
LCD_Init();
LCD_Write_Char(0x01,0); //清屏

HEX_Num_Disp(0,0,13,1);
DEC_Num_Disp(0,1,4,1);
//LCD_Write_String(2,0,"T");
LCD_Write_String(1,0,"Disp");


while(1);
}


上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉