728x90
LCD에 글자 출력하기
MAKEFILE 소스 수정
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c lcd.c
make하기전에 각 소스의 마지막 줄은 비워둘 것
LCD에 A 출력
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 //control line
void LCD_Init(void);
void LCD_Inst(unsigned char ucInst);
void LCD_Data(unsigned char ucData);
void LCD_STR(const char* cString);
#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);
DDRA = 0xff; //C3개, A8개 연다.
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); //A
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //B
CTL = CTL | (1<<EN);
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //C
CTL = CTL & ~(1<<EN);
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //D
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //E
}
void LCD_Data(unsigned char ucData)
{
volatile unsigned int uiCnt;
CTL = CTL | (1<<RS);
CTL = CTL & ~(1<<RW);
CTL = CTL & ~(1<<EN);
BUS = ucData;
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //A
//CTL = CTL | (1<<RS);
//CTL = CTL & ~(1<<RW);
//CTL = CTL & ~(1<<EN);
//BUS = ucData;
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //B
//CTL = CTL | (1<<RS);
//CTL = CTL & ~(1<<RW);
CTL = CTL | (1<<EN);
//BUS = ucData;
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //C
//CTL = CTL | (1<<RS);
//CTL = CTL & ~(1<<RW);
CTL = CTL & ~(1<<EN);
//BUS = ucData;
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //D
//CTL = CTL | (1<<RS);
//CTL = CTL & ~(1<<RW);
//CTL = CTL & ~(1<<EN);
//BUS = ucData;
for(uiCnt = 0; 30000>uiCnt; ++uiCnt); //E
}
void LCD_STR(const char* cString)
{
while(0!=*cString)
{
LCD_Data(*cString);
++cString;
}
} |
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" ::)
#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 //__MAIN_H__ |
main.c
#include "main.h"
#include "lcd.h"
int main(void)
{
LCD_Init();
LCD_STR("TEST");
while(1)
{
}
return 0;
} |
LCD에 TEST 출력
'Study > Embedded' 카테고리의 다른 글
20160321_펌웨어(UART) (0) | 2016.03.21 |
---|---|
20160317-펌웨어(타이머 카운터) (0) | 2016.03.17 |
20160315-펌웨어 분석 및 학습 (0) | 2016.03.16 |
20160314-펌웨어 분석(외부 인터럽트) (0) | 2016.03.15 |
20160311-펌웨어분석 (FND, LED Test) (0) | 2016.03.12 |