AVR을 이용한 CLCD 출력
PORTA.7~4 – data_bit , PORTA.3 – not used
PORTA.2 – Enable, PORTA.1 – RW, PORTA.0 – RS
* Processor: ATmega128, Compiler: WinAVR, Simulation: AVR Simulator IDE
[code]
#include<avr/io.h>
#include<util/delay.h>
// PORTA SET
#define DDR_LCD DDRA
#define PORT_LCD PORTA
#define ENABLE (PORT_LCD |= 0x04) // LCD enable
#define DISABLE (PORT_LCD &= 0xFB)// LCD disable
#define RS_H (PORT_LCD |= 0x01) // RS=1
#define RS_L (PORT_LCD &= 0xFE) // RS=0
#define RW_H (PORT_LCD |= 0x02) // RW=1
#define RW_L (PORT_LCD &= 0xFD) // RW=0
void instruction_out(unsigned char b) //명령어 쓰기 함수
{
PORT_LCD=b&0xF0; //상위 4BIT 출력
RS_L;RW_L; //RS=0,RW=0
ENABLE; //E=1
_delay_us(1);
DISABLE; //E=0
PORT_LCD=(b<<4)&0xF0; //하위 4BIT 출력
RS_L;RW_L; //RS=0,RW=0
ENABLE; //E=1
_delay_us(1);
DISABLE; //E=0
}
void char_out(unsigned char b) //LCD에 한문자 출력 함수
{
_delay_us(100);
PORT_LCD=(b&0xF0); //상위 4BIT 출력
RS_H;RW_L; //RS=1,RW=0
ENABLE; //E=1
_delay_us(1);
DISABLE; //E=0
PORT_LCD=((b<<4)&0xF0); //하위 4BIT 출력
RS_H;RW_L; //RS=1,RW=0
ENABLE; //E=1
_delay_us(1);
DISABLE; //E=0
}
void string_out(unsigned char b, char *str) //문자열 출력 함수
{
unsigned int i=0;
instruction_out(b); //LCD 위치 지정
do{
char_out(str[i]);
}while(str[++i]!=’\0′); //NULL 문자를 만날 때 까지
_delay_ms(1);
}
void init_LCD(void) //LCD초기화
{
DDR_LCD = 0xFF; //PORTA 출력
PORT_LCD=0x00; //초기 값
_delay_ms(40); //Initial wating time
//Function Set
instruction_out(0x28);
_delay_us(50);
//Display On/Off Control
instruction_out(0x0C); //LCD DISPLAY ON, CURSOR OFF, BLINK OFF
_delay_us(50);
//Display Clear
instruction_out(0x01); //LCD CLEAR
_delay_ms(2);
//Entry mode Set
instruction_out(0x06);
_delay_us(50);
}
int main(void)
{
char string1[16]= “D.Blog-downrg.”;
char string2[16]= “123456789ABCDEFG”;
init_LCD(); // LCD Initialize
string_out(0x80, string1); // 출력문자열
string_out(0xc0, string2);
while(1);
return 0;
}[/code]