Easyflow Inc.
हिन्दी · विदेश · अमेरिकी डॉलर ($) में दिखाया जा रहा है। आप इसे ऊपर दिए ग्लोब आइकन से बदल सकते हैं।

FM8P तकनीकी दस्तावेज़

ATMEGA128 atmega2561 그래픽 LCD 소스

AVR 소스코드 ATMEGA128 atmega2561 GLCD Library v10 2011-10-06
/*
///////////////////////////////////////////////////////////////////////////////

    ATMEGA 128, 2561 Graphic LCD Library V.1.0

    1st v.1.0   :	2011년 9월 23일
	  제작자  	  :	(주)이지플로우

///////////////////////////////////////////////////////////////////////////////
*/


#ifdef  EF_GRAPHIC_LCD

// 완성형을 조합형으로 변환후 표시할 경우 사용
#define HAN_CONVERT
#define MYEONGJO

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Graphic LCD 포트를 정의합니다.
// Graphic LCD Module : YHG12864HG,128x64 dot,LED backlight

#define GLCD_DATA         (PORTA)
#define GLCD_DATA_DIR	    (DDRA)
#define GLCD_CONTROL_DIR	(DDRC)
#define GLCD_CONTROL_BIT  ( (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4) )

#define GLCD_RW_1		  SETBIT  (PORTC, 1)
#define GLCD_RW_0		  CLEARBIT(PORTC, 1)
#define GLCD_E_1		  SETBIT  (PORTC, 0)
#define GLCD_E_0		  CLEARBIT(PORTC, 0)
#define GLCD_RS_1		  SETBIT  (PORTC, 2)
#define GLCD_RS_0		  CLEARBIT(PORTC, 2)

#define GLCD_CS1_1		SETBIT  (PORTC, 3)
#define GLCD_CS1_0		CLEARBIT(PORTC, 3)
#define GLCD_CS2_1		SETBIT  (PORTC, 4)
#define GLCD_CS2_0		CLEARBIT(PORTC, 4)


///////////////////////////////////////////////////////////////////////////////


unsigned char ScreenBuffer[8][128];           // screen buffer

#include "HanFont.h"

unsigned char xcharacter, ycharacter;		      // x character(0-3), y character(0-15)
unsigned char cursor_flag, xcursor, ycursor;  // x and y cursor position(0-3, 0-15)

// write a command
// LCD Module 에 명령을 저장합니다.
void GLCD_Command(unsigned char signal,unsigned char command)      
{
  if ( signal & 0x40 ) GLCD_CS1_0;
  else                 GLCD_CS1_1;
  if ( signal & 0x80 ) GLCD_CS2_0;
  else                 GLCD_CS2_1;
  
  GLCD_RS_0;                // Rs	= 0	
  GLCD_E_0;				          // E	= 0
  GLCD_RW_0;				        // RW	= 0;
  Delay_us(1);	
				
  GLCD_DATA_DIR  =	0xFF;	  // LCD Data output				
  GLCD_DATA      = command;	// Output Data
  GLCD_E_1;			      	    // E	= 1
  Delay_us(1);				      // 1us Delay
  GLCD_E_0;				          // E = 0
        
  _NOP();
  GLCD_CS1_1;
  GLCD_CS2_1;				        // clear all control signals

  Delay_us(10);             // wait for GLCD busy
}


// write a data
// LCD Module 에 데이터를 저장합니다.
void GLCD_Data(unsigned char signal,unsigned char data)
{
  if ( signal & 0x40 ) GLCD_CS1_0;
  else                 GLCD_CS1_1;
  if ( signal & 0x80 ) GLCD_CS2_0;
  else                 GLCD_CS2_1;
  GLCD_RS_1;         				// Rs	= 1
	GLCD_E_0;				          // E	= 0
	GLCD_RW_0;				        // RW	= 0;
  Delay_us(1);
         
	GLCD_DATA_DIR  =	0xFF;		// LCD Data output				
	GLCD_DATA      =	data;		// Output data
  GLCD_E_1;						      // E	= 1
	Delay_us(1);					    // 1us Delay
	GLCD_E_0;                 // E = 0

  _NOP();
                            
  GLCD_CS1_1;               // clear all control signals
  GLCD_CS2_1;
  
  Delay_us(10);             // wait GLCD busy
}


// clear GLCD screen
// LCD Module 화면을 지웁니다.
void GLCD_clear(void)				
{
  unsigned char i, j, x;

  //LCD_CONTROL = 0x00;		      // clear all control signals
  GLCD_Command(0xC0,0x3F);			// CS1,CS2 display ON
  GLCD_Command(0xC0,0xC0);			// CS1,CS2 display position

  x = 0xB8;
  for(i = 0; i <= 7; i++)
  { 
    GLCD_Command(0xC0,x);       // X start addtess
    GLCD_Command(0xC0,0x40);    // Y start address
    for(j = 0; j <= 63; j++)
    {    
      GLCD_Data(0xC0,0x00);			// clear CS1 and CS2 screen
    }
    x++;
  }
  
  // Ram Buffer를 지웁니다.
  for(i = 0; i <= 7; i++)
  { 
     for(j = 0; j <= 127; j++)
    {    
      ScreenBuffer[i][j]=0;
    }
  }
}


// set English character position
// 영문 글자 위치를 설정합니다.
void GLCD_xy(unsigned char x,unsigned char y)
{ 
  xcharacter = x;				// x = 0 - 3
  ycharacter = y;				// y = 0 - 15
}


// set character upper/lower row
// 글자 위치를 위로 또는 아래로 설정합니다.
void GLCD_xy_row(unsigned char x,unsigned char y,unsigned char row)
{  
  // if upper row, set Y address, else if lower row, set Y address + 1
  if(row == 0)  { GLCD_Command(0xC0,0xB8 + x*2);      }
  else          { GLCD_Command(0xC0,0xB8 + x*2 + 1);  }
  
   // if y <= 7, CS1 Y address, else if y >= 8, CS2 Y address
  if(y <= 7)    { GLCD_Command(0x40,0x40 + y*8);      }
  else	        { GLCD_Command(0x80,0x40 + (y-8)*8);  }
}


// display a 8x16 Dot English(ASCII)
// 8*16 영문글자(ASCII)를 표시합니다.
void GLCD_English(unsigned char Ecode)
{ 
  unsigned char i, signal;
  
  // display upper row
  GLCD_xy_row(xcharacter,ycharacter,0);		
  // if y <= 7, CS1, else if y >= 8, CS2
  if(ycharacter <= 7) { signal = 0x40; }
  else	              { signal = 0x80; }
  for(i = 0; i <= 7; i++)
  {
    //GLCD_Data(signal,pgm_read_byte(&E_font[Ecode][i]));
    GLCD_Data(signal,E_font[Ecode][i] );
  }
  // display lower row
  GLCD_xy_row(xcharacter,ycharacter,1); 
  
  // if y <= 7, CS1, else if y >= 8, CS2 
  if(ycharacter <= 7) { signal = 0x40; }
  else                { signal = 0x80; }
  
  for(i = 8; i <= 15; i++)
  { 
    if((cursor_flag == 1) && (xcharacter == xcursor) && (ycharacter == ycursor))
    {    
      GLCD_Data(signal, E_font[Ecode][i] | 0x80 );
    }
    else
    {        
      GLCD_Data(signal, E_font[Ecode][i]);
    }
  }

  // go next character position
  ycharacter++;                         
  if(ycharacter == 16)
  { 
    ycharacter = 0;
    xcharacter++;
  }
}


// display a 16x16 Dot Korean
// 16*16 한글을 표시합니다.
void GLCD_Korean(unsigned int Kcode)
{ 
  unsigned char i, signal;
  unsigned char cho_5bit, joong_5bit, jong_5bit;
  unsigned char cho_bul, joong_bul, jong_bul=0, jong_flag;
  unsigned int character;
  unsigned char Korean_buffer[32];	// 32 byte Korean font buffer

  // if can not display, go next line
  if(ycharacter == 15)				      
  {  
    GLCD_English(0x20);
  }
					
  // get cho, joong, jong 5 bit
  cho_5bit    = table_cho[(Kcode >> 10) & 0x001F];
  joong_5bit  = table_joong[(Kcode >> 5) & 0x001F];
  jong_5bit   = table_jong[Kcode & 0x001F];

  // don't have jongsung
  if(jong_5bit == 0)		 
  { 
    jong_flag = 0;
    cho_bul = bul_cho1[joong_5bit];
    if((cho_5bit == 1) || (cho_5bit == 16)) { joong_bul = 0; }
    else                                    { joong_bul = 1; }
  }
  else						      
  { 
    // have jongsung
    jong_flag = 1;
    cho_bul = bul_cho2[joong_5bit];
    if((cho_5bit == 1) || (cho_5bit == 16)) { joong_bul = 2; }
    else                                    { joong_bul = 3; }
    jong_bul = bul_jong[joong_5bit];
  }

  // copy chosung font
  character = cho_bul*20 + cho_5bit;		        
  for(i = 0; i <= 31; i++)
  {  Korean_buffer[i] = K_font[character][i]; }

  // OR joongsung font
  character = 8*20 + joong_bul*22 + joong_5bit;	
  for(i = 0; i <= 31; i++)
  {  Korean_buffer[i] |= K_font[character][i]; }

  // if jongsung, OR jongsung font
  if(jong_flag == 1)				
  { 
    character = 8*20 + 4*22 +jong_bul*28 + jong_5bit;
    for(i = 0; i <= 31; i++)
    { Korean_buffer[i] |= K_font[character][i]; }
  }

  GLCD_xy_row(xcharacter,ycharacter,0);		// display upper left row
  // if y <= 7, CS1, else if y >= 8, CS2
  if(ycharacter <= 7) {	 signal = 0x40; }
  else                {	 signal = 0x80; }
  for(i = 0; i <= 7; i++)
  { GLCD_Data(signal,Korean_buffer[i]); }

  GLCD_xy_row(xcharacter,ycharacter,1);		// display lower left row
  // if y <= 7, CS1, else if y >= 8, CS2 
  if(ycharacter <= 7) { signal = 0x40; }
  else						    { signal = 0x80; }
  for(i = 16; i <= 23; i++)
  { 
    if((cursor_flag == 1) && (xcharacter == xcursor) && (ycharacter == ycursor))
    { GLCD_Data(signal,Korean_buffer[i] | 0x80);  }
    else
    { GLCD_Data(signal,Korean_buffer[i]);         }
  }

  ycharacter++;

  GLCD_xy_row(xcharacter,ycharacter,0);		// display upper right row
  // if y <= 7, CS1, else if y >= 8, CS2 
  if(ycharacter <= 7) {	signal = 0x40; }
  else						    { signal = 0x80; }
  for(i = 8; i <= 15; i++)
  { GLCD_Data(signal,Korean_buffer[i]); }

  GLCD_xy_row(xcharacter,ycharacter,1);		// display lower right row
  // if y <= 7, CS1, else if y >= 8, CS2
  if(ycharacter <= 7) {	signal = 0x40; }
  else						    { signal = 0x80; }
  for(i = 24; i <= 31; i++)
  { 
    if((cursor_flag == 1) && (xcharacter == xcursor) && (ycharacter == (ycursor+1)))
    { GLCD_Data(signal,Korean_buffer[i] | 0x80);  }
    else
    { GLCD_Data(signal,Korean_buffer[i]);         }
  }

  ycharacter++;                           // go next character position
  if(ycharacter == 16)
  { 
    ycharacter = 0;
    xcharacter++;
  }
}


// display a string
// 문자열을 표시합니다.
void GLCD_string(unsigned char x,unsigned char y,unsigned char *string)
{
  unsigned char character1;
  unsigned int character2;

  GLCD_xy(x,y);					          // x = 0 - 3, y = 0 - 15

  while(*string != '\0')
  {
    character1 = *string;
    string++;
    
    if(character1 < 0x80)
    {     
      GLCD_English(character1);		// display English character
    }
    else     
    { 
      character2 = 256*character1 + (*string & 0xFF);
      string++;
      // 조합형 코드를 표시할때  
      //    GLCD_Korean(character2);		// display Korean character
      // 완성형을 조합형으로 변환한 후 표시할때 
      GLCD_Korean( HangulCodeConvert(1, character2 ) );		// display Korean character
      // 조합형을 완성형으로 변환한 후 표시할때 
      //GLCD_Korean( HangulCodeConvert(0, character2 ) );		// display Korean character  
    }
  }
}

// Get XY Dot address
// 점을 주소를 가져옵니다.
void GLCD_Axis_xy(unsigned char x, unsigned char y)
{
        GLCD_Command(0xC0, 0xB8 + x); // X address
        if(y <= 63)
        {
                GLCD_Command(0x40, 0x40 + y); // CS1 Y address
        }
        else
        {
                GLCD_Command(0x80, 0x40 + y - 64); // CS2 Y address
        }
} 


// draw a dot on GLCD
// 점을 그립니다.
void GLCD_Dot(unsigned char xx,unsigned char y)
{
  unsigned char x, i;

  // 해상도 범위(128.64) 인지 검사합니다.
  if((xx > 63) || (y > 127)) return;

  x = xx / 8;					            // calculate x address
  i = xx % 8;
  if(i == 0)      { i = 0x01; }
  else if(i == 1) { i = 0x02; }
  else if(i == 2) { i = 0x04; }
  else if(i == 3) { i = 0x08; }
  else if(i == 4) { i = 0x10; }
  else if(i == 5) { i = 0x20; }
  else if(i == 6) { i = 0x40; }
  else            { i = 0x80; }
  
  ScreenBuffer[x][y] |= i;				// OR old data with new data

  GLCD_Axis_xy(x, y);				      // draw dot on GLCD screen
  if(y <= 63) { GLCD_Data(0x40, ScreenBuffer[x][y]);  }
  else        { GLCD_Data(0x80, ScreenBuffer[x][y]);  }
}


// draw a straight line
// 직선을 그립니다.
void GLCD_Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)	
{
  int x, y;

  if(y1 != y2)				// if y1 != y2, y is variable
  {
    if(y1 < y2)				//              x is function
    {
      for(y = y1; y <= y2; y++)
      {
        x = x1 + (y - y1)*(x2 - x1)/(y2 - y1);
        GLCD_Dot(x,y);
      }
    }
    else
    {
      for(y = y1; y >= y2; y--)
      { 
        x = x1 + (y - y1)*(x2 - x1)/(y2 - y1);
        GLCD_Dot(x,y);
      }
    }
  }
  else if(x1 != x2)	  // if x1 != x2, x is variable
  { 
    if(x1 < x2)				//              y is function
    {
      for(x = x1; x <= x2; x++)
      { y = y1 + (x - x1)*(y2 - y1)/(x2 - x1);
        GLCD_Dot(x,y);
      }
    }
    else
    {
      for(x = x1; x >= x2; x--)
      {
        y = y1 + (x - x1)*(y2 - y1)/(x2 - x1);
        GLCD_Dot(x,y);
      }
    }
  }
  else                  // if x1 == x2 and y1 == y2,
  {
    GLCD_Dot(x1,y1);		//             it is a dot
  }
}


// draw a rectangle
// 직사각형을 그립니다.
void GLCD_Rectangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2) 
{
  GLCD_Line(x1,y1,x1,y2);				// horizontal line
  GLCD_Line(x2,y1,x2,y2);
  GLCD_Line(x1,y1,x2,y1);				// vertical line
  GLCD_Line(x1,y2,x2,y2);
}


// draw a circle
// 원을 그립니다.
void GLCD_Circle(unsigned char x1,unsigned char y1,unsigned char r)	
{
  int x, y;
  float s;

  for(y = y1 - r*3/4; y <= y1 + r*3/4; y++)	// draw with y variable
  {
    s = sqrt(r*r - (y-y1)*(y-y1)) + 0.5;
    x = x1 + (unsigned char)s;
    GLCD_Dot(x,y);
    x = x1 - (unsigned char)s;
    GLCD_Dot(x,y);
  }

  for(x = x1 - r*3/4; x <= x1 + r*3/4; x++)	// draw with x variable
  {
    s = sqrt(r*r - (x-x1)*(x-x1)) + 0.5;
    y = y1 + (unsigned char)s;
    GLCD_Dot(x,y);
    y = y1 - (unsigned char)s;
    GLCD_Dot(x,y);
  }
}


// Display floating-point number xx.x
// 00.0로 소수점을 표시합니다.
void GLCD_2Dot1Float(float number)		       
{
  unsigned int i, j;
  
  j = (int)(number*10. + 0.5);
  i = j / 100;					// 10^1
  if(i == 0) { GLCD_English(' ');     }
  else       { GLCD_English(i + '0'); }

  j = j % 100;					// 10^0
  i = j / 10;
  GLCD_English(i + '0');
  GLCD_English('.');

  i = j % 10;					// 10^-1
  GLCD_English(i + '0');
}


// display 1-digit decimal number
// 1자리의 10진수 값을 표시합니다.
unsigned char GLCD_1DigitDecimal(unsigned char number, unsigned char flag)
{
  number %= 10;               // 10^0
  
  if ((number == 0) && (flag == 0))
  { 
    GLCD_English(' '); 
    return 0;
  } 
  
  GLCD_English(number + '0');
  return 1;
}


// display 2-digit decimal number
// 2자리의 10진수 값을 표시합니다.
void GLCD_2DigitDecimal(unsigned char number)
{
  unsigned int i;
  unsigned char flag;
   
  flag = 0;
  number = number % 100;                        
  i = number/10;
  flag = GLCD_1DigitDecimal(i, flag); // 10^1

  i = number % 10;                              
  GLCD_English(i + '0');              // 10^0
}


// display 3-digit decimal number
// 3자리의 10진수 값을 표시합니다.
void GLCD_3DigitDecimal(unsigned int number)
{
  unsigned int i;
  unsigned char flag;

  flag = 0;
  number = number % 1000; 
  i = number/100;                      
  flag = GLCD_1DigitDecimal(i, flag); // 10^2

  number = number % 100;               
  i = number/10;
  flag = GLCD_1DigitDecimal(i, flag); // 10^1

  i = number % 10;                              
  GLCD_English(i + '0');              // 10^0
}


// display 4-digit decimal number
// 4자리의 10진수 값을 표시합니다.
void GLCD_4DigitDecimal(unsigned int number)
{
  unsigned int i;
  unsigned char flag;

  flag = 0;
  number = number % 10000;
  i = number/1000;                              
  flag = GLCD_1DigitDecimal(i, flag); // 10^3

  number = number % 1000;                       
  i = number/100;
  flag = GLCD_1DigitDecimal(i, flag); // 10^2

  number = number % 100;                        
  i = number/10;
  flag = GLCD_1DigitDecimal(i, flag); // 10^1

  i = number % 10;                              
  GLCD_English(i + '0');              // 10^0
}


// display 1-digit hex number
// 1자리의 16진수 값을 표시합니다.
void GLCD_1DigitHex(unsigned char i)
{
  i &= 0x0F;  // 16^0
  if(i <= 9) { GLCD_English(i + '0');      }
  else       { GLCD_English(i - 10 + 'A'); }
}


// display 2-digit hex number
// 2자리의 16진수 값을 표시합니다.
void GLCD_2DigitHex(unsigned char number)
{
  GLCD_1DigitHex(number >> 4);    // 16^1
  GLCD_1DigitHex(number     );    // 16^0
}


// display 4-digit hex number
// 4자리의 16진수 값을 표시합니다.
void GLCD_4DigitHex(unsigned int number)
{
  GLCD_1DigitHex(number >> 12);   // 16^3
  GLCD_1DigitHex(number >> 8 );   // 16^2
  GLCD_1DigitHex(number >> 4 );   // 16^1
  GLCD_1DigitHex(number      );   // 16^0
}


// display 8-bit binary number
// 8자리의 2진수 값을 표시합니다.
void GLCD_8BitBinary(unsigned char number)            
{
  GLCD_English(((number >> 7) & 0x01) + '0');   // 2^7
  GLCD_English(((number >> 6) & 0x01) + '0');   // 2^6
  GLCD_English(((number >> 5) & 0x01) + '0');   // 2^5
  GLCD_English(((number >> 4) & 0x01) + '0');   // 2^4
  GLCD_English(((number >> 3) & 0x01) + '0');   // 2^3
  GLCD_English(((number >> 2) & 0x01) + '0');   // 2^2
  GLCD_English(((number >> 1) & 0x01) + '0');   // 2^1
  GLCD_English(((number     ) & 0x01) + '0');   // 2^0
}

///////////////////////////////////////////////////////////////////////////////

#endif

2026 चुसोक अवकाश के दौरान कार्यालय बंद रहने की सूचना