LCD 펌웨어 실습 이론--------------------------
선생님께서 그림으로 그려주셔서 이해하기 쉬웠습니다. 감사합니다.
LCD 펌웨어 실습--------------------------
<LCD.h 소스>
#ifndef __LCD_H__
#define __LCD_H__
#include "main.h"
#define RS 4
#define RW 5
#define EN 6
#define BUS PORTA
#define CTL PORTC
void LCD_Init(void);
void LCD_Inst(unsigned char ucInst);
void LCD_Data(unsigned char ucData);
#define LCD_CLR 0x01
#define LCD_HOME 0x02
#define LCD_ENT 0x06 //S:0Shift OFF, I/D:1 Increase Mode
#define LCD_DSP 0x0F //D:1 Display On C:1 Cursor on B:1 Blink On
#define LCD_CUR 0x14 //S/C:0 Shift Cursor OFF R/L:1
#define LCD_FUNC 0x38 //DL:1 Data length 8bit N:1 2Line F:0 Font 5X8
#endif //__LCD_H__
==================================================================================================================
<LCD.c 소스>
#include "LCD.h"
void LCD_Init(void)
{
DDRC = (1<<RS)|(1<<RW)|(1<<EN); //RS, RW, EN만 열어라.
DDRA = 0xFF; //8개 다 열어라.
CTL = (0<<RS)|(0<<RW)|(0<<EN); //RS, RW, EN을 LOW로 만든다.
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); //RS는 뒤로 안변해서 뒤는 제거
CTL = CTL & ~(1<<RW); //RW도 뒤가 안변해서 뒤로는 제
CTL = CTL & ~(1<<EN);
BUS = ucInst;
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 A를 나타낸다.
for(uiCnt =0; 3000>uiCnt; ++uiCnt);//여기가 B를 나타낸다.
CTL = CTL | (1<<EN);
for(uiCnt =0; 3000>uiCnt; ++uiCnt);//여기가 C를 나타낸다.
CTL = CTL & ~(1<<EN);
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 D를 나타낸다.
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 E를 나타낸다.
}
void LCD_Data(unsigned char ucData)
{
volatile unsigned int uiCnt;
CTL = CTL |(1<<RS); //RS는 뒤로 안변해서 뒤는 제거
CTL = CTL & ~(1<<RW); //RW도 뒤가 안변해서 뒤로는 제
CTL = CTL & ~(1<<EN);
BUS = ucData;
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 A를 나타낸다.
for(uiCnt =0; 3000>uiCnt; ++uiCnt);//여기가 B를 나타낸다.
CTL = CTL | (1<<EN);
for(uiCnt =0; 3000>uiCnt; ++uiCnt);//여기가 C를 나타낸다.
CTL = CTL & ~(1<<EN);
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 D를 나타낸다.
for(uiCnt =0; 3000>uiCnt; ++uiCnt); //여기가 E를 나타낸다.
}
==================================================================================================================
<main.c 소스>
#include "main.h"
#include "LCD.h"
int main(void)
{
LCD_Init();
LCD_Data('A');
LCD_Data('B');
LCD_Data('C');
LCD_Data('D');
while(1)
{
}
return 0;
}
==================================================================================================================
<main.h 소스>
#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" ::) //7번비트만 1로 만들어줌.어셈블리코드
#define sleep() __asm__ __volatile__ ( "sleep" "\n\t" :: )
void __vector_1(void) __attribute__((signal, used, externally_visible)); //인터럽트 신호를 받는다,사용된다,외부에서 이걸 볼 수 있어야한다.(호출가능하다) INT0를 뜻함.
void __vector_2(void) __attribute__((signal, used, externally_visible)); //인터럽트 신호를 받는다,사용된다,외부에서 이걸 볼 수 있어야한다.(호출가능하다) INT1를 뜻함.
#endif //__MAIN_H__
==================================================================================================================
<구동 영상1>
<구동 영상2 내이름 나오게 하기>
'코스웨어 > 16년 스마트컨트롤러' 카테고리의 다른 글
20160316_업무일지_정우민_펌웨어실습(LCD) (0) | 2016.03.16 |
---|---|
2016.03.11_노태경_업무일지 (0) | 2016.03.16 |
16.03.16 조승현 업무일지 about_LCD 디스플레이 명령어 (0) | 2016.03.16 |
20160314_오아람_업무일지_펌웨어분석+전역변수 (0) | 2016.03.16 |
Lcd.h (0) | 2016.03.16 |
Alpha Yong (1) | 2016.03.16 |
20160310_업무일지_정우민_펌웨어실습 (0) | 2016.03.16 |
20160314_김도관_업무일지_펌웨어실습_인터럽트_버튼으로 LED점멸 (0) | 2016.03.16 |