graphical lcd (nokia 3310)

part 3 and final:

/*--------------------------------------------------------------------------------------------------
 
 Name         :  LcdPixel
 
 Description  :  Displays a pixel at given absolute (x, y) location.
 
 Argument(s)  :  x, y -> Absolute pixel coordinates
 mode -> Off, On or Xor. See enum.
 
 Return value :  None.
 
 --------------------------------------------------------------------------------------------------*/
void LcdPixel ( byte x, byte y, int mode )
{
  word  index;
  byte  offset;
  byte  data;

  if ( x > LCD_X_RES ) return;
  if ( y > LCD_Y_RES ) return;

  index = ((y / 8) * 84) + x;
  offset  = y - ((y / 8) * 8);

  data = LcdCache[index];

  if ( mode == PIXEL_OFF )
  {
    data &= (~(0x01 << offset));
  }
  else if ( mode == PIXEL_ON )
  {
    data |= (0x01 << offset);
  }
  else if ( mode  == PIXEL_XOR )
  {
    data ^= (0x01 << offset);
  }

  LcdCache[index] = data;

  if ( index < LoWaterMark )
  {
    //  Update low marker.
    LoWaterMark = index;
  }

  if ( index > HiWaterMark )
  {
    //  Update high marker.
    HiWaterMark = index;
  }
}

/*--------------------------------------------------------------------------------------------------
 
 Name         :  LcdLine
 
 Description  :  Draws a line between two points on the display.
 
 Argument(s)  :  x1, y1 -> Absolute pixel coordinates for line origin.
 x2, y2 -> Absolute pixel coordinates for line end.
 mode   -> Off, On or Xor. See enum.
 
 Return value :  None.
 
 --------------------------------------------------------------------------------------------------*/
void LcdLine ( byte x1, byte y1, byte x2, byte y2, int 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;

  LcdPixel( x1, y1, mode );

  if ( dx > dy )
  {
    fraction = dy - (dx >> 1);
    while ( x1 != x2 )
    {
      if ( fraction >= 0 )
      {
        y1 += stepy;
        fraction -= dx;
      }
      x1 += stepx;
      fraction += dy;
      LcdPixel( x1, y1, mode );
    }
  }
  else
  {
    fraction = dx - (dy >> 1);
    while ( y1 != y2 )
    {
      if ( fraction >= 0 )
      {
        x1 += stepx;
        fraction -= dy;
      }
      y1 += stepy;
      fraction += dx;
      LcdPixel( x1, y1, mode );
    }
  }

  UpdateLcd = true;
}

/*--------------------------------------------------------------------------------------------------
 
 Name         :  LcdUpdate
 
 Description  :  Copies the LCD cache into the device RAM.
 
 Argument(s)  :  None.
 
 Return value :  None.
 
 --------------------------------------------------------------------------------------------------*/
void LcdUpdate ( void )
{
  int i;
  
//always update everything for the moment
LoWaterMark = 0;
HiWaterMark = LCD_CACHE_SIZE - 1;


  if ( LoWaterMark < 0 ){
    LoWaterMark = 0;
  }
  else if ( LoWaterMark >= LCD_CACHE_SIZE ){
    LoWaterMark = LCD_CACHE_SIZE - 1;
  }

  if ( HiWaterMark < 0 ){
    HiWaterMark = 0;
  }
  else if ( HiWaterMark >= LCD_CACHE_SIZE ){
    HiWaterMark = LCD_CACHE_SIZE - 1;
  }

  //  Set base address according to LoWaterMark.
  LcdSendCmd( 0x80 | (LoWaterMark % LCD_X_RES), LCD_CMD );
  LcdSendCmd( 0x40 | (LoWaterMark / LCD_X_RES), LCD_CMD );

  //  Serialize the video buffer.
  for ( i = LoWaterMark; i <= HiWaterMark; i++ )
  {
    LcdSendCmd( LcdCache[i], LCD_DATA );
  }

  //  Reset watermark pointers.
  LoWaterMark = LCD_CACHE_SIZE - 1;
  HiWaterMark = 0;

  UpdateLcd = false;
}




void setup() {

  beginSerial(19200);
  //power the control led
  pinMode(CONTROL_LED,OUTPUT); 


  pinMode(LCD_RST_PIN,OUTPUT); 
  pinMode(LCD_DC_PIN ,OUTPUT);
  pinMode(LCD_CE_PIN ,OUTPUT);
  pinMode(SPI_MOSI_PIN ,OUTPUT);
  pinMode(SPI_CLK_PIN,OUTPUT);
 pinMode(voltometer,OUTPUT);



  //power the display
  pinMode(LCD_POWER_PIN,OUTPUT); 
  //start
  digitalWrite(CONTROL_LED, HIGH); 
  analogWrite(voltometer, 150);
  LcdInit();
  




}

void loop() {
 
LcdClear();
delay(100);
LcdGotoXY ( 7, 3 );   
     
LcdStr(1, "OK");

LcdUpdate();

delay(500);




}

hope you can work with it.