?? lcd驅(qū)動(dòng)程序.c
字號(hào):
/*
LCD1602液晶屏驅(qū)動(dòng)模塊
1、可直接嵌入到項(xiàng)目中使用
2、晶振頻率:1M
3、如晶振提高低層驅(qū)動(dòng)延時(shí)要作相應(yīng)修改
AVR_AFA
www.iccavr.com
程序編寫過程中參照了peak的4線顯示程序
peak:AVR論壇技術(shù)版版主
*/
#include <iom16.h>
#define RS_BIT PD6 //RS接到PD6
#define RW_BIT PD5 //RW接到PD5
#define EN_BIT PD4 //EN接到PD4
#define LCD_CON_DDR DDRD
#define LCD_CON_PORT PORTD
#define LCD_DATA_DDR DDRA //PA為數(shù)據(jù)接口
#define LCD_DATA_PORT PORTA
#define LCD_DATA_PIN PINA
#define RS_CLR PORTD &= ~(1 << RS_BIT)
#define RS_SET PORTD |= (1 << RS_BIT)
#define RW_CLR PORTD &= ~(1 << RW_BIT)
#define RW_SET PORTD |= (1 << RW_BIT)
#define EN_CLR PORTD &= ~(1 << EN_BIT)
#define EN_SET PORTD |= (1 << EN_BIT)
/*延時(shí)函數(shù)*/
void delay_us(unsigned int n) {
if (n == 0) {
return ;
}
while (--n);
}
/*延時(shí)函數(shù)*/
void delay_ms(unsigned char i) {
unsigned char a, b;
for (a = 1; a < i; a++) {
for (b = 1; b; b++) {
;
}
}
}
/*顯示屏命令寫入函數(shù)*/
void LCD_write_com(unsigned char com) {
RS_CLR;
RW_CLR;
EN_SET;
LCD_DATA_PORT = com;
delay_us(5);
EN_CLR;
}
/*顯示屏命令寫入函數(shù)*/
void LCD_write_data(unsigned char data) {
RS_SET;
RW_CLR;
EN_SET;
LCD_DATA_PORT = data;
delay_us(5);
EN_CLR;
}
/*顯示屏清空顯示*/
void LCD_clear(void) {
LCD_write_com(0x01);
delay_ms(5);
}
/*顯示屏字符串寫入函數(shù)*/
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s) {
if (y == 0) {
LCD_write_com(0x80 + x);
}
else {
LCD_write_com(0xC0 + x);
}
while (*s) {
LCD_write_data( *s);
s ++;
}
}
/*顯示屏單字符寫入函數(shù)*/
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data) {
if (y == 0) {
LCD_write_com(0x80 + x);
}
else {
LCD_write_com(0xC0 + x);
}
LCD_write_data( data);
}
/*顯示屏初始化函數(shù)*/
void LCD_init(void) {
LCD_DATA_DDR = 0xFF; /*I/O口方向設(shè)置*/
LCD_CON_DDR |= (1 <<EN_BIT) | (1 << RW_BIT) | (1 << RS_BIT);
LCD_write_com(0x38); /*顯示模式設(shè)置*/
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
LCD_write_com(0x08); /*顯示關(guān)閉*/
LCD_write_com(0x01); /*顯示清屏*/
LCD_write_com(0x06); /*顯示光標(biāo)移動(dòng)設(shè)置*/
delay_ms(5);
LCD_write_com(0x0C); /*顯示開及光標(biāo)設(shè)置*/
}
void main()
{
LCD_init();
LCD_write_str(0,0,"chenxiaOTAO");
while(1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -