資源簡介
#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);
}
//毫秒級延時程序晶振8MHZ
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(1000);
time--;
}
}
/*顯示屏命令寫入函數*/
void LCD_write_com(unsigned char com)
{
RS_0;
RW_0;
PORTB = com;
EN_1;
delay_us(20);
EN_0;
}
/*顯示屏命令寫入函數*/
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);
}
/*顯示屏字符串寫入函數*/
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 ++;
}
}
/*顯示屏單字符寫入函數*/
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);
}
/*顯示屏初始化函數*/
void LCD_init(void) {
DDRB = 0xFF; /*I/O口方向設置*/
DDRD |= (1 << PD3) | (1 << PD4) | (1 << PD6);
LCD_write_com(0x38); /*顯示模式設置*/
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); /*顯示關閉*/
LCD_write_com(0x01); /*顯示清屏*/
LCD_write_com(0x06); /*顯示光標移動設置*/
delay_ms(5);

代碼片段和文件信息
- 上一篇:微信小程序地圖demo
- 下一篇:51實現倒計時器帶原理圖和匯編程序
評論
共有 條評論