밑의 소스 코드를 사용하면 LED에 LOVE라는 글자가 뜬다.
코드 주의 선 주의 !!
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("LOVE");
while(1)
{
}
return 0;
}
'코스웨어 > 16년 스마트컨트롤러' 카테고리의 다른 글
2016_03_21_펌웨어_노태경_업무일지 (0) | 2016.03.21 |
---|---|
20160318-이보원-업무일지-펌웨어(전역변수 공용) (0) | 2016.03.21 |
20160317_박진한_업무일지_펌웨어 LCD 숫자 카운트 (0) | 2016.03.21 |
2016_03_21_리눅스명령어_업무일지_노태경 (0) | 2016.03.21 |
20160315_박진한_업무일지_펌웨어 LCD 기초 (0) | 2016.03.21 |
20160318_송민규_업무일지_펌웨어실습 (0) | 2016.03.21 |
20160317_송민규_업무일지_펌웨어실습 타이머카운트 (0) | 2016.03.21 |
20160316_송민규_업무일지_펌웨어실습 LCD (0) | 2016.03.21 |