#include "LCD.h" #include "USART.h" #include "SMART.h"
//Wide variable static unsigned int uiCharCnt;
// LCD driver 프로그램 작성
void LCD_AVR_PIN_INIT(void) { LCD_BUS_DDR = 0xFF; LCD_CTL_DDR = (1<<LCD_PIN_RS) | (1<<LCD_PIN_RW) | (1<< LCD_PIN_EN); // == 0x07 return; }
void LCD_INST(unsigned char ucInst)
{ volatile unsigned int uiCnt; LCD_BUS=ucInst;
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (1<< LCD_PIN_EN); // == 0x01
Delay(500); //4//Tw(230)- Tsu2(80) = 150ns 지연
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
}
void LCD_Data(unsigned char ucData)
{ volatile unsigned int uiCnt;
LCD_BUS=ucData;
LCD_CTL = (1<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
LCD_CTL = (1<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (1<< LCD_PIN_EN); // == 0x01
Delay(500); //4//Tw(230)- Tsu2(80) = 150ns 지연
LCD_CTL = (1<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN);
Delay(500); //4//10ns 지연
}
void LCD_Init(void) { volatile unsigned int uiCnt;
LCD_AVR_PIN_INIT();
Delay(500); // ATmega가 LCD보다 구동이 먼저 되는 경우를 대비하여 넣어주는 딜레이 코드
LCD_INST(LCD_INST_FUNC); LCD_INST(LCD_INST_DSP); LCD_INST(LCD_INST_ENT); LCD_INST(LCD_INST_CUR); LCD_INST(LCD_INST_CLR); LCD_INST(LCD_INST_HOME);
uiCharCnt = 0;
return; }
void LCD_PRINT(const unsigned char * ucString) { for(;*ucString != 0; ++ucString) { LCD_Data(*ucString); } return; }
void LCD_SetAddr(unsigned char ucAddr) { if(ucAddr>15) { if(ucAddr<40) { ucAddr = 40; } else if(ucAddr>55) { ucAddr = 0;
} }
LCD_INST(0x80|ucAddr); }
void LCD_CGRom_Write(unsigned char ucInst)
{ volatile unsigned int uiCnt; LCD_BUS=ucInst;
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
LCD_CTL = (1<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (1<< LCD_PIN_EN); // == 0x01
Delay(500); //4//Tw(230)- Tsu2(80) = 150ns 지연
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
} void LCD_CGRom_Read(unsigned char ucInst)
{ volatile unsigned int uiCnt; LCD_BUS=ucInst;
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연
LCD_CTL = (1<<LCD_PIN_RS) | (1<<LCD_PIN_RW) | (1<< LCD_PIN_EN); // == 0x01
Delay(500); //4//Tw(230)- Tsu2(80) = 150ns 지연
LCD_CTL = (0<<LCD_PIN_RS) | (0<<LCD_PIN_RW) | (0<< LCD_PIN_EN); // == 0x00 DC 영역
Delay(500); //40ns 지연 }
void LCD_MYNAME(void) { volatile unsigned int vuiCnt; unsigned char font[] = { 0x0A, 0x04, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, // 0.second char ㅡ 0x0E, 0x00, 0x1f, 0x00, 0x04, 0x0a, 0x0a, 0x04, // 1. forth char ㅎ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, // 2. fifth char ㅣ 0x1F, 0x0A, 0x0A, 0x0A, 0x00, 0x10, 0x1F, 0x00, // 3. sixth char ㅠㄴ 0x12, 0x12, 0x1E, 0x12, 0x12, 0x12, 0x00, 0x00, // 4. eighth char ㅐ 0x04, 0x0A, 0x11, 0x0A, 0x04, 0x00, 0x1F, 0x00, // 5. nineth char ㅇ ㅡ }; for(vuiCnt=0; vuiCnt<42; ++vuiCnt) LCD_Data(font[vuiCnt]); } |