ok, so here the working code.
part 1 because its to long for one reply...
#define LCD_X_RES 84
#define LCD_Y_RES 48
#define LCD_CACHE_SIZE ((LCD_X_RES * LCD_Y_RES) / 8)
/*--------------------------------------------------------------------------------------------------
Type definitions
--------------------------------------------------------------------------------------------------*/
#define LCD_CMD 0
#define LCD_DATA 1
#define PIXEL_OFF 0
#define PIXEL_ON 1
#define PIXEL_XOR 2
#define FONT_1X 1
#define FONT_2X 2
typedef unsigned int word;
// Mega8 port B pinout for LCD.
int CONTROL_LED=12;
int LCD_POWER_PIN = 11;
int LCD_DC_PIN = 2; // PB0 4 Data Command
int LCD_CE_PIN = 3; // PB2 5 /CS active low chip select ??
int SPI_MOSI_PIN = 4; // PB3 3 Serial line
int LCD_RST_PIN = 5; // PB4 8 /RES RESET
int SPI_CLK_PIN = 6; // PB5 2 CLOCK
int voltometer = 9;
// Public function prototypes
void LcdInit ( void );
void LcdClear ( void );
void LcdUpdate ( void );
void LcdGotoXY ( byte x, byte y );
void LcdChr ( int size, byte ch );
void LcdStr ( int size, byte *dataPtr );
void LcdPixel ( byte x, byte y, int mode );
void LcdLine ( byte x1, byte y1, byte x2, byte y2, int mode );
void LcdSendCmd ( byte data, int cd );
// This table defines the standard ASCII characters in a 5x7 dot format.
// Global Variables
byte LcdCache [ LCD_CACHE_SIZE ];
int LcdCacheIdx;
int LoWaterMark;
int HiWaterMark;
boolean UpdateLcd;
char sign;
byte ser= 0; //from serial port
// This table defines the standard ASCII characters in a 5x7 dot format.
static const byte FontLookup [][5] =
{
{
0x7E, 0x11, 0x11, 0x11, 0x7E }
, // A
{
0x7F, 0x49, 0x49, 0x49, 0x36 }
, // B
{
0x3E, 0x41, 0x41, 0x41, 0x22 }
, // C
{
0x7F, 0x41, 0x41, 0x22, 0x1C }
, // D
{
0x7F, 0x49, 0x49, 0x49, 0x41 }
, // E
{
0x7F, 0x09, 0x09, 0x09, 0x01 }
, // F
{
0x3E, 0x41, 0x49, 0x49, 0x7A }
, // G
{
0x7F, 0x08, 0x08, 0x08, 0x7F }
, // H
{
0x00, 0x41, 0x7F, 0x41, 0x00 }
, // I
{
0x20, 0x40, 0x41, 0x3F, 0x01 }
, // J
{
0x7F, 0x08, 0x14, 0x22, 0x41 }
, // K
{
0x7F, 0x40, 0x40, 0x40, 0x40 }
, // L
{
0x7F, 0x02, 0x0C, 0x02, 0x7F }
, // M
{
0x7F, 0x04, 0x08, 0x10, 0x7F }
, // N
{
0x3E, 0x41, 0x41, 0x41, 0x3E }
// O
, // Y
{
0x61, 0x51, 0x49, 0x45, 0x43 }
//Z
};
/*--------------------------------------------------------------------------------------------------
Name : LcdSendCmd
Description : Sends data to display controller.
Argument(s) : data -> Data to be sent
cd -> Command or data (see/use enum)
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdSendCmd ( byte data, int cd )
{
byte i = 8;
byte mask;
//
if ( cd == LCD_DATA )
{
digitalWrite(LCD_DC_PIN,HIGH);
}
else
{
digitalWrite(LCD_DC_PIN,LOW) ;
}
while(0 < i) {
mask = 0x01 << --i; // get bitmask and move to least significant bit
// cause edge to fall
digitalWrite(SPI_CLK_PIN,LOW); // tick
delayMicroseconds(400);
// set out byte
if(data & mask){ // choose bit
digitalWrite(SPI_MOSI_PIN,HIGH); // send 1
}
else{
digitalWrite(SPI_MOSI_PIN,LOW); // send 0
}
// cause edge to rise
digitalWrite(SPI_CLK_PIN,HIGH); // tock
delayMicroseconds(400);
}
}
/*--------------------------------------------------------------------------------------------------
Name : LcdInit
Description : Performs MCU SPI & LCD controller initialization.
Argument(s) : None.
Return value : None.
--------------------------------------------------------------------------------------------------*/
void LcdInit ( void )
{
int m;
// Toggle display reset pin.
digitalWrite(LCD_RST_PIN,LOW);
delay(40);
digitalWrite(LCD_RST_PIN,HIGH);
// Enable SPI port: No interrupt, MSBit first, Master mode, CPOL->0, CPHA->0, Clk/4
// SPCR = 0x50;
LcdSendCmd( 0x21, LCD_CMD ); // LCD Extended Commands.
LcdSendCmd( 0xB3, LCD_CMD ); // Set LCD Vop (Contrast). //B1
LcdSendCmd( 0x04, LCD_CMD ); // Set Temp coefficent. //0x04
LcdSendCmd( 0x13, LCD_CMD ); // LCD bias mode 1:48. //0x13
LcdSendCmd( 0x20, LCD_CMD ); // LCD Standard Commands, Horizontal addressing mode.
LcdSendCmd( 0x0C, LCD_CMD ); // LCD in normal mode. 0x0d for inverse
// LcdSendCmd( 0x0D, LCD_CMD );
// Reset watermark pointers.
LoWaterMark = LCD_CACHE_SIZE;
HiWaterMark = 0;
LcdClear();
LcdUpdate();
}