Micom_Electric/GLCD_CLCD_TFT
2012. 1. 22. 18:48
윤덕용 교수의 한글 GLCD 라이브러리 수정 - 그래픽 기능 추가
TFT LCD에는 있는 기능인데 GLCD 라이브러리에는 없어 수정함
..
수정할 곳..
맨위에 아래 수정 및 추가
GLCD 데이터 읽기 - RW 핀 수정해야 함 (원래는 GND에 묶여 있다)
// ----------------------------------------------------------------------------
픽셀 그리기
픽셀단위 이동 (윤교수님 라이브러리는 글자 단위 이동 : 8비트)
그리고 기타 선 / 원 / 박스 그리기 기능 -- 인터넷에서 주워 왔음
TFT LCD에는 있는 기능인데 GLCD 라이브러리에는 없어 수정함
..
수정할 곳..
맨위에 아래 수정 및 추가
/* -------------------------------------------------------------------------*/
/* Graphic LCD Module : Hyundai LCD,HG12605NY-LY,128x64 dot,LED backlight */
/* -------------------------------------------------------------------------*/
/* LCD_DATABUS(0x2000) : D0-D7 = DB0-DB7 (7-14, data bus) */
/* LCD_CONTROL(0x2100) : D3 = R/-W (5, read/write) */
/* D4 = D/-I (4, data/instruction) */
/* D5 = E (6, enable) */
/* D6 = CS1 (15, chip select 1) */
/* D7 = CS2 (16, chip select 2) */
#define LCD_DATABUS PORTD // LCD/GLCD data
#define LCD_CONTROL PORTF // LCD/GLCD control signal
#define LCD_DATA_PIN PIND // Added to read data
#define LCD_DATA_DIR DDRD
#define LCD_CTRL_DIR DDRF
const unsigned char color = 1; // Added for Graphic Routin
GLCD 데이터 읽기 - RW 핀 수정해야 함 (원래는 GND에 묶여 있다)
// ----------------------------------------------------------------------------
unsigned char GLCD_data_RD(uint8_t cols) // Read a data
{
unsigned char data=0, signal;
if(cols < 64) // if y <= 7, CS1
signal = 0x40;
else // if y >= 8, CS2
signal = 0x80;
LCD_CONTROL = (signal & 0xC0)|0x10; // RS = 1 => PD4
asm volatile(" PUSH R0 "); // delay for 500 ns
asm volatile(" POP R0 ");
asm volatile(" PUSH R0 ");
asm volatile(" POP R0 ");
LCD_CONTROL |= 0x08; // Set Read; RW = PD3
LCD_DATA_DIR = 0x00;
LCD_DATABUS = 0x00;
LCD_CONTROL |= (signal & 0xC0)|0x30; // E = 1
asm volatile(" PUSH R0 "); // delay for 500 ns
asm volatile(" POP R0 ");
asm volatile(" PUSH R0 ");
asm volatile(" POP R0 ");
data = LCD_DATA_PIN;
LCD_CONTROL = (signal & 0xC0)|0x10; // E = 0
asm volatile(" NOP ");
LCD_CONTROL &= ~0x08; // Set Write ; RW = PD3
LCD_DATA_DIR = 0xFF;
LCD_DATABUS = 0x00;
LCD_CONTROL = 0x00; // clear all control signals
Delay_us(10); // wait GLCD busy
return data;
}
픽셀 그리기
// ----------------------------------------------------------------------------
void GLCD_SetPixel(unsigned char cols, unsigned char rows, unsigned char color){
unsigned char temp=0, signal;
if(cols < 64) // if y <= 7, CS1
signal = 0x40;
else // if y >= 8, CS2
signal = 0x80;
GLCD_move_xy(cols, rows);
GLCD_data_RD(cols);
GLCD_move_xy(cols, rows);
temp = GLCD_data_RD(cols);
temp |= _BV(rows%8);
GLCD_move_xy(cols, rows);
GLCD_data(signal, temp);
} 픽셀단위 이동 (윤교수님 라이브러리는 글자 단위 이동 : 8비트)
// ----------------------------------------------------------------------------
void GLCD_move_xy(unsigned char cols, unsigned char rows){
unsigned char signal;
if((cols/8) <= 7) // if y <= 7, CS1
signal = 0x40;
else // if y >= 8, CS2
signal = 0x80;
GLCD_command(signal, 0xB8 + (rows/8));
if(cols < 64) GLCD_command(signal,0x40 + cols);
else GLCD_command(signal,0x40 + (cols - 64));
}
그리고 기타 선 / 원 / 박스 그리기 기능 -- 인터넷에서 주워 왔음
// ----------------------------------------------------------------------------
void GLCD_Rectangle(
unsigned char x, unsigned char y, unsigned char b, unsigned char a)
{
unsigned char j; // zmienna pomocnicza
// rysowanie linii pionowych (boki)
for (j = 0; j < a; j++){
GLCD_SetPixel(x, y + j, color);
GLCD_SetPixel(x + b - 1, y + j, color);
}
// rysowanie linii poziomych (podstawy)
for (j = 0; j < b; j++){
GLCD_SetPixel(x + j, y, color);
GLCD_SetPixel(x + j, y + a - 1, color);
}
}
// ----------------------------------------------------------------------------
void GLCD_Circle(unsigned char cx, unsigned char cy ,unsigned char radius){
int x, y, xchange, ychange, radiusError;
x = radius;
y = 0;
xchange = 1 - 2 * radius;
ychange = 1;
radiusError = 0;
while(x >= y){
GLCD_SetPixel(cx+x, cy+y, color);
GLCD_SetPixel(cx-x, cy+y, color);
GLCD_SetPixel(cx-x, cy-y, color);
GLCD_SetPixel(cx+x, cy-y, color);
GLCD_SetPixel(cx+y, cy+x, color);
GLCD_SetPixel(cx-y, cy+x, color);
GLCD_SetPixel(cx-y, cy-x, color);
GLCD_SetPixel(cx+y, cy-x, color);
y++;
radiusError += ychange;
ychange += 2;
if ( 2*radiusError + xchange > 0 ){
x--;
radiusError += xchange;
xchange += 2;
}
}
}
// ----------------------------------------------------------------------------
void GLCD_Line(unsigned int X1,unsigned int Y1,unsigned int X2,unsigned int Y2)
{
int CurrentX, CurrentY, Xinc, Yinc,
Dx, Dy, TwoDx, TwoDy,
TwoDxAccumulatedError, TwoDyAccumulatedError;
Dx = (X2-X1); // obliczenie sk쿪dowej poziomej
Dy = (Y2-Y1); // obliczenie sk쿪dowej pionowej
TwoDx = Dx + Dx; // podwojona sk쿪dowa pozioma
TwoDy = Dy + Dy; // podwojona sk쿪dowa pionowa
CurrentX = X1; // zaczynamy od X1
CurrentY = Y1; // oraz Y1
Xinc = 1; // ustalamy krok zwi?szania pozycji w poziomie
Yinc = 1; // ustalamy krok zwi?szania pozycji w pionie
if(Dx < 0){
Xinc = -1; // to b?ziemy si?"cofa? (krok ujemny)
Dx = -Dx; // zmieniamy znak sk쿪dowej na dodatni
TwoDx = -TwoDx; // jak r?nie?podwojonej sk쿪dowej
}
if (Dy < 0){
Yinc = -1; // to b?ziemy si?"cofa? (krok ujemny)
Dy = -Dy; // zmieniamy znak sk쿪dowej na dodatki
TwoDy = -TwoDy; // jak r?niez podwojonej sk쿪dowej
}
GLCD_SetPixel(X1,Y1, color);
if((Dx != 0) || (Dy != 0)){
if (Dy <= Dx){
TwoDxAccumulatedError = 0; // zerujemy zmienn?
do{
CurrentX += Xinc; // do aktualnej pozycji dodajemy krok
TwoDxAccumulatedError += TwoDy;
if(TwoDxAccumulatedError > Dx){
CurrentY += Yinc; // zwi?szamy aktualn?pozycj?w pionie
TwoDxAccumulatedError -= TwoDx; // i odejmujemy TwoDx
}
GLCD_SetPixel(CurrentX,CurrentY, color);
}while (CurrentX != X2);
}else{
TwoDyAccumulatedError = 0;
do{
CurrentY += Yinc;
TwoDyAccumulatedError += TwoDx;
if(TwoDyAccumulatedError>Dy){
CurrentX += Xinc;
TwoDyAccumulatedError -= TwoDy;
}
GLCD_SetPixel(CurrentX,CurrentY, color);
}while (CurrentY != Y2);
}
}
}
// ----------------------------------------------------------------------------