📄 lcd_1602.h
字号:
#ifndef __LCD_1602_H_
#define __LCD_1602_H_
#include "system.h"
#define DELAY 1500
/***********************************************************/
/*DELAY set to delay time for LCD finishing its operation,*/
/*When CPU Frequancy is 50MHZ, DELAY set as 2000*/
/*When CPU Frequancy is other value, DELAY set as other value*/
/*For example,when CPU Frequancy is 100MHZ, DELAY set as 4000*/
/*************************************************************/
#define LCD_DATA *(unsigned int *)PIO_LCD_DATA_BASE
#define LCD_DATA_DIR *(unsigned int *)(PIO_LCD_DATA_BASE+4)
#define LCD_CTL *(unsigned int *)PIO_LCD_CTL_BASE
#define LCD_DATA_IN 0
#define LCD_DATA_OUT 0xFF
void writelcdinstruction(char instru)
{
int i;
for(i=DELAY;i>0;i--) ;
LCD_CTL = 0x4;
/*clr RS low */
/*clr R/w for write*/
/*Set enable*/
LCD_DATA_DIR = LCD_DATA_OUT;
LCD_DATA = instru;
for(i=DELAY;i>0;i--) ;
LCD_CTL = 0x00;
}
void initialcd()
{
writelcdinstruction((unsigned int)0x38); //initialcd
writelcdinstruction((unsigned int)0x0C); //initialcd
writelcdinstruction((unsigned int)0x06); //initialcd
writelcdinstruction((unsigned int)0x01); //Clean the LCD
}
void writelcddata(char lcddata)
{
int i;
for(i=DELAY;i>0;i--) ;
LCD_CTL = 0x6;
/*clr R/w for write*/
/*set RS */
/*Set enable*/
LCD_DATA_DIR = LCD_DATA_OUT;
LCD_DATA = lcddata;
for(i=DELAY;i>0;i--) ;
LCD_CTL = 0x2;
for(i=0;i<100;i++) ;
}
/* void cleanlcd()
{
writelcdinstruction((unsigned int)0x01);
}*/
/* void lcddisplay(unsigned int addr,unsigned int data)
{
writelcdinstruction(addr);
writelcddata(data);
}*/
/* void displayram(unsigned int *valpt)
{
int i;
unsigned int tempval;
unsigned int val;
val = *valpt;
for(i=8;i>0;i--){
tempval= val & 0xF0000000;
tempval >>= 28;
tempval &= 0x0000000F;
if(tempval>9) tempval+=0x37; //A~F
else tempval+=0x30; //0~9
writelcddata(tempval);
val <<= 4;
}
} */
void displaystring(char addr,char * str)
{
// char val;
writelcdinstruction(addr);
do {
// val= *str;
writelcddata(*str);
str++;}
while(*str!='\0');
}
/********************************/
#endif /* __LCD_1602_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -