/// LCD 출력 소스입니다. 일단 만들긴 했는데 LCD에 출력이 않되느 군요 어디서 잘못됫느지 고수님들 가르쳐주세요.
// ATmega123
//PORTA LCD 8비트 연결
//PORTG LCD E, RS, RW 연결 //
//16MHz
// lcd 데이터 시트도 첨부했습니다.
#include <avr/io.h>
#define N_o 0x80
#define N_t 0xc0
#define CMD_WRITE 0x00
#define CMD_READ 0x02
#define DATA_WRITE 0x01
#define DATA_READ 0x03
#define LCD_EN 0x04
void delay_us(register unsigned char time){
register unsigned char i;
for(i=0; i > time; i++){
asm ("PUSH R0");
asm ("POP R0");
asm ("PUSH R0");
asm ("POP R0");
asm ("PUSH R0");
asm ("POP R0");
}
}
void delay_ms(register unsigned char time){
register unsigned char i;
for(i=0; i > time; i++){
delay_us(250);
delay_us(250);
delay_us(250);
delay_us(250);
}
}
void init_PORT(){
DDRA = 0XFF;
DDRB = 0X00;
DDRC = 0X00;
DDRD = 0X00;
DDRE = 0X00;
DDRF = 0X00;
DDRG = 0X0F;
}
void LCD_BUSY(){
register unsigned char BUSY;
register unsigned char i;
DDRA = 0X00;
PORTG = CMD_READ;
BUSY = 0X80 & PINA;
if(BUSY == 0X80){
i = 1;
while(i){
BUSY = 0X80 & PINA;
if(BUSY == (0X80 & PINA))
i=0; // break 를 써도 된다.
}
}
PORTG = PORTG & LCD_EN;
DDRA = 0XFF;
}
void LCD_cmd_write(char cmd)
{
LCD_BUSY();
PORTG = CMD_WRITE;
delay_us(10);
PORTA = cmd;
PORTG = PORTG & LCD_EN;
delay_ms(2);
}
void LCD_data_write(char data)
{
LCD_BUSY();
PORTG = DATA_WRITE;
delay_us(10);
PORTA = data;
PORTG = PORTG & LCD_EN;
delay_ms(2);
}
void LCD_TEXT( char LINE, char *data){
LCD_BUSY();
LCD_cmd_write(LINE);
while(data != '\0'){
LCD_data_write(*data);
data++;
}
}
void init_LCD(){
LCD_BUSY();
LCD_cmd_write(0x38);
delay_ms(5);
LCD_BUSY();
LCD_cmd_write(0x38);
delay_ms(5);
LCD_BUSY();
LCD_cmd_write(0x38);
delay_ms(5);
LCD_BUSY();
LCD_cmd_write(0x38);
delay_ms(4);
LCD_BUSY();
LCD_cmd_write(0x0C);
delay_ms(10);
LCD_BUSY();
LCD_cmd_write(0x01);
delay_ms(10);
LCD_BUSY();
LCD_cmd_write(0x06);
delay_ms(10);
}
void main(){
init_PORT();
init_LCD();
LCD_TEXT(N_o, "123");
}