新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 自制51單片機常用頭文件(st7920并行方式)

自制51單片機常用頭文件(st7920并行方式)

作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
/*--------------------------------------------------------------------------

ST7920.H

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

The user function is C51.
Copyright (c) 1988-2004 Keil Elektronik GmbH sum zhaojun
All rights reserved.
--------------------------------------------------------------------------*/
// 并行方式
#ifndef __ST7920_H__
#define __ST7920_H__

#define uchar unsigned char
#define uint unsigned int

sbit LCD_RS = P3^2; // 指令/數(shù)據(jù)選擇
sbit LCD_RW = P3^3; // 并行讀寫選擇信號
sbit LCD_EN = P3^4; // 并行使能信號
sbit LCD_PSB = P3^5; // 并/串選擇端口:H - 并行;L - 串行
sbit LCD_RES = P3^6;// LCD復位,LCD模塊自帶復位電路??刹唤?/p>

#define LCD_DATA P1 // MCU P1<------>LCM
/*****************************************************
函 數(shù) 名:void Delay_LCD(void)
功 能:5ms延時
入口參數(shù):無
返 回 值:無
****************************************************/
void Delay_LCD(uint t)
{
uint i,j;

for (i=0; i{
for (j=0; j<10; j++)
{
;
}
}
}
/*****************************************************
函 數(shù) 名:void WriteCommandLCM()
功 能:向LCM中寫入指令
入口參數(shù):WCLCM
返 回 值:無
****************************************************/
void WriteCommandLCM(uchar WCLCM)
{
LCD_RS = 0; // 選擇寫入指令
LCD_RW = 0; // 寫入
LCD_EN = 1; // 使能

LCD_DATA = WCLCM; // 寫入指令
LCD_EN = 0;
Delay_LCD(5);
}
/*****************************************************
函 數(shù) 名:void WriteDataLCM()
功 能:向LCM1602中寫入數(shù)據(jù)
說 明:將形參WDLCM中的數(shù)據(jù)寫入LCM中
入口參數(shù):WDLCM
返 回 值:無
*****************************************************/
void WriteDataLCM(uchar WDLCM)
{
LCD_RS = 1; // 選擇寫入數(shù)據(jù)
LCD_RW = 0; // 寫入
LCD_EN = 1; //

LCD_DATA = WDLCM; // 寫入數(shù)據(jù)
LCD_EN = 0;
Delay_LCD(5);
}
/*****************************************************
函 數(shù) 名:void LCMInit()
功 能:初始化LCM
說 明:LCM在工作前先要對顯示屏初始化,否則模塊無法正常工作
入口參數(shù):無
返 回 值:無
*****************************************************/
void LCMInit(void)
{
Delay_LCD(20);
LCD_PSB = 1; // 選擇并行傳輸方式
Delay_LCD(20);

LCD_RES = 0; // 復位,可不要
Delay_LCD(1);
LCD_RES = 1;

WriteCommandLCM(0x30); // 選擇基本指令集
Delay_LCD(10);
WriteCommandLCM(0x0c); // 開顯示(無游標、反白)
Delay_LCD(10);
WriteCommandLCM(0x01); // 清顯示并設地址指針為00H
Delay_LCD(50);
}
/*****************************************************
函 數(shù) 名:void DisplayListChar()
功 能:向指點的地址寫入字符串
入口參數(shù):x-橫坐標,y-縱坐標,s-字符串
返 回 值:無
*****************************************************/
void DisplayListChar(uchar x, uchar y, uchar code *s)
{
uchar add; // 顯示地址

switch (y) // 顯示地址計數(shù)
{
case 0: add = x + 0x80; break; // 第一行的地址
case 1: add = x + 0x90; break; // 第二行的地址
case 2: add = x + 0x88; break; // 第三行的地址
case 3: add = x + 0x98; break; // 第四行的地址
default: break;
}

WriteCommandLCM(0x30); // 基本指令
WriteCommandLCM(add); // 寫入地址

while (*s > 0) // 寫入字符串
{
WriteDataLCM(*s);
s++;
Delay_LCD(50);
}
}

/*****************************************************
函 數(shù) 名:void DisplayPicture()
功 能:寫入一幅128x64的圖片
入口參數(shù):img - 圖片數(shù)組名
返 回 值:無
*****************************************************/
//顯示圖片(圖片為公司名稱)
void DisplayPicture(uchar code *img)
{
uint j = 0;
uchar x,y;
// -------------- 上半屏 ----------------
for (y=0; y<32; y++) // 垂直坐標32位
{
for (x=0; x<8; x++) // 水平坐標16字節(jié)
{
WriteCommandLCM(0x36); // 擴展指令
WriteCommandLCM(y+0x80); // 先寫入垂直坐標
WriteCommandLCM(x+0x80); // 再寫入水平坐標

WriteCommandLCM(0x30); // 基本指令
WriteDataLCM(img[j++]); // 連續(xù)寫入16位數(shù)據(jù)
WriteDataLCM(img[j++]);
}
}
// --------------- 下半屏 ---------------
j = 512; // 下半屏起始數(shù)據(jù)

for (y=0; y<32; y++) // 垂直坐標32位
{
for (x=0; x<8; x++) // 水平坐標16字節(jié)
{
WriteCommandLCM(0x36); // 擴展指令
WriteCommandLCM(y+0x80); // 先寫入垂直坐標
WriteCommandLCM(x+0x88); // 再寫入水平坐標

WriteCommandLCM(0x30); // 基本指令
WriteDataLCM(img[j++]); // 連續(xù)寫入16位數(shù)據(jù)
WriteDataLCM(img[j++]);
}
}
}

#endif



評論


技術專區(qū)

關閉