ATmega128 16핀 LCD 8비트 인터페이스 제어 소스
2019. 7. 7. 22:18ㆍ임베디드/ATmega128
궁금한 점은 댓글로 남겨주시면 감사하겠습니다
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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_ */ |
'임베디드 > ATmega128' 카테고리의 다른 글
ATmega128 적외선 리모콘으로 수신기 제어하기 (1) | 2019.07.13 |
---|---|
ATmega128 I2C 1602 텍스트 LCD 코드 (5) | 2019.07.11 |
ATmega128 I2C 1602 텍스트 LCD 정리 (3) | 2019.07.06 |
AVR 스터디 [2019.06.30] (0) | 2019.06.30 |
ATS75 온도값 (0) | 2019.06.30 |