#define GLCD_RS PIN_E1           	  //kijelzõ beállítások
#define GLCD_RW PIN_E0
#define GLCD_E PIN_E2
#define GLCD_CS PIN_B4
#define GLCD_RST PIN_B3


int1 ON = true;
int1 OFF = false;

void lcd_strobe_enable(void) {
   output_high(GLCD_E);
   delay_us (3);
   output_low(GLCD_E);
   delay_us (3);   
}


void lcd_wait_busy(void) {
   delay_us(3);
}


void lcd_write_command(int8 command, int8 data) {
   lcd_wait_busy();

	output_low(GLCD_RW);
   output_high(GLCD_RS);
   output_low(GLCD_CS);

   output_d(command);
   delay_us (3);
   lcd_strobe_enable();
   delay_us (3);   

   output_low(GLCD_RW);
   output_low(GLCD_RS);
   output_d(data);
   delay_us (3);
   lcd_strobe_enable();
   delay_us (3);
}



void lcd_graphics_move(int16 x, int16 y) {
   int16 pos;
   int8 LA, UA;

   /* Calculate the raw address in terms of bytes on the screen */
   pos = (_mul(y, 480)+x)/8;
   LA = make8(pos, 0);
   UA = make8(pos, 1);
   
   /* Move the cursor to the new address */
   lcd_write_command(0x0A, LA);
   lcd_write_command(0x0B, UA);
}


void glcd_pixel8(int16 x, int16 y, int8 pixel8) {
   lcd_graphics_move(x,y);
   lcd_write_command(0x0c, pixel8);
}



void glcd_pixel(int16 x, int16 y)
{
   int16 pos;
   
   lcd_graphics_move(x, y);
   pos = x%8;
      lcd_write_command(0x0F, pos);
}



void glcd_init()
{
   // Initialze some pins
   output_low(GLCD_RST);
   output_low(GLCD_E);
   output_low(GLCD_RS);
   output_high(GLCD_CS);
   output_d(0x00);
   delay_ms(2);
   output_high(GLCD_RST);
   delay_ms(2);
   lcd_write_command(0x00, 0x32);  //0x32
   lcd_write_command(0x01, 0x77);  //0x77
   lcd_write_command(0x02, 0x3B);  //0x3B
   lcd_write_command(0x03, 0x3F);  //0x3F
   lcd_write_command(0x04, 0x08);  //0x07
   lcd_write_command(0x08, 0x00);
   lcd_write_command(0x09, 0x00);
   lcd_write_command(0x0A, 0x00);
   lcd_write_command(0x0B, 0x00);
   glcd_fillScreen(false);               // Clear the display
}



void char_fillScreen(short mode) {
   long i;
   /* Move cursor to home (top left corner) */
   move_char(0, 0);
   /* Draw blank or filled chars to ocucpy the entire screen */
   for (i = 0; i < 160; i++)
      if (mode == OFF)
         lcd_write_command(0x0c, 0x20);
      else
         lcd_write_command(0x0c, 0xFF);
} 



void lcd_write(int8 command, int8 data) {
   lcd_wait_busy();

   output_low(GLCD_RW);
   output_high(GLCD_RS);
   output_low(GLCD_CS);

   output_d(command);
   delay_us (3);
   lcd_strobe_enable();
   delay_us (3);   

   output_low(GLCD_RW);
   output_low(GLCD_RS);
   output_d(data);
   delay_us (3);
}







void main(void)
{

   SET_TRIS_B(0x19);         //bemenetek kivéve b3-b4
   SET_TRIS_D(0xFF);         //minden bemenet
   SET_TRIS_E(0xFF);   		 //minden bemenet 
   SET_TRIS_C(0xFF);   		 //minden bemenet 


while (TRUE) {

delay_ms(50);
glcd_init();
delay_ms(100);

glcd_fillScreen(true);  
delay_ms(50);

glcd_pixel(12, 12);



for(;;)
   {

delay_ms(1000); 




   }}
}










