program S55lcd;
//Nem ment vele
{const init:array[1..66] of byte=($FD,$FD,$FD,$FD,$EF,$00,$EE,$04,$1B,$04,$FE,$FE,$FE,$FE,$FE,$90,$4A,$04,
                            $7F,$3f,$EE,$04,$43,$06,
                            $EF,$90,$09,$83,$08,$00,$0B,$AF,$0A,$00,$05,$00,$06,$00,
                            $07,$00,$EF,$00,$EE,$0C,$EF,$90,$00,$80,$EF,$B0,$49,$02,
                            $EF,$00,$7F,$01,$E1,$81,$E2,$02,$E2,$76,$E1,$83,$80,$01);}
                            
// Elvileg ez egy jo inicializalo resz
const init:array[1..164] of byte=($F4, $90, $B3, $A0, $D0, $F0, $E2, $D4, $70, $66,
                                 $B2, $BA, $A1, $A3, $AB, $94, $95, $95, $95, $F5,
                                 $90, $F1, $00, $10, $22, $30, $45, $50, $68, $70,
                                 $8A, $90, $AC, $B0, $CE, $D0, $F2, $0F, $10, $20,
                                 $30, $43, $50, $66, $70, $89, $90, $AB, $B0, $CD,
                                 $D0, $F3, $0E, $10, $2F, $30, $40, $50, $64, $70,
                                 $87, $90, $AA, $B0, $CB, $D0, $F4, $0D, $10, $2E,
                                 $30, $4F, $50, $F5, $91, $F1, $01, $11, $22, $31,
                                 $43, $51, $64, $71, $86, $91, $A8, $B1, $CB, $D1,
                                 $F2, $0F, $11, $21, $31, $42, $51, $63, $71, $85,
                                 $91, $A6, $B1, $C8, $D1, $F3, $0B, $11, $2F, $31,
                                 $41, $51, $62, $71, $83, $91, $A4, $B1, $C6, $D1,
                                 $F4, $08, $11, $2B, $31, $4F, $51, $80, $94, $F5,
                                 $A2, $F4, $60, $F0, $40, $50, $C0, $F4, $70, $F0,
                                 $81, $F4, $B3, $A0, $F0, $06, $10, $20, $30, $F5,
                                 $0F, $1C, $2F, $34, $f0, $0f, $00, $0f, $00, $f5,
                                 79, 4, 111, 6);

//Ez sem jo
{const init:array[1..139] of byte=($F4 , $90 , $B3 , $A0 , $D0,
$F0 , $E2 , $D4 , $70 , $66 , $B2 , $BA , $A1 , $A3 , $AB , $94 , $95 , $95 , $95,
$F5 , $90,
$F1 , $00 , $10 , $22 , $30 , $45 , $50 , $68 , $70 , $8A , $90 , $AC , $B0 , $CE , $D0,
$F2 , $0F , $10 , $20 , $30 , $43 , $50 , $66 , $70 , $89 , $90 , $AB , $B0 , $CD , $D0,
$F3 , $0E , $10 , $2F , $30 , $40 , $50 , $64 , $70 , $87 , $90 , $AA , $B0 , $CB , $D0,
$F4 , $0D , $10 , $2E , $30 , $4F , $50,
$F5 , $91,
$F1 , $01 , $11 , $22 , $31 , $43 , $51 , $64 , $71 , $86 , $91 , $A8 , $B1 , $CB , $D1,
$F2 , $0F , $11 , $21 , $31 , $42 , $51 , $63 , $71 , $85 , $91 , $A6 , $B1 , $C8 , $D1,
$F3 , $0B , $11 , $2F , $31 , $41 , $51 , $62 , $71 , $83 , $91 , $A4 , $B1 , $C6 , $D1,
$F4 , $08 , $11 , $2B , $31 , $4F , $51,
$80 , $94,
$F5 , $A2,
$F4 , $60,
$F0 , $40 , $50 , $C0,
$F4, $70);
}
                            
var vill:byte;
    adat:byte;
    i:word;
    
{// Software SPI module connections
var SoftSpi_SDI : sbit at RA4_bit;
var SoftSpi_SDO : sbit at RC0_bit;
var SoftSpi_CLK : sbit at RC1_bit;

var SoftSpi_SDI_Direction : sbit at TRISA4_bit;
var SoftSpi_SDO_Direction : sbit at TRISC0_bit;
var SoftSpi_CLK_Direction : sbit at TRISC1_bit;
// End Software SPI module connections}

procedure interrupt;
begin
    INTCON := $20;
    inc(vill);
    if vill mod 10=0 then PORTB.5:=1 // Megy-e a pic rendesen
                    else PORTB.5:=0;
end;

procedure kiir(adat:byte); //SPI kuldes 8bit
var j:byte;
begin
for j:=0 to 7 do
begin
  PORTC.1:=0;
  if adat and 128 then PORTC.0:=1
                  else PORTC.0:=0;
  PORTC.1:=1;
  adat:=adat shl 1;
end;
  PORTC.1:=0;
end;

procedure lcdc(adat:byte); //lcd parancs kuldes
begin
   PORTC.4:=0;
   PORTC.2:=1;
   kiir(adat);
   PORTC.4:=1;
end;

procedure lcdd(adat:byte); //lcd adat kuldes
begin
   PORTC.4:=0;
   PORTC.2:=0;
   kiir(adat);
   PORTC.4:=1;
end;

begin
{ PORTC.0 adat
  PORTC.1 clk
  PORTC.2 adat/parancs
  PORTC.3 reset
  PORTC.4 Chip enable}
   
  OPTION_REG := %10000111;
  TMR0:=0;
  INTCON := $A0;
  TRISB.5:=0;
  TRISC:=0;
  vill:=0;
  PORTB.5:=1;
  PORTC:=1;
  while true do
  begin
     PORTC.4:=1;         //deselect chip
     PORTC.1:=0;      //clk le
     PORTC.2:=1;      //parancs mod;
     PORTC.3:=0;       //reset
     delay_ms(100);
     PORTC.3:=1;         //reset vege
     delay_ms(100);
     PORTC.4:=0;     //chip enab.
     for i:=1 to 164 do          //inicializalo byteok kuldese
     begin
       lcdc(INIT[i]);
       //delay_ms(1);
     end;
     PORTC.4:=1;
     delay_ms(1);
     PORTC.4:=0;
     delay_ms(1);

     lcdc($ef);lcdc($90);lcdc($00);lcdc($00);
     
  delay_ms(10000);
  
  end;
end.
