?? lcd.c
字號(hào):
/******************************************************************************/
/**
/** 模 塊 名: -------------------Virtual_UART.C-----------------------------
/** -----------------虛擬串口調(diào)試------------------------------*/
/** 功能描述:
/**
/** 創(chuàng) 建 人: huangtiexiong 日期:2006-11-28 */
/** 修 改 人: 日期:2006-11-28 */
/** 其他說(shuō)明:
/******************************************************************************/
#include "Includes.h"
/*************************************************
模塊級(jí)變量申明
*************************************************/
static void LCD_WriteDat(int8u lcd_dat);
static void LCD_WriteCmd(int8u lcd_cmd);
static int8u LCD_ReadStatus(void);
static void LCD_Goto(int8u x,int8u y);
/*******************************************************************************
*** 函 數(shù) 名: void main(void)
*** 功能描述:
*** 全局變量:
*** 輸 入:
*** 輸 出:
*** 創(chuàng) 建 人:huangtiexiong 日期:2006-11-28
*** 修 改 人: 日期:2006-11-28
*** 函數(shù)說(shuō)明:
/******************************************************************************/
extern void LCD_Init(void)
{
Delay20ms();
LCD_WriteCmd(0x38); //功能設(shè)置:8位機(jī)接口、雙行顯示、5×7字符點(diǎn)陣;
LCD_WriteCmd(0x0c); //顯示控制:光標(biāo)開(kāi)啟、字符不閃爍;
LCD_WriteCmd(0x01); //清屏;
LCD_WriteCmd(0x06); //訪問(wèn)模式:光標(biāo)右移一位、整屏不移動(dòng);
LCD_Goto(0,0);
}
static void LCD_WriteDat(int8u lcd_dat)
{
int8u tmp;
tmp = LCD_ReadStatus(); //讀狀態(tài);
while((tmp & 0x80)) //是否忙 ?
{
tmp = LCD_ReadStatus();
}
#if 0
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 1;
_nop_();
_nop_();
LCD_DATA = lcd_dat;
_nop_();
_nop_();
LCD_EN = 0;
#endif
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = lcd_dat;
_nop_();
LCD_EN = 0;
_nop_();
_nop_();
LCD_EN = 1;
}
static void LCD_WriteCmd(int8u lcd_cmd)
{
int8u tmp;
tmp = LCD_ReadStatus();
while((tmp & 0x80))
{
tmp = LCD_ReadStatus();
}
#if 0
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
_nop_();
_nop_();
LCD_DATA = lcd_cmd;
_nop_();
_nop_();
LCD_EN = 0;
#endif
LCD_RS = 0;
LCD_RW = 0;
LCD_DATA = lcd_cmd;
_nop_();
LCD_EN = 0;
_nop_();
_nop_();
LCD_EN = 1;
}
static int8u LCD_ReadStatus(void)
{
int8u tmp;
#if 0
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
tmp = LCD_DATA;
LCD_EN = 0;
#endif
LCD_DATA = 0xff;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 0;
_nop_();
_nop_();
LCD_EN = 1;
tmp = LCD_DATA;
return tmp;
}
static void LCD_Goto(int8u x,int8u y)
{
int8u tmp;
if(y) //若是第二行;
{
tmp = 0xc0 + x;
LCD_WriteCmd(tmp);
}
else
{
tmp = 0x80 + x;
LCD_WriteCmd(tmp);
}
}
#if 0
extern void LCD_DisplayShiftR(void) //整屏右移;
{
LCD_WriteCmd(0x1f);
}
extern void LCD_DisplayShiftL(void) //整屏左移;
{
LCD_WriteCmd(0x18);
}
#endif
extern void LCD_Display(int8u row,int8u *str)
{
if(row)
{
LCD_Goto(0,1);
}
else
{
LCD_Goto(0,0);
}
while(*str != '\0')
{
LCD_WriteDat(*str++);
}
}
#if 0
extern void LCD_Display(int8u x,int8u y,int8u disp_dat)
{
LCD_Goto(x,y);
LCD_WriteDat(disp_dat);
}
#endif
#if 0
extern void LCD_Display(int8u disp_dat)
{
int8u tmp;
tmp = LCD_ReadStatus();
tmp &= 0x7f;
if(tmp == 0x10) //第一行顯示滿則轉(zhuǎn)向第二行;
{
LCD_Goto(0,1);
}
if(tmp == 0x50) //全屏顯示滿則清屏;
{
LCD_WriteCmd(0x01);
}
LCD_WriteDat(disp_dat); //將接收字符顯示在LCD屏上;
}
#endif
extern void Delay20ms() //粗略延時(shí);
{
int16u tmp = 50000;
while(tmp--);
}
/*******************************************************************************
**** End Of File
*******************************************************************************/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -