/* Renders the contents of the pixel buffer on the LCD.  */
void sharpmemRefresh(void)
/* Renders the contents of the pixel buffer on the LCD.  */
void sharpmemRefresh(void)
{
  uint16_t i, totalbytes, currentline, oldline;  
  totalbytes = (SHARPMEM_LCDWIDTH * SHARPMEM_LCDHEIGHT) / 8;
  SET_CS;
  sharpmemSendByte(SHARPMEM_BIT_WRITECMD | _sharpmem_vcom);
  TOGGLE_VCOM;
  oldline = currentline = 1;
  sharpmemSendByte(sharpmemSwap(currentline));
  for (i=0; i<totalbytes; i++)
  {
    sharpmemSendByte(sharpmemSwap(_sharpmembuffer[i]));
    currentline = ((i+1)/(SHARPMEM_LCDWIDTH/8)) + 1;
    if(currentline != oldline)
    {
      sharpmemSendByte(0x00);
      if (currentline <= SHARPMEM_LCDHEIGHT)
      {
        sharpmemSendByte(sharpmemSwap(currentline));
      }
      oldline = currentline;
    }
  }
  sharpmemSendByte(0x00);
  CLR_CS;
}