Problem s LCD 16x2
Jan Waclawek
konfera@efton.sk
Středa Září 16 18:27:25 CEST 2009
A RW?
Predpokladajuc, ze RW je na PORTB.1
var portBShdw: byte;
dummy: byte;
procedure PulseE;
begin
portBShdw := portBShdw AND 0xF7; { E up }
PORTB := portBShdw;
Delay_us(1);
portBShdw := portBShdw OR 0x08; { E down }
PORTB := portBShdw;
end;
procedure OutNibble(b: byte);
begin
portBShdw := portBShdw AND 0xFB; { RS down }
PORTB := portBShdw;
portBShdw := (portBShdw AND 0x0F) OR b; { data }
PORTB := portBShdw;
PulseE;
portBShdw := portBShdw OR 0x04; { RS up }
PORTB := portBShdw;
end;
procedure DisplayWriteCommand(b: byte);
begin
portBShdw := portBShdw AND 0xFB; { RS down }
PORTB := portBShdw;
portBShdw := (portBShdw AND 0x0F) OR (b SHL 4); { lower data }
PORTB := portBShdw;
PulseE;
portBShdw := (portBShdw AND 0x0F) OR (b AND 0xF0); { upper data }
PORTB := portBShdw;
PulseE;
portBShdw := portBShdw OR 0x04; { RS up }
PORTB := portBShdw;
end;
function DisplayReadStatus: byte;
begin
----- sem musi prist nieco co sposobi, ze horne bity portu budu citatelne
portBShdw := portBShdw AND 0xFB; { RS down }
portBShdw := portBShdw OR 0x02; { WR up }
PORTB := portBShdw;
portBShdw := portBShdw AND 0xF7; { E up }
PORTB := portBShdw;
Delay_us(1);
DisplayReadStatus := PORTB; ----- toto samozrejme takto asi nepojde... vid zaciatok rutiny
portBShdw := portBShdw OR 0x08; { E down }
PORTB := portBShdw;
portBShdw := portBShdw AND 0xFD; { WR down }
portBShdw := portBShdw OR 0x04; { RS up }
PORTB := portBShdw;
----- teraz treba nastavit znova tie horne bity na zapis
end;
{main} begin
portBShdw := 0xFF;
PORTB := PortBShdw;
Delay_m(100); { initial wait until LCD resets itself }
portBShdw := portBShdw AND 0xF5; { E and RW down - we are going to write to registers now}
OutNibble(0x30);
Delay_m(10);
OutNibble(0x30);
Delay_m(1);
OutNibble(0x30);
Delay_m(1);
OutNibble(0x20);
Delay_m(1);
dummy := DisplayReadStatus; {black magic, but if there is no read in the 8-bit mode, some of the commands get not executed until this is called... and characters are not written correctly...}
DisplayWriteCommand(0x08); // 0000 1000 (Display off)
Delay_m(1);
DisplayWriteCommand(0x01); // 0000 0001 (Display clear)
Delay_m(2);
DisplayWriteCommand(0x02); // 0000 0010 (Cursor home)
Delay_m(2);
DisplayWriteCommand(0x06); // 0000 0110 (Entry Mode Set: increment, no shift)
Delay_m(1);
DisplayWriteCommand(0x0C); // 0000 1100 (Display on)
Delay_m(1);
--- a sem pride nejaky normalny vypis
end;
Pochopitelne to nemam ako vyskusat, mozno som tam urobil aj nejake chyby, ale na uvod takto nejako.
wek
----- Original Message ---------------
>na porty jednoduse:
>
>na cely port:
>PORTB := 0xff;
>na bit
>PORTB.1 := _TRUE;
>
>displej visi takhle:
>LCD_RS : PORTB.2
>LCD_EN : PORTB.3;
>
>LCD_D4 : PORTB.4;
>LCD_D5 : PORTB.5;
>LCD_D6 : PORTB.6;
>LCD_D7 : PORTB.7;
>
>delay:
>sto mikrosekund:
>Delay_us(100);
>sto milisekund:
>Delay_m(100);
>
>
Další informace o konferenci Hw-list