資源簡(jiǎn)介
#include
#include
#define RS_0 PORTD &= ~(1 << PD3)
#define RS_1 PORTD |= (1 << PD3)
#define RW_0 PORTD &= ~(1 << PD4)
#define RW_1 PORTD |= (1 << PD4)
#define EN_0 PORTD &= ~(1 << PD6)
#define EN_1 PORTD |= (1 <1);
}
//毫秒級(jí)延時(shí)程序晶振8MHZ
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(1000);
time--;
}
}
/*顯示屏命令寫(xiě)入函數(shù)*/
void LCD_write_com(unsigned char com)
{
RS_0;
RW_0;
PORTB = com;
EN_1;
delay_us(20);
EN_0;
}
/*顯示屏命令寫(xiě)入函數(shù)*/
void LCD_write_data(unsigned char data) {
RS_1;
RW_0;
PORTB = data;
EN_1;
delay_us(200);
EN_0;
}
/*顯示屏清空顯示*/
void LCD_clear(void) {
LCD_write_com(0x01);
delay_ms(5);
}
/*顯示屏字符串寫(xiě)入函數(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 ++;
}
}
/*顯示屏單字符寫(xiě)入函數(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) {
DDRB = 0xFF; /*I/O口方向設(shè)置*/
DDRD |= (1 << PD3) | (1 << PD4) | (1 << PD6);
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);

代碼片段和文件信息
評(píng)論
共有 條評(píng)論