?? 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 + -