// Driver for LCD Nokia 3320 (NXP PCF8511).
#define NOK_3310
//------------------------------------------------
#include <mega128.h>
#include <spi.h>
#include <delay.h>
#include <stdio.h>
#include <LCD_3320.h>


unsigned char buff[6][84];
unsigned char posx, posy;
 
//------------------------------------------------------
#ifdef NOK_3310
#define LCD_RESET PORTC.4
#define LCD_DC PORTC.5
//------------------------------------------------------
void LCD_init(void) // ИНИЦИАЛИЗАЦИЯ ДИСПЛЕЯ
{
LCD_DC =0;
LCD_RESET=0;
delay_ms(1);
LCD_RESET=1;
delay_ms(1);
LCD_DC=0;
spi(0x21);     // включить питание, расшир. команды
spi(0xC8);     // включить внутренний источник, Vop=0x48;
spi(0x06);    
spi(0x13);      // bias=3
spi(0x20);     // обычный набор инструкций
spi(0x0c);     
delay_us(500);
LCD_clear();  
LCD_refresh();  
}
//------------------------------------------------------
void LCD_refresh (void)  // Обновление дисплея (отображение буффера)
{
unsigned char i,j;

LCD_DC=0 ;
spi(64);
LCD_DC=1;
for(i=0; i<6; i++)
  { 
  LCD_DC=0 ;
  spi(64+i);
  spi(128);
  LCD_DC=1;
  for (j=0; j<84; j++) spi(buff[i][j]);
  }
}
//------------------------------------------------------
#else 
//3320
//------------------------------------------------------

#define LCD_RESET PORTC.4
#define LCD_CS PORTC.5
unsigned char DataLCDTmp;
unsigned char CntLCDTmp;
//------------------------------------------------------
void LCDSend(unsigned char data, unsigned char fc)
{
unsigned char i;
unsigned int d, m;

d=data; if(!fc) d|=0x100;
for(i=0, m=0x100; i<9; i++, m>>=1)
  {
  DataLCDTmp<<=1; if(d & m) DataLCDTmp|=1;
  CntLCDTmp++;
  if(CntLCDTmp==8) { spi(DataLCDTmp); DataLCDTmp=0; CntLCDTmp=0; }
  }
}
//------------------------------------------------------
void LCDSendStart(void)
{
PORTC.5=0; //CS
DataLCDTmp=0; CntLCDTmp=0;
//delay_ms(1);
}
//------------------------------------------------------
void LCDSendEnd(void)
{
if(CntLCDTmp)
  {
  while(CntLCDTmp<8) { DataLCDTmp<<=1; CntLCDTmp++; }
  spi(DataLCDTmp);
  }
DataLCDTmp=0; CntLCDTmp=0;
//delay_ms(1);
PORTC.5=1; //CS
}
//------------------------------------------------------
void LCD_init(void) // ИНИЦИАЛИЗАЦИЯ ДИСПЛЕЯ
{
delay_ms(10);
LCD_RESET=0;
delay_ms(1);
LCD_RESET=1;
delay_ms(100);

LCDSendStart();
LCDSend(0xe2,1); // Soft reset
LCDSend(0xa0,1); // MX=0
LCDSend(0xc0,1); // MY=0
LCDSend(0xa4,1); // DAL=0
LCDSend(0x2f,1); // HVGEN PC0, PC1 = 1
LCDSend(0xaf,1); // DON=1
LCDSendEnd();
delay_ms(100);
LCD_clear();  
LCD_refresh();  
}
//------------------------------------------------------
void LCD_refresh (void)  // Обновление дисплея (отображение буффера)
{
unsigned char x, y;

LCDSendStart();
LCDSend(0xb0,1); // Y=0
LCDSend(0x10,1); // X=0
LCDSend(0x0,1); 
for (y=0; y<6; y++)
  for(x=0; x<84; x++) LCDSend(buff[y][x], 0);
LCDSendEnd();
}
#endif
//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
void LCD_clear (void)
{
unsigned char x, y;
for (y=0; y<6; y++)    
  for (x=0; x<84; x++) buff[y][x]=0;   
}           
//------------------------------------------------------
void LCD_pixel (unsigned char x, unsigned char y, unsigned char color)
{   // Рисуем пиксель. Все остальные процедуры работают через нее
unsigned char i, bt;
i=y>>3;
bt=1<<(y & 0x7);
if(color) buff[i][x]|=bt;
else buff[i][x]&=(~bt); 
}
//------------------------------------------------------
void LCD_line ( char x1, char y1, char x2, char y2, char mode )
{
int dx, dy, stepx, stepy, fraction;

dy = y2 - y1;
dx = x2 - x1;
if ( dy < 0 ) { dy= -dy; stepy= -1; }
else stepy = 1;
if ( dx < 0 ) { dx= -dx; stepx= -1; }
else stepx = 1;
dx <<= 1;
dy <<= 1;
LCD_pixel( x1, y1, mode );
if ( dx > dy )
  {
  fraction = dy - (dx >> 1);
  while ( x1 != x2 )
    {
    if ( fraction >= 0 ) { y1 += stepy; fraction -= dx; }
    x1 += stepx;
    fraction += dy;
    LCD_pixel( x1, y1, mode );
    }
  }
else
  {
  fraction = dx - (dy >> 1);
  while ( y1 != y2 )
    {
    if ( fraction >= 0 ) { x1 += stepx; fraction -= dy; }
    y1 += stepy;
    fraction += dx;
    LCD_pixel( x1, y1, mode );
    }
  }
}
//------------------------------------------------------
void LCD_dashline ( char x1, char y1, char x2, char y2)
{
char mode;
int dx, dy, stepx, stepy, fraction;

dy = y2 - y1;
dx = x2 - x1;
mode=1;
    
if ( dy < 0 ) { dy= -dy; stepy = -1; }
else stepy = 1;
if ( dx < 0 ) { dx= -dx; stepx = -1; }
else stepx = 1;
dx <<= 1;
dy <<= 1;
LCD_pixel( x1, y1, mode );
if ( dx > dy )
  {
  fraction = dy - (dx >> 1);
  while ( x1 != x2 )
    {
    if(fraction >= 0 ) { y1 += stepy; fraction -= dx; }
    x1 += stepx;
    fraction += dy;
    if (mode) mode=0;
    else mode=1;
    LCD_pixel( x1, y1, mode );
    }
  }
else
  {
  fraction = dx - (dy >> 1);
  while ( y1 != y2 )
    {
    if ( fraction >= 0 ) { x1 += stepx; fraction -= dy; }
    y1 += stepy;
    fraction += dx;
    if (mode) mode=0;
    else mode=1;
    LCD_pixel( x1, y1, mode );
    }
  }
}
//------------------------------------------------------
void LCD_rectangle(char x, char y, char x1, char y1,unsigned char color)  // Прямоугольник
{
LCD_line (x,y,x,y1,color);
LCD_line (x,y1,x1,y1,color);
LCD_line (x1,y1,x1,y,color);
LCD_line (x,y,x1,y,color);
}
//------------------------------------------------------
void LCD_fillrect  (char x, char y, char x1, char y1,unsigned char color)  // закрашенный прямоугольник
{
unsigned char i;
for (i=y; i<=y1; i++) LCD_line(x,i,x1,i,color);
}
//------------------------------------------------------
/*
__flash const unsigned char font8x8[][8] = {         
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  //
	{0x00,0x06,0x5F,0x5F,0x06,0x00,0x00,0x00},
	{0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00},
	{0x14,0x7F,0x7F,0x14,0x7F,0x7F,0x14,0x00},
	{0x24,0x2E,0x6B,0x6B,0x3A,0x12,0x00,0x00},
	{0x46,0x66,0x30,0x18,0x0C,0x66,0x62,0x02},
	{0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48,0x00},
	{0x04,0x07,0x03,0x00,0x00,0x00,0x00,0x00},
	{0x00,0x1C,0x3E,0x63,0x41,0x00,0x00,0x00},
	{0x00,0x41,0x63,0x3E,0x1C,0x00,0x01,0x00},
	{0x08,0x2A,0x3E,0x1C,0x1C,0x3E,0x2A,0x08},
	{0x08,0x08,0x3E,0x3E,0x08,0x08,0x08,0x00},
	{0x00,0x80,0xE0,0x60,0x00,0x00,0x00,0x00},
	{0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},
	{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},
	{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00},
	{0x3E,0x7F,0x41,0x41,0x41,0x7F,0x3E,0x00},
	{0x40,0x42,0x7F,0x7F,0x40,0x40,0x00,0x00},
	{0x62,0x73,0x5B,0x49,0x6F,0x66,0x00,0x00},
	{0x22,0x63,0x49,0x49,0x7F,0x36,0x00,0x00},
	{0x18,0x1C,0x16,0x53,0x7F,0x7F,0x50,0x00},
	{0x27,0x67,0x45,0x45,0x7D,0x39,0x00,0x00},
	{0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00,0x00},
	{0x03,0x03,0x71,0x79,0x0F,0x07,0x00,0x00},
	{0x36,0x7F,0x49,0x49,0x7F,0x36,0x00,0x00},
	{0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00,0x00},
	{0x00,0x00,0x66,0x66,0x00,0x00,0x00,0x00},
	{0x00,0x80,0xE6,0x66,0x00,0x00,0x00,0x00},
	{0x08,0x1C,0x36,0x63,0x41,0x00,0x00,0x00},
	{0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
	{0x00,0x41,0x63,0x36,0x1C,0x08,0x00,0x00},
	{0x02,0x03,0x51,0x59,0x0F,0x06,0x00,0x00},
	{0x3E,0x7F,0x41,0x5D,0x5D,0x1F,0x1E,0x00},
	{0x7C,0x7E,0x13,0x13,0x7E,0x7C,0x00,0x00},
	{0x41,0x7F,0x7F,0x49,0x49,0x7F,0x36,0x00},
	{0x1C,0x3E,0x63,0x41,0x41,0x63,0x22,0x00},
	{0x41,0x7F,0x7F,0x41,0x63,0x3E,0x1C,0x00},
	{0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63,0x00},
	{0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03,0x00},
	{0x1E,0x3E,0x63,0x41,0x51,0x73,0x72,0x00},
	{0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00,0x00},
	{0x41,0x7F,0x7F,0x41,0x00,0x00,0x00,0x00},
	{0x30,0x70,0x40,0x41,0x7F,0x3F,0x01,0x00},
	{0x41,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x00},
	{0x41,0x7F,0x7F,0x41,0x40,0x60,0x70,0x00},
	{0x7F,0x7F,0x0E,0x1C,0x0E,0x7F,0x7F,0x00},
	{0x7F,0x7F,0x06,0x0C,0x18,0x7F,0x7F,0x00},
	{0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C,0x00},
	{0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06,0x00},
	{0x1E,0x3F,0x21,0x71,0x7F,0x5E,0x00,0x00},
	{0x41,0x7F,0x7F,0x09,0x19,0x7F,0x66,0x00},
	{0x22,0x67,0x4D,0x59,0x73,0x22,0x00,0x00},
	{0x03,0x41,0x7F,0x7F,0x41,0x03,0x00,0x00},
	{0x3F,0x7F,0x40,0x40,0x7F,0x3F,0x00,0x00},
	{0x1F,0x3F,0x60,0x60,0x3F,0x1F,0x00,0x00},
	{0x7F,0x7F,0x30,0x18,0x30,0x7F,0x7F,0x00},
	{0x43,0x67,0x3C,0x18,0x3C,0x67,0x43,0x00},
	{0x07,0x4F,0x78,0x78,0x4F,0x07,0x00,0x00},
	{0x47,0x63,0x71,0x59,0x4D,0x67,0x73,0x00},
	{0x00,0x7F,0x7F,0x41,0x41,0x00,0x00,0x00},
	{0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x00},
	{0x00,0x41,0x41,0x7F,0x7F,0x00,0x00,0x00},
	{0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00},
	{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},
	{0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00},
	{0x20,0x74,0x54,0x54,0x3C,0x78,0x40,0x00},
	{0x41,0x7F,0x3F,0x48,0x48,0x78,0x30,0x00},
	{0x38,0x7C,0x44,0x44,0x6C,0x28,0x00,0x00},
	{0x30,0x78,0x48,0x49,0x3F,0x7F,0x40,0x00},
	{0x38,0x7C,0x54,0x54,0x5C,0x18,0x00,0x00},
	{0x48,0x7E,0x7F,0x49,0x01,0x03,0x02,0x00},
	{0x4C,0x5E,0x52,0x52,0x7C,0x3E,0x02,0x00},
	{0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78,0x00},
	{0x00,0x44,0x7D,0x7D,0x40,0x00,0x00,0x00},
	{0x60,0xE0,0x80,0x80,0xFD,0x7D,0x00,0x00},
	{0x41,0x7F,0x7F,0x10,0x38,0x6C,0x44,0x00},
	{0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,0x00},
	{0x7C,0x7C,0x18,0x38,0x1C,0x7C,0x78,0x00},
	{0x7C,0x7C,0x04,0x04,0x7C,0x78,0x00,0x00},
	{0x38,0x7C,0x44,0x44,0x7C,0x38,0x00,0x00},
	{0x84,0xFC,0xF8,0xA4,0x24,0x3C,0x18,0x00},
	{0x18,0x3C,0x24,0xA4,0xF8,0xFC,0x84,0x00},
	{0x44,0x7C,0x78,0x4C,0x04,0x1C,0x18,0x00},
	{0x48,0x5C,0x54,0x54,0x74,0x24,0x00,0x00},
	{0x00,0x04,0x3E,0x7F,0x44,0x24,0x00,0x00},
	{0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40,0x00},
	{0x1C,0x3C,0x60,0x60,0x3C,0x1C,0x00,0x00},
	{0x3C,0x7C,0x70,0x38,0x70,0x7C,0x3C,0x00},
	{0x44,0x6C,0x38,0x10,0x38,0x6C,0x44,0x00},
	{0x9C,0xBC,0xA0,0xA0,0xFC,0x7C,0x00,0x00},  //
	{0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00,0x00},  //122
        
    {0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0xFF}, //квадратик       123
    {0xFF,0x81,0xBD,0xBD,0xBD,0xBD,0x81,0xFF}, //закрашенный квадратик      124
        
    {0x01,0x31,0x79,0x79,0x7D,0x7F,0x7D,0x31},  //Верт 125,126 символ;
    {0x11,0x11,0x11,0x10,0x10,0x10,0x38,0x10},
        
    {0x3E,0x08,0x1C,0x1C,0x7C,0x3E,0x1E,0x1E},  //самолет 127,128 символ;
    {0x1E,0x1C,0x18,0x18,0x18,0x1C,0x0E,0x0E},

    {0xF0,0x08,0x04,0x02,0x01,0x51,0xF1,0xF1},  //ДВИГ, 129,130,131,132
    {0xFD,0xF1,0xF1,0x71,0x1A,0x0C,0x08,0xF0},
    {0x0F,0x10,0x24,0x74,0x9C,0x8E,0x9F,0x9F},  
    {0x9F,0x9F,0x9F,0x9E,0x40,0x20,0x10,0x0F}

} ;
*/
 // Стандартый шрифт
__flash const unsigned char font_norm[][9] = {         
    
    {0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  Пробел
	{0x03,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  !
	{0x04,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00},    //  "
	{0x07,0x24,0x7E,0x24,0x24,0x7E,0x24,0x00,0x00},    //  #
	{0x06,0x04,0x2A,0x7F,0x2A,0x10,0x00,0x00,0x00},    //  $
	{0x08,0x02,0x05,0x62,0x18,0x26,0x50,0x20,0x00},    //  %
	{0x07,0x36,0x49,0x49,0x56,0x20,0x50,0x00,0x00},    //  &
	{0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  Резерв
	{0x03,0x3E,0x41,0x00,0x00,0x00,0x00,0x00,0x00},    //  (
	{0x03,0x41,0x3E,0x00,0x00,0x00,0x00,0x00,0x00},    //  )
	{0x06,0x14,0x08,0x3E,0x08,0x14,0x00,0x00,0x00},    //  *
	{0x06,0x08,0x08,0x3E,0x08,0x08,0x00,0x00,0x00},    //  +
	{0x04,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0x00},    //  ,
	{0x05,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00},    //  -
	{0x03,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  .
	{0x04,0x60,0x1C,0x03,0x00,0x00,0x00,0x00,0x00},    //  /
	{0x06,0x3E,0x61,0x5D,0x43,0x3E,0x00,0x00,0x00},    //  0
	{0x06,0x04,0x02,0x7F,0x00,0x00,0x00,0x00,0x00},    //  1
	{0x06,0x42,0x61,0x51,0x49,0x46,0x00,0x00,0x00},    //  2
	{0x06,0x22,0x41,0x49,0x49,0x36,0x00,0x00,0x00},    //  3
	{0x06,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,0x00},    //  4
	{0x06,0x27,0x45,0x45,0x45,0x39,0x00,0x00,0x00},    //  5
	{0x06,0x3E,0x45,0x45,0x45,0x38,0x00,0x00,0x00},    //  6
	{0x06,0x01,0x61,0x19,0x07,0x01,0x00,0x00,0x00},    //  7
	{0x06,0x36,0x49,0x49,0x49,0x36,0x00,0x00,0x00},    //  8
	{0x06,0x0E,0x51,0x51,0x51,0x3E,0x00,0x00,0x00},    //  9
	{0x03,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  :
	{0x04,0x80,0x62,0x00,0x00,0x00,0x00,0x00,0x00},    //  ;
	{0x04,0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00},    //  <
	{0x05,0x14,0x14,0x14,0x14,0x00,0x00,0x00,0x00},    //  =
	{0x04,0x22,0x14,0x08,0x00,0x00,0x00,0x00,0x00},    //  >
	{0x06,0x02,0x01,0x51,0x09,0x06,0x00,0x00,0x00},    //  ?
	{0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  Резерв
	{0x06,0x7C,0x12,0x11,0x12,0x7C,0x00,0x00,0x00},    //  A
	{0x06,0x7F,0x49,0x49,0x49,0x3E,0x00,0x00,0x00},    //  B
	{0x06,0x3E,0x41,0x41,0x41,0x22,0x00,0x00,0x00},    //  C
	{0x06,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00,0x00},    //  D
	{0x06,0x7F,0x49,0x49,0x49,0x49,0x00,0x00,0x00},    //  E
	{0x05,0x7F,0x09,0x09,0x01,0x00,0x00,0x00,0x00},    //  F
	{0x06,0x3C,0x42,0x41,0x51,0x72,0x00,0x00,0x00},    //  G
	{0x06,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00,0x00},    //  H
	{0x03,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  I
	{0x06,0x30,0x40,0x40,0x40,0x3F,0x00,0x00,0x00},    //  J
	{0x06,0x7F,0x08,0x14,0x22,0x41,0x00,0x00,0x00},    //  K
	{0x06,0x7F,0x40,0x40,0x40,0x40,0x00,0x00,0x00},    //  L
	{0x07,0x7F,0x02,0x04,0x04,0x02,0x7F,0x00,0x00},    //  M
	{0x06,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00,0x00},    //  N
	{0x06,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00,0x00},    //  O
	{0x06,0x7F,0x09,0x09,0x09,0x06,0x00,0x00,0x00},    //  P
	{0x06,0x3E,0x41,0x61,0xC1,0x3E,0x00,0x00,0x00},    //  Q
	{0x06,0x7F,0x09,0x09,0x19,0x66,0x00,0x00,0x00},    //  R
	{0x06,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x00},    //  S
	{0x06,0x01,0x01,0x7F,0x01,0x01,0x00,0x00,0x00},    //  T
	{0x06,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00,0x00},    //  U
	{0x07,0x07,0x38,0x40,0x40,0x38,0x07,0x00,0x00},    //  V
	{0x08,0x3F,0x40,0x38,0x06,0x38,0x40,0x3F,0x00},    //  W
	{0x06,0x63,0x14,0x08,0x14,0x63,0x00,0x00,0x00},    //  X
	{0x06,0x03,0x04,0x78,0x04,0x03,0x00,0x00,0x00},    //  Y
	{0x06,0x61,0x51,0x49,0x45,0x43,0x00,0x00,0x00},    //  Z
	{0x03,0x7F,0x41,0x00,0x00,0x00,0x00,0x00,0x00},    //  [
	{0x04,0x03,0x1C,0x60,0x00,0x00,0x00,0x00,0x00},    //  \
	{0x03,0x41,0x7F,0x00,0x00,0x00,0x00,0x00,0x00},    //  ]
	{0x06,0x04,0x02,0x01,0x02,0x04,0x00,0x00,0x00},    //  ^
	{0x05,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00},    //  _
	{0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  Резерв
	{0x05,0x20,0x54,0x54,0x78,0x00,0x00,0x00,0x00},    //  a
	{0x05,0x7F,0x44,0x44,0x38,0x00,0x00,0x00,0x00},    //  b
	{0x05,0x38,0x44,0x44,0x44,0x00,0x00,0x00,0x00},    //  c
	{0x05,0x38,0x44,0x44,0x7F,0x00,0x00,0x00,0x00},    //  d
	{0x05,0x38,0x54,0x54,0x58,0x00,0x00,0x00,0x00},    //  e
	{0x04,0x04,0x7E,0x05,0x00,0x00,0x00,0x00,0x00},    //  f
	{0x05,0x18,0xA4,0xA4,0x7C,0x00,0x00,0x00,0x00},    //  g
	{0x05,0x7F,0x04,0x04,0x78,0x00,0x00,0x00,0x00},    //  h
	{0x02,0x7D,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  i
	{0x04,0x40,0x80,0x7D,0x00,0x00,0x00,0x00,0x00},    //  j
	{0x05,0x7F,0x10,0x28,0x44,0x00,0x00,0x00,0x00},    //  k
	{0x03,0x7F,0x40,0x00,0x00,0x00,0x00,0x00,0x00},    //  l
	{0x06,0x7C,0x04,0x7C,0x04,0x78,0x00,0x00,0x00},    //  m
	{0x05,0x7C,0x04,0x04,0x78,0x00,0x00,0x00,0x00},    //  n
	{0x05,0x38,0x44,0x44,0x38,0x00,0x00,0x00,0x00},    //  o
	{0x05,0xFC,0x24,0x24,0x18,0x00,0x00,0x00,0x00},    //  p
	{0x05,0x18,0x24,0x24,0xFC,0x80,0x00,0x00,0x00},    //  q
	{0x04,0x78,0x04,0x04,0x00,0x00,0x00,0x00,0x00},    //  r
	{0x05,0x48,0x54,0x54,0x24,0x00,0x00,0x00,0x00},    //  s
	{0x04,0x04,0x7F,0x44,0x00,0x00,0x00,0x00,0x00},    //  t
	{0x05,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00},    //  u
	{0x06,0x04,0x38,0x40,0x38,0x04,0x00,0x00,0x00},    //  v
	{0x08,0x3C,0x40,0x30,0x08,0x30,0x40,0x3C,0x00},    //  w
	{0x06,0x44,0x28,0x10,0x28,0x44,0x00,0x00,0x00},    //  x
	{0x06,0x04,0x98,0x60,0x18,0x04,0x00,0x00,0x00},    //  y
	{0x06,0x44,0x64,0x54,0x4C,0x44,0x00,0x00,0x00},     //  z
    
    {0x08, 0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0xFF}, //квадратик       123
    {0x08, 0xFF,0x81,0xBD,0xBD,0xBD,0xBD,0x81,0xFF}, //закрашенный квадратик      124
        
    {0x08, 0x01,0x31,0x79,0x79,0x7D,0x7F,0x7D,0x31},  //Верт 125,126 символ;
    {0x08, 0x11,0x11,0x11,0x10,0x10,0x10,0x38,0x10},
        
    {0x08, 0x3E,0x08,0x1C,0x1C,0x7C,0x3E,0x1E,0x1E},  //самолет 127,128 символ;
    {0x08, 0x1E,0x1C,0x18,0x18,0x18,0x1C,0x0E,0x0E},
    {0x06, 0x07,0x05,0x05,0x05,0x07,0x02,0x00,0x00}, // batt 129
    {0x05, 0x01,0x02,0x0f,0x02,0x01,0x00,0x00,0x00}, // antenn 130
    {0x05, 0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00}, // t-gradC 131
    {0x08, 0x0a,0xfe,0xab,0xff,0xfe,0xea,0xe0,0x40}, // RPM 132
    {0x08, 0x3c,0x42,0x85,0x99,0x99,0x85,0x42,0x3c}, // Clock 133
    {0x08, 0x20,0x30,0x38,0x3c,0x38,0x30,0x20,0x00}, // arrow up 134
    {0x08, 0x04,0x0c,0x1c,0x3c,0x1c,0x0c,0x04,0x00}, // arrow down 135

};

     
//------------------------------------------------------
__flash const unsigned char deg12x16[][24] = {
// 0x30 - '0'.
  {0x00, 0xF8, 0xFE, 0x06, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0xFE, 0xF8,
  0x00, 0x07, 0x1F, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x1F, 0x07},
// 0x31 - '1'.
  {0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0e, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x3f, 0x3f, 0x30, 0x30, 0x30, 0x00},
// 0x32 - '2'.
  {0x00, 0x1c, 0x1e, 0x07, 0x03, 0x03, 0x83, 0xc3, 0xe3, 0x77, 0x3e, 0x1c,
  0x00, 0x30, 0x38, 0x3c, 0x3e, 0x37, 0x33, 0x31, 0x30, 0x30, 0x30, 0x30},
// 0x33 - '3'.
  {0x00, 0x0c, 0x0e, 0x07, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e, 0x3c,
  0x00, 0x0c, 0x1c, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x1f, 0x0e},
// 0x34 - '4'.
  {0x00, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0xff, 0xff, 0x00, 0x00,
  0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f, 0x03, 0x03},
// 0x35 - '5'.
  {0x00, 0x3f, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0xe3, 0xc3, 0x83,
  0x00, 0x0c, 0x1c, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x1f, 0x0f},
// 0x36 - '6'.
  {0x00, 0xc0, 0xf0, 0xf8, 0xdc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0x80, 0x00,
  0x00, 0x0f, 0x1f, 0x39, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x1f, 0x0f},
// 0x37 - '7'.
  {0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xc3, 0xf3, 0x3f, 0x0f, 0x03,
  0x00, 0x00, 0x00, 0x00, 0x30, 0x3c, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00},
// 0x38 - '8'.
  {0x00, 0x00, 0xbc, 0xfe, 0xe7, 0xc3, 0xc3, 0xc3, 0xe7, 0xfe, 0xbc, 0x00,
  0x00, 0x0f, 0x1f, 0x39, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x1f, 0x0f},
// 0x39 - '9'.
  {0x00, 0x3c, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0xfe, 0xfc,
  0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x38, 0x1c, 0x0e, 0x07, 0x03, 0x00},
// 0x3a - двоеточие.
  {0x00, 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00}
  };
//------------------------------------------------------
void LCD_setxy(char x,unsigned char y)        // установка координат курсора
{
posx=x;
posy=y;
}
//------------------------------------------------------
void LCD_deg12x16(unsigned char c, unsigned char color)    // вывод символа
{ // c = address of character in the font array
char i, j;
unsigned char b;

for(i=0; i<12; i++) 
  {
  b=deg12x16[c][i];
  for(j=0; j<8; j++) 
    {
    LCD_pixel(posx, posy+j, (~(b ^ color)) & 1);
    b >>= 1;
    }
  posx++;
  }
posy+=8;
posx-=12;
for(i=12; i<24; i++) 
  {
  b = deg12x16[c][i];
  for(j=0; j<8; j++) 
    {
    LCD_pixel(posx, posy+j, (~(b ^ color)) & 1);
    b >>= 1;
    }
  posx++;
  }
}
//------------------------------------------------------
unsigned char LCD_get_char_len(unsigned char ch)
{
return font_norm[ch-32][0];
}
//------------------------------------------------------
void LCD_char(unsigned char ch, unsigned char color)    // вывод символа
{
unsigned char x, y, len, b;
flash unsigned char *p;

//if(posx>75 || posy>40) return;
if(ch=='\t') { posx=72; return; }
p=font_norm[ch-32];
len=*p++; if(len>8) len=8;
for(x=0; x<len; x++) 
  {
  b=*p++;
  for(y=0; y<8; y++) 
    {
    LCD_pixel(posx, posy+y, (~(b ^ color)) & 1);
    b >>= 1;
    }
  posx++; 
  }
}
//------------------------------------------------------
void LCD_frame(unsigned char x)   
{
LCD_line(x-1, posy-1, posx-1, posy-1, 1);
LCD_line(x-1, posy-1, x-1, posy+7, 1);
}
//------------------------------------------------------
void  LCD_wrs (unsigned char*str,unsigned char color) // ВЫВОД СТРОКИ ИЗ ОПЕРАТИВЫ      
{
unsigned char x;
 
x=posx;
while(*str!='\0')  LCD_char(*str++, color);
if(color==0) LCD_frame(x);
}
//------------------------------------------------------
void LCD_wrsf (unsigned char flash*str,unsigned char color) // ВЫВОД СТРОКИ ИЗ ФЛЕША    
{
unsigned char x;

x=posx;
while(*str!='\0') LCD_char(*str++, color);
if(color==0) LCD_frame(x);
}
