?? lcd1602_14p.c
字號:
/*-------------------------------------------------------
LCD1602 Module
Donald
Apr 30, 2007
-------------------------------------------------------*/
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include "LCD1602_14P.h"
void LcdInit(){
DDRH = 0xff;
DDRE = 0xff;
LCDIO_DIR = LCDIO_DIR_OUT;
LcdDelay();
LcdCommand(CLR,0); //clear screen
LcdCommand(DATA_MODE,1); //set 8 bit data transmission mode
LcdCommand(INPUTMODE_CUR_R | INPUTMODE_ALL_D, 1); // cursor right, disable moving
LcdCommand(SCREEN_OPEN
| SCREEN_OPEN_CUR
| SCREEN_OPEN_TWI
, 1); //open display (enable lcd display)
LcdCommand(LINE1_HEAD,1); //set lcd first display address
LcdCommand(CLR,1); //clear screen
}
////////////////////////////////////////////////////////////////////
// write command function
//
void LcdCommand(unsigned char command,unsigned char BusyC){
if (BusyC) ReadStatus(); //Test it busy or not
LCDIO=command;
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=0;
LCD1602_EN=1;
}
unsigned char ReadStatus(void)
{
unsigned char cRtn;
LCDIO_DIR = LCDIO_DIR_IN;
LCD1602_RS = 0;
LCD1602_RW = 1;
LCD1602_EN = 0;
LCD1602_EN = 0;
LCD1602_EN = 1;
while (LCDIO & BUSY); //Test Busy State
cRtn = LCDIO_DIR; // if Not save the port value, it should be change
LCDIO_DIR = LCDIO_DIR_OUT;
return(cRtn);
}
void LcdDelay(void){
word i, j;
for (i = 0; i < 300; i++)
for(j = 0; j < 3000; j++);
}
////////////////////////////////////////////////////////////////////
// write data function
//
void LcdData(unsigned char dat,unsigned char BusyC)
{
if (BusyC) ReadStatus(); //Test it busy or not
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=0;
LCD1602_EN=1;
}
////////////////////////////////////////////////////////////////////
// write lcd a character function
//
void LcdWriteChar( unsigned char x,unsigned char y,unsigned char dat){
LcdSetXY(x, y);
LcdData(dat,1);
}
////////////////////////////////////////////////////////////////////
// set display address function
//
void LcdSetXY( unsigned char x, unsigned char y ){
unsigned char address;
if (y == LINE1)
address = LINE1_HEAD + x;
else
address = LINE2_HEAD + x;
LcdCommand(address,1);
}
////////////////////////////////////////////////////////////////////
// write lcd string function
//
void LcdWriteStr(unsigned char X,unsigned char Y,char *s)
{
LcdSetXY( X, Y ); //set address
while (*s) // write character
{
LcdData(*s, 1);
s++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -