GLCD 제어를 위해서는 DataSheet가 필수적이다.
--------------------------
사용 Chip : Atmega8
사용 Program : Microchip Studio(Ver - 7.0.2542)
Proteus 8 Professional
--------------------------
KS0108은 5개의 제어핀, 8개의 Data핀으로 구성되어 있다.
CS1 = 0 && CS2 = 1 -> NT1707C(Left) IC를 사용하겠다는 코드이다.
CS1 = 1 && CS2 = 0 -> NT1708C(Right) IC를 사용하겠다는 코드이다.
CS1 = 0 && CS2 = 0 -> 2개의 IC가 활성화 되어 Data를 출력 시 Left , Right 동시에 글자가 입력됨.
DI or RS -> H : Data, L : Instruction
R/W -> H : Read Data, L = Write Data
RS = 0 && RW = 0 && DataPin = 0x3F => GLCD ON
RS = 0 && RW = 0 && DataPin = 0x3E => GLCD OFF
Atmel Studio 소스코드 :
/*
* GccApplication1.c
*
* Created: 2021-01-01 오후 10:29:03
* Author : jh
*/
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#include "glcd-font.h"
#define GLCD_DATA_PORT PORTD
#define GLCD_CTRL_PORT PORTC
#define GLCD_DPORT_DIR DDRD
#define GLCD_CPORT_DIR DDRC
#define RS PC0
#define RW PC1
#define E PC2
#define RST PC3
#define CS1 PC4
#define CS2 PC5
void glcd_cmd(unsigned char cmd);
void glcd_dta(unsigned char dta);
void glcd_PageSelect(char pge);
void glcd_writeChar(char *chr);
void glcd_SetCursor(uint8_t x,uint8_t y);
void glcd_writeStr(uint8_t x, uint8_t y, char *str);
void glcd_writeImg(char *pxl);
void glcd_int(void);
int main(void)
{
glcd_int();
/* Replace with your application code */
while (1)
{
glcd_writeStr(0, 1, "A");
glcd_writeStr(0, 2, "APPLE");
glcd_writeStr(0, 3, "SAMRT PHONE");
glcd_writeStr(0, 4, "BAAM");
_delay_ms(1000);
}
}
void glcd_cmd(unsigned char cmd)
{
GLCD_CTRL_PORT &= ~(1<<RS);
GLCD_CTRL_PORT &= ~(1<<RW);
GLCD_DATA_PORT = cmd;
GLCD_CTRL_PORT |= (1<<E);
_delay_ms(1);
GLCD_CTRL_PORT &= ~(1<<E);
}
void glcd_dta(unsigned char dta)
{
GLCD_CTRL_PORT |= (1<<RS);
GLCD_CTRL_PORT &= ~(1<<RW);
GLCD_DATA_PORT = dta;
GLCD_CTRL_PORT |= (1<<E);
_delay_ms(1);
GLCD_CTRL_PORT &= ~(1<<E);
}
void glcd_SetCursor(uint8_t x, uint8_t y)
{
if(x>63)
{
GLCD_CTRL_PORT &= ~(1<<CS1);
GLCD_CTRL_PORT |= (1<<CS2);
glcd_cmd(64+x-64);
glcd_cmd(184+y);
}
else
{
GLCD_CTRL_PORT |= (1<<CS1);
GLCD_CTRL_PORT &= ~(1<<CS2);
glcd_cmd(64+x);
glcd_cmd(184+y);
}
// X
//|---------------|
//| | Y
//| |
//|---------------|
//glcd_cmd(0xB8+x);
//glcd_cmd(0x40+y);
}
void glcd_writeChar(char *chr)
{
uint8_t i;
glcd_SetCursor(0,0);
for (i=0;i<5;i++)
{
glcd_dta(*(chr+i));
}
}
void glcd_writeStr(uint8_t x, uint8_t y, char *str)
//void glcd_writeStr(char pge, char *str)
{
int i = 0;
int startFont = 0, endFont = 0, xNum = 0;
//glcd_PageSelect(pge);
while(*str)
{
glcd_SetCursor(x+(xNum*6),y);
startFont = (*str - 32) * 5;
endFont = startFont + 5;
for (i=startFont;i<endFont;i++)
{
//glcd_dta(sys5x7[i]);
_delay_ms(1);
}
str++;
xNum++;
}
}
void glcd_writeImg(char *pxl)
{
}
void glcd_int(void)
{
GLCD_DPORT_DIR = 0xFF;
GLCD_CPORT_DIR = 0xFF;
GLCD_CTRL_PORT &= ~(1<<RST);
_delay_ms(10);
GLCD_CTRL_PORT |= (1<<RST);
glcd_cmd(0x3F);
glcd_cmd(0xC0);
}
회로도 :
참고 문헌 :
'프로그래밍 > 임베디드' 카테고리의 다른 글
[GLCD] 한글의 모든 조합 (0) | 2021.01.05 |
---|---|
[AVR] Avr Studio Flash Memory 사용법 (0) | 2021.01.04 |
[전자회로] 스위치의 Pull-UP, Pull-Down (0) | 2021.01.03 |
[AVR] GLCD Font.h 생성 프로그램 (2) | 2021.01.03 |
[AVR] OR, AND 연산자를 통한 출력 (0) | 2021.01.02 |
댓글