I tried to port this lib to Mikropascal but perhaps i've missed out something coz well, it doesn't work on my setup
The lib is here : http://www.libstock.com/projects/view/6 ... ing-cd4094
And the port is as below. The hardware connections are the same as in the libstock schematic. Any help with this would be hugely appreciated.
Code: Select all
unit TwoWireLCD;
const
_LCD_FIRST_ROW = 0x80; //Move cursor to the 1st row
_LCD_SECOND_ROW = 0xC0; //Move cursor to the 2nd row
_LCD_THIRD_ROW = 0x94; //Move cursor to the 3rd row
_LCD_FOURTH_ROW = 0xD4; //Move cursor to the 4th row
_LCD_CLEAR = 0x01; //Clear display
_LCD_RETURN_HOME = 0x02; //Return cursor to home position, returns a shifted display to
//its original position. Display data RAM is unaffected.
_LCD_CURSOR_OFF = 0x0C; //Turn off cursor
_LCD_UNDERLINE_ON = 0x0E; //Underline cursor on
_LCD_BLINK_CURSOR_ON = 0x0F; //Blink cursor on
_LCD_MOVE_CURSOR_LEFT = 0x10; //Move cursor left without changing display data RAM
_LCD_MOVE_CURSOR_RIGHT = 0x14; //Move cursor right without changing display data RAM
_LCD_TURN_ON = 0x0C; //Turn Lcd display on
_LCD_TURN_OFF = 0x08; //Turn Lcd display off
_LCD_SHIFT_LEFT = 0x18; //Shift display left without changing display data RAM
_LCD_SHIFT_RIGHT = 0x1E; //Shift display right without changing display data RAM
var
//LCD_clk: sbit; sfr; external;
//LCD_data: sbit; sfr; external;
LCD_clk: sbit at RB0_bit;
LCD_data: sbit at RB1_bit;
procedure SerialLcd_WriteNibble(d: byte);
procedure Serial_Lcd_Cmd(const Command: byte);
procedure Serial_LCD_Chr(row, col: byte; LCDChar: byte);
procedure Serial_Lcd_Init();
procedure Serial_LCD_Out(row, col: byte; var str: string);
implementation
var
rs: byte;
procedure SerialLcd_WriteNibble(d: byte);
var
i: byte;
begin
LCD_clk := 0;
LCD_data := 0;
for i := 0 to 7 do
begin
LCD_clk := 1;
Delay_Us(10);
LCD_clk := 0;
Delay_Us(10);
end;
LCD_data := 1; //set Q7= 1 for E
LCD_clk := 1;
Delay_Us(10);
LCD_clk := 0;
Delay_Us(10);
LCD_data := rs; //set Q6 for RS
LCD_clk := 1;
Delay_Us(10);
LCD_clk := 0;
Delay_Us(10);
i := 8;
while i > 0 do //8;i>0;i=i>>1)
begin
i := i shr 1;
if (d and i)=1 then
LCD_data := 1
else
LCD_data := 0;
Delay_Us(10);
LCD_clk := 1;
Delay_Us(10);
LCD_clk := 0;
end;
LCD_data := 0; //shift Q0
Delay_Us(10);
LCD_clk := 1;
Delay_Us(10);
LCD_clk := 0;
LCD_data := 1; //now send enable
Delay_Us(10);
LCD_data := 0;
Delay_Us(10);
end;
procedure Serial_Lcd_Cmd(Command: byte);
begin
rs := 0; //because sending command
SerialLcd_WriteNibble(Command shr 4);
Delay_Us(100);
SerialLcd_WriteNibble(Command and 0xF);
if((Command = 0x0C) or (Command = 0x01) or (Command = 0x0E) or (Command = 0x0F) or (Command = 0x10)
or (Command = 0x1E) or (Command = 0x18) or (Command = 0x08) or (Command = 0x14)
or (Command = 0x02)) then
Delay_ms(50);
end;
procedure Serial_LCD_Chr(row, col: byte; LCDChar: byte);
begin
case (row) of
1: Serial_Lcd_Cmd(0x80 + col-1);
2: Serial_Lcd_Cmd(0xC0 + col-1);
3: Serial_Lcd_Cmd(0x94 + col-1);
4: Serial_Lcd_Cmd(0xD4 + col-1);
end;
RS := 1;
SerialLcd_WriteNibble(LCDChar shr 4);
Delay_us(10);
SerialLcd_WriteNibble(LCDChar and 0x0F);
end;
procedure Serial_Lcd_Init();
begin
LCD_Clk := 0;
LCD_data := 0;
rs := 0;
delay_ms(40);
Serial_Lcd_Cmd(0x03);
delay_ms(5);
Serial_Lcd_Cmd(0x03);
delay_ms(5);
Serial_Lcd_Cmd(0x03);
delay_ms(2);
//SerialLcd_WriteNibble(0x02);
Serial_Lcd_Cmd(0x02);
Serial_Lcd_Cmd(0x28); //set LCD_data length 4 bit 2 line
delay_ms(50);
Serial_Lcd_Cmd(0x0C); // set display on cursor oFF blink off to on the cursor E to and on the blink F
delay_ms(50);
// Serial_Lcd_Cmd(0x01); // clear lcd
//delay_ms(250);
Serial_Lcd_Cmd(0x06); // cursor shift direction
delay_ms(50);
Serial_Lcd_Cmd(0x0C); //set ram address
delay_ms(50);
end;
procedure Serial_LCD_Out(row, col: byte; var str: string);
var
p, q, c: byte;
begin
q := strlen(str);
c := col;
for p := 0 to q-1 do
begin
Serial_LCD_Chr(row,c,str[p]);
c := c+1;
end;
row := 1;
col := 1;
end;
end.