참고사이트
http://gongnoob.blog.me/133468759
이렇게 참고 했는데..
음... 왜 안되지...;;??
=========================================================================수정
음? USBISP 케이블을 한번 뺐다가 끼니까 되넹...? 엥? ㅋㅋ;;
=======================================================================코드
/*
PA.0 = RS
PA.1 = RW
PA.2 = E1
PA.4 = D4
PA.5 = D5
PA.6 = D6
PA.7 = D7
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/delay.h>
#define RS_H (PORTA |= 0x01) // RS=1
#define RS_L (PORTA &= 0xFE) // RS=0
#define RW_H (PORTA |= 0x02) // RW=1
#define RW_L (PORTA &= 0xFD) // RW=0
#define ENABLE (PORTA |= 0x04) // ENABLE
#define DISABLE (PORTA &= 0xFB) // DISABLE
void LCD_command(char command){
PORTA = (command&0xF0); // send High nibble
RS_L; RW_L; // RS=0 RW=0
ENABLE; // E1 : L->H
_delay_us(1);
DISABLE; // E1 : H->L
PORTA = (command & 0x0F)<<4; // send Low nibble
RS_L; RW_L; // RS=0 RW=0
ENABLE; // E1 : L->H
_delay_us(1);
DISABLE; // E1 : H->L
}
void LCD_data(char data){
_delay_us(100);
PORTA = (data&0xF0); // send High nibble
RS_H; RW_L; // RS=1 RW=0
ENABLE; // E1 : L->H
_delay_us(1);
DISABLE; // E1 : H->L
PORTA = (data&0x0F)<<4; // send Low nibble
RS_H; RW_L; // RS=1 RW=0
ENABLE; // E1 : L->H
_delay_us(1);
DISABLE; // E1 : H->L
}
void LCD_init(void){
DDRA = 0xFF;
PORTA = 0x00;
_delay_ms(40);
LCD_command(0x28); // DL=0(4bit) N=1(2Line) F=0(5x7)
_delay_us(50);
LCD_command(0x0C); // LCD ON, Cursor X, Blink X
_delay_us(50);
LCD_command(0x01); // LCD Clear
_delay_ms(2);
LCD_command(0x06); // Entry Mode
_delay_us(50);
}
void LCD_string(char command, char *string){
LCD_command(command);
while(*string != '\0'){
LCD_data(*string);
string++;
}
}
int main(void){
char string1[16] = "Hello World!";
char string2[16] = "Good Job!";
LCD_init();
while(1){
LCD_string(0x80+0x00, string1);
_delay_ms(2000);
LCD_command(0x01); // LCD Clear
_delay_ms(2);
LCD_string(0x80+0x40, string2);
_delay_ms(2000);
LCD_command(0x01); // LCD Clear
_delay_ms(2);
}
return 0;
}