ATmega128 16핀 LCD 8비트 인터페이스 제어 소스

2019. 7. 7. 22:18임베디드/ATmega128

궁금한 점은 댓글로 남겨주시면 감사하겠습니다

 

#define F_CPU 16000000UL
#include "LCD.h"
#include <avr/io.h>
#include <util/delay.h>
void LCD_command(unsigned char command)
{
LCD_CONTROL &= ~((1<<EN) | (1<<RS) | (1<<RW));
_delay_us(1);
LCD_DATABUS = command;
LCD_CONTROL |= (1<<EN);
_delay_us(1);
LCD_CONTROL &= ~(1<<EN);
_delay_us(40);
}
void LCD_data(unsigned char data)
{
LCD_CONTROL &= ~((1<<EN) | (1<<RW));
LCD_CONTROL |= (1<<RS);
_delay_us(1);
LCD_DATABUS = data;
LCD_CONTROL |= (1<<EN);
_delay_us(1);
LCD_CONTROL &= ~(1<<EN);
_delay_us(40);
}
void LCD_string(unsigned char command, char* string)
{
LCD_command(command);
while(*string != '\0')
{
LCD_data(*string);
string++;
}
}
void LCD_init()
{
LCD_DATABUS_DDR = 0b11111111;
LCD_CONTROL_DDR |= ((1<<EN) | (1<<RS) | (1<<RW));
_delay_us(50);
LCD_CONTROL |= ((1<<EN) | (1<<RS));
_delay_us(50);
LCD_CONTROL &= ~(1<<EN);
_delay_us(50);
LCD_command(0x38);
LCD_command(0x0C);
LCD_command(0x06);
LCD_command(0x01);
_delay_ms(10);
}
view raw clcd8bit.c hosted with ❤ by GitHub
#ifndef LCD_H_
#define LCD_H_
#define LCD_DATABUS PORTC
#define LCD_CONTROL PORTA
#define LCD_DATABUS_DDR DDRC
#define LCD_CONTROL_DDR DDRA
#define RS 5
#define RW 6
#define EN 7
void LCD_command(unsigned char command);
void LCD_data(unsigned char data);
void LCD_string(unsigned char command, char* string);
void LCD_init();
#endif /* LCD_H_ */
view raw clcd8bit.h hosted with ❤ by GitHub