#include<avr/io.h>

#define F_CPU 16000000

#include<util/delay.h>

#define LCD_CONTROL  PORTG
#define LCD_DATABUS  PORTC
 
#define minwoo while

void LCD_cmd(unsigned char cmd){

 LCD_CONTROL = 0x00; // E = 0, RS = 0
 _delay_ms(2);
 LCD_DATABUS = cmd;
 LCD_CONTROL = 0x02; // E = 1, Rs = 0
 _delay_us(10);
 LCD_CONTROL = 0x00; // E = 0,Rs = 0
 _delay_us(50);
}

void LCD_data(unsigned char data){

 LCD_CONTROL = 0x01; // E = 0, Rs = 1
 LCD_DATABUS = data;
 LCD_CONTROL = 0x03; // E = 1, Rs = 1
 _delay_us(10);
 LCD_CONTROL = 0x01; // E = 0, RS = 1
 _delay_us(50);
}
 
void LCD_str(unsigned char cmd, char *str){

 LCD_cmd(cmd);
 while(*str!='\0')
  LCD_data(*(str++));
}
 
void LCD_init(void){

 DDRC = 0xFF; 
  DDRG = 0xFF;


 LCD_cmd(0x38);
 LCD_cmd(0x0C);
 LCD_cmd(0x06);
 LCD_cmd(0x01); // cls
 _delay_ms(2);
}


void Putch(char);
char Getch(void);

int main(void){

 UCSR0A = 0;
 UCSR0B |= (1<<RXEN0) | (1<<TXEN0);
 UCSR0C |= (1<<UCSZ01) | (1 <<UCSZ00);
 UBRR0H = 0;
 UBRR0L = 103;
 
 LCD_init();

 minwoo(1){
  Putch(Getch());
 }

}

void Putch(char data){

 while(!(UCSR0A & (1<<UDRE0)));
 UDR0 = data;

 char DATA[2] = {data, '\0'};
 LCD_str(0x80, DATA);
}

char Getch(void){

 while(!(UCSR0A & (1<<RXC0)));
 return UDR0;
}

'OpenSTUDY > AVR' 카테고리의 다른 글

UART  (0) 2011.10.15
직렬통신  (0) 2011.10.15
USART - 아스키 & 헥사  (0) 2011.10.09
USART  (0) 2011.10.07
CISC & RISC  (0) 2011.10.02

+ Recent posts