-
[AVR] 간단한 LCD 구동 코드 예제AVR study 2013. 1. 29. 18:38반응형
#include<avr/io.h>
#include<util/delay.h>#define RS 0
#define RW 1
#define E 2
#define DATA PORTA
#define LCD_CLEAR 0x1f
#define LCD_RTH 0x02
#define LCD_RSH 0x07
#define LCD_LSH 0x06
#define LCD_NOMAL 0x04
#define LCD_on 0x0c
#define LCD_off 0x08
#define LCD_8bit 0x30
#define LCD_ALLon 0x0e
#define LCD_5X8 0x38
//#define LCD_
unsigned char a[]="IHATEAVR";
unsigned char c[]="hellomysemina";void LCD_CR(unsigned char com)
{
PORTC&=~(1<<RS);
PORTC&=~(1<<RW);
PORTC|=(1<<E);
_delay_ms(50);
DATA=com;
_delay_ms(50);
PORTC&=~(1<<E);}
void LCD_DB(unsigned char com)
{
PORTC|=(1<<RS);
PORTC&=~(1<<RW);
PORTC|=(1<<E);
_delay_ms(10);
DATA=com;
//delay_ms();
PORTC&=~(1<<E);
}
void LCD_PST(unsigned char col, unsigned char row)
{
LCD_CR(0x80|(row+col*0x40));
}
void str(unsigned char* com)
{
while(*com!=0)
{
LCD_DB(*com);
com++;}
}
void init_buffer(void)
{PORTC|=(1<<RS);
PORTC|=(1<<RW);
PORTC|=(1<<E);
_delay_ms(10);
while(DATA!=0)
{
LCD_DB(0);
_delay_ms(10);
}
}
int main()
{
int b;
DDRA=0xff;
DDRC=0xff;
PORTA=0x00;
PORTB=0x00;
LCD_CR(0x30);
_delay_ms(2);
LCD_CR(0x38);
_delay_ms(2);
LCD_CR(0x0c);
//delay_ms(2);
LCD_CR(0x14);
_delay_ms(2);
LCD_CR(0x06);
_delay_ms(2);
LCD_CR(0x01);
// while(1)
//{
// for(b=0;b<16;b++)
//{
// while(1)
// {
LCD_PST(0,0);
str(a);
// for(b=0;b<16;b++)
//{
LCD_PST(1,0);
str(c);
// LCD_DB(0X23);
// init_buffer();
//}
// delay_ms(1000);
//str(a);
//LCD_PST(1,1);
//delay_ms(1000);
//LCD_DB(0x2b);
//delay_ms(1000);
//LCD_CR(LCD_CLEAR);
//delay_ms(1000);
//}
}반응형'AVR study' 카테고리의 다른 글
[AVR] 타이머/카운터0 와 CLCD를 이용한 디지털 시계 (3) 2013.02.03 [AVR] 사용자 정의 문자 선언을 통해 간단한 그림 출력 (2) 2013.01.30 [AVR] CLCD의 Instruction Table을 통한 헤더파일 작성 (0) 2013.01.29 [AVR] CLCD 내부구조 및 핀설명 / WH1602B-YYH-JT# (0) 2013.01.29 LCD란? LCD의 동작원리와 장단점 (1) 2013.01.27