📄 162.c
字号:
#include <io8515v.h>
#include <macros.h>
#include <162-1302.h>
void delay_ms(unsigned char n)
{
unsigned char a, b;
for (a = 1; a<n; a++)
for (b = 1; b; b++)
;
}
void delay_us(unsigned int n)
{
unsigned char b;
for (b = 1; b<n; b++)
;
}
void LCD_wait(void) //等待LCD空闲
{
LCD_DATA_PORT&=~BIT(7);
PORTB&=~BIT(0);
PORTB|=BIT(1);
PORTB|=BIT(2);
while(!(LCD_DATA_PIN &0x80)==0);
LCD_DATA_DDR|=0xFF;
PORTB&=~BIT(2);
}
void command_enable() //写指令使能
{
PORTB&=~(BIT(0)|BIT(1));
PORTB|=BIT(2);
asm("nop");
PORTB&=~BIT(2);
}
void data_enable() //写数据使能
{
PORTB|=BIT(0);
PORTB&=~BIT(1);
PORTB|=BIT(2);
asm("nop");
PORTB&=~BIT(2);
}
/*设置LCD显示的起始位置输入参数:x、y
显示字符串的位置,X:0-15,Y:0-1
LCD第一行显示寄存器地址:0X80-0X8F
LCD第一行显示寄存器地址:0XC0-0XCF*/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y==0)
address=0x80+x;
else
address=0xC0+x;
LCD_DATA_PORT=address; //输入开始显示地址
command_enable();
delay_ms(10);
}
//写一个字符
void LCD_write_char(unsigned char data)
{
LCD_DATA_PORT=data;
data_enable();
delay_ms(10);
}
//写一字符串
void LCD_write_string(unsigned char x, unsigned char y,unsigned char *s)
{
LCD_set_xy(x,y);
while(*s)
{
LCD_write_char(*s);
s++;
}
}
void init_lcd() //初始化
{
delay_ms(180); //等待30ms以上
LCD_DATA_PORT=0x38; //8位2行5×7点阵
command_enable();
delay_us(100); //等待39us以上
LCD_DATA_PORT=0x0C; //显示器开、光标开、闪烁关
command_enable();
delay_us(100); //等待39us以上
LCD_DATA_PORT=0x01; //清屏
command_enable();
delay_ms(10); //等待1.53ms以上
LCD_DATA_PORT=0x06; //输入方式
command_enable();
delay_ms(180); //初始化完毕
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -