본문 바로가기
코스웨어/16년 스마트컨트롤러

2016.03.16 이종찬 업무일지

by 알 수 없는 사용자 2016. 3. 18.
728x90
반응형

LCD출력

캐릭터 LCD를 동작시키기 위한 명령어는 다양하다. 하지만 명령어를분류한다면 4가지로 분류할 수 있다.

1.명령어 쓰기 (디스플레이 데이터 포맷, 깜박임,쉬프트 밑줄, 커서,어그레스 등의 대한 설정)

2.상태 읽기 (비지체크 등)

3.데이터 쓰기 (디스플레이할 데이터 쓰기)

4.데이터 읽기

아래표는 제어명령어 이다.

 

표를 보면 DB07~DB00 까지2진수로 표현 되어있습니다.

0 0 0 0 | 0 0 0 0 이런식으로 나와있습니다.


리고 설명칸에는 어떤자리에 명령어를 써야하는지 친절하게 나와있다.

설명칸 밑에 보면 멍령어 설명도 있다.

ex)





이렇게 써넣으면(?) 된다!


LCD에 T출력

LCD헤더파일은 바로 위 사진과 동일.

LCD c소스파일.

#include "LCD.h"

void LCD_Init(void)
{
 DDRC=(1<<RS) | (1<<RW) | (1<<EN);
 DDRA=0xFF;
 CTL=(0<<RS) | (0<<RW) | (0<<EN);
 BUS=0x00;

 LCD_Inst(LCD_FUNC);
 LCD_Inst(LCD_DSP);
 LCD_Inst(LCD_ENT);
 LCD_Inst(LCD_CUR);
 LCD_Inst(LCD_CLR);
 LCD_Inst(LCD_HOME);

}

void LCD_Inst(unsigned char ucInst)
{
 volatile unsigned int uicnt;

 CTL=CTL & ~(1<<RS);
 CTL=CTL & ~(1<<RW);
 CTL=CTL & ~(1<<EN);
 BUS=ucInst;
 for(uicnt=0; 30000>uicnt; uicnt++); // 1번 구간을 유지하기위해 지연문을 사용한다.

 for(uicnt=0; 30000>uicnt; uicnt++);

 CTL=CTL | (1<<EN);
 for(uicnt=0; 30000>uicnt; uicnt++);

 CTL=CTL & ~(1<<EN);
 for(uicnt=0; 30000>uicnt; uicnt++);

 for(uicnt=0; 30000>uicnt; uicnt++);
 
}

void LCD_Data(unsigned char ucData)
{
 volatile unsigned uicnt ;

 CTL=CTL | (1<<RS);
 CTL=CTL & ~(1<<RW);
 CTL=CTL & ~(1<<EN);
 BUS=ucData;
 for(uicnt=0; 30000>uicnt; uicnt++); // 1번 구간을 유지하기위해 지연문을 사용한다.

 for(uicnt=0; 30000>uicnt; uicnt++);

 CTL=CTL | (1<<EN);
 for(uicnt=0; 30000>uicnt; uicnt++);

 CTL=CTL & ~(1<<EN);
 for(uicnt=0; 30000>uicnt; uicnt++);
 
 for(uicnt=0;30000>uicnt;uicnt++);
 
}


void LCD_str (const char *cstring)
{
 while(0!=*cstring)
 {
  LCD_Data(*cstring);
  ++cstring;
  
 }
}

메인 헤더파일.

#ifndef __MAIN_H__ 
#define __MAIN_H__ 

void Init(void);
void Port_Init(void);
void INT_Init(void);

#define PINA (*((volatile unsigned char *)0x20))
#define DDRA  (*((volatile unsigned char *)0x21))
#define PORTA (*((volatile unsigned char *)0x22))

#define PINC (*((volatile unsigned char *)0x26))
#define DDRC  (*((volatile unsigned char *)0x27))
#define PORTC  (*((volatile unsigned char *)0x28))

#define EICRA  (*((volatile unsigned char *)0x69))
#define EICRB  (*((volatile unsigned char *)0x6A))
#define EIMSK  (*((volatile unsigned char *)0x3D))

#define SREG (*((volatile unsigned char *)0x5F))

#define INT7 7
#define INT6 6
#define INT5 5
#define INT4 4
#define INT3 3
#define INT2 2
#define INT1 1
#define INT0 0

#define ISC7 6
#define ISC6 4
#define ISC5 2
#define ISC4 0
#define ISC3 6
#define ISC2 4
#define ISC1 2
#define ISC0 0

#define sei()   __asm__ __volatile__ ("sei" ::) 
#define sleep() __asm__ __volatile__ ( "sleep" "\n\t" :: )

void __vector_1(void) __attribute__((signal, used, externally_visible)); 
void __vector_2(void) __attribute__((signal, used, externally_visible)); 

#endif 


메인 c소스파일.

#include "main.h"
#include "lcd.h"

int main(void)
{
 LCD_Init();
 LCD_STR("T");
  
 while(1)
 {
 }

 return 0;
}


이렇게 넣어서 출력.







728x90