Hello!
Help with the code
STM32F103C8 -> I2C1-> LCD
thanks
STM32F103C8 -> I2C1-> LCD
Re: STM32F103C8 -> I2C1-> LCD
Code: Select all
Program MyProject;
{Biblioteca Lcd I2C com CI - PCF8574
Autor: Nelson Lima
MikroC 1.1v
OBS.: Habilitar Biblioteca I2C
OBS2.: Porta I2C2 Pinos PB_10, PB_11
}
const _LCD_FIRST_ROW = 0x80 ; //Move cursor to the 1st row - ok
const _LCD_SECOND_ROW = 0xC0; //Move cursor to the 2nd row - ok
const _LCD_THIRD_ROW = 0x94 ; //Move cursor to the 3rd row - ok
const _LCD_FOURTH_ROW = 0xD4 ; //Move cursor to the 4th row - ok
const _LCD_CLEAR = 0x01; //Clear display - ok
const _LCD_RETURN_HOME = 0x02; //Return cursor to home position, returns a shifted display to
const _LCD_BACKLIGHT_ON = 0x08; //
//its original position. Display data RAM is unaffected. - ok
const _LCD_CURSOR_OFF = 0x0C; //Turn off cursor - ok
const _LCD_UNDERLINE_ON = 0x0E; //Underline cursor on - ok
const _LCD_BLINK_CURSOR_ON = 0x0F; //Blink cursor on - ok
const _LCD_MOVE_CURSOR_LEFT = 0x10; //Move cursor left without changing display data RAM - ok
const _LCD_MOVE_CURSOR_RIGHT = 0x14; //Move cursor right without changing display data RAM - ok
const _LCD_TURN_ON = 0x0C; //Turn Lcd display on - ok
const _LCD_TURN_OFF = 0x08; //Turn Lcd display off - ok
const _LCD_SHIFT_LEFT = 0x18; //Shift display left without changing display data RAM
const _LCD_SHIFT_RIGHT = 0x1E; //Shift display right without changing display data RAM
const ADD = 0x3F;
procedure Lcd_I2C_Cmd(out_char : char);
var I2C_byte: array[1] of char;
begin
// I2C_byte[0] = out_char & 0xF0;
I2C_byte[0] := out_char and 0xF0;
I2C_byte[0].0 := 0;
I2C_byte[0].1 := 0;
I2C_byte[0].2 := 1;
I2C_byte[0].3 := 1;
I2C1_Start();
I2C1_Write(ADD,@I2C_byte,1,END_MODE_RESTART);
I2C_byte[0].2 := 0;
I2C1_Write(ADD,@I2C_byte,1,END_MODE_RESTART);
// I2C_byte[0] := (out_char << 4) & 0xF0;
I2C_byte[0] := out_char shl 4 and 0xF0;
I2C_byte[0].0 := 0;
I2C_byte[0].1 := 0;
I2C_byte[0].2 := 1;
I2C_byte[0].3 := 1;
I2C1_Write(ADD,@I2C_byte,1,END_MODE_RESTART);
I2C_byte[0].2 := 0;
I2C1_Write(ADD,@I2C_byte,1, END_MODE_STOP);
Delay_ms(10);
end;
//Final LCD_I2C_Cmd
procedure Lcd_I2C_Init();
var I2C_bytes: array[1] of char;
begin
Delay_ms(100);
I2C_bytes[0] := 0x30;
I2C_bytes[0].1 := 0;
I2C_bytes[0].2 := 1;
I2C_bytes[0].3 := 1;
I2C1_Start();
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_RESTART);
I2C_bytes[0].2 := 0;
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_RESTART);
Delay_ms(10);
I2C_bytes[0].2 := 1;
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_RESTART);
I2C_bytes[0].2 := 0;
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_RESTART);
Delay_ms(10);
I2C_bytes[0] := 0x20;
I2C_bytes[0].2 := 1;
I2C1_Is_Idle();
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_RESTART);
I2C_bytes[0].2 := 0;
I2C1_Is_Idle();
I2C1_Write(ADD,@I2C_bytes,1,END_MODE_STOP);
Delay_ms(10);
LCD_I2C_Cmd(0x28);
Delay_ms(10);
LCD_I2C_Cmd(0x0F);
Delay_ms(10);
LCD_I2C_Cmd(0x06);
Delay_ms(10);
LCD_I2C_Cmd(0x01);
Delay_ms(10);
end;
//Final do I2C_Lcd_Init
procedure Lcd_I2C_Chr_CP(out_char :byte);
var
bytes: array[1] of byte;
begin
bytes[0] := out_char and 0xF0;
bytes[0].0 := 1;
bytes[0].1 := 0;
bytes[0].2 := 1;
bytes[0].3 := 1;
I2C1_Start();
I2C1_Write(ADD,@bytes,1,END_MODE_RESTART);
bytes[0].2 := 0;
I2C1_Write(ADD,@bytes,1,END_MODE_RESTART);
// byt[0] := (out_char << 4) & 0xF0;
bytes[0] := (out_char shl 4) and 0xF0;
bytes[0].0 := 1;
bytes[0].1 := 0;
bytes[0].2 := 1;
bytes[0].3 := 1;
I2C1_Write(ADD,@bytes,1,END_MODE_RESTART);
bytes[0].2 := 0;
I2C1_Write(ADD,@bytes,1,END_MODE_STOP);
Delay_ms(10);
end;
//Final da Lcd_I2C_Chr_CP
procedure Lcd_I2C_Out_CP(var txt : string);
begin
// while text do
begin
// Lcd_I2C_Chr_CP(StrToInt(@txt));
// text++;
end;
end;
//Final do Lcd_I2C_Out_CP
procedure Lcd_I2C_Chr(row, column: word; out_char: byte);
begin
case row of
1:Lcd_I2C_Cmd(0x80 + (column - 1));
//break;
2:Lcd_I2C_Cmd(0xC0 + (column - 1));
// break;
3:Lcd_I2C_Cmd(0x94 + (column - 1));
// break;
4:Lcd_I2C_Cmd(0xD4 + (column - 1));
// break;
end;
Lcd_I2C_Chr_CP(out_char);
end;
//Final do Lcd_I2C_Chr
procedure Lcd_I2C_Out(Row, Column: Word; var txt : String);
var
res, col:Word;
S:string[15];
begin
Col:= Column;
S:= txt;
for res := 1 to length(S) do
begin
Lcd_I2C_Chr(Row, res, StrToShort(S));
end;
end;
////-----------------------------------------------------------------------------------------------
begin
I2C1_Init_Advanced(400000, @_GPIO_MODULE_I2C1_PB67);
I2C1_Init();
Lcd_I2C_Init();
Lcd_I2C_Cmd(_LCD_CLEAR);
Lcd_I2C_Cmd(_LCD_CURSOR_OFF);
Lcd_I2C_Out(1,4,'World');
Delay_ms(1000);
Lcd_I2C_Cmd(_LCD_CLEAR);
while TRUE do
Lcd_I2C_Out(2,5,'1234567890');
end.
- Attachments
-
- 20191222_121044.jpg (2.96 MiB) Viewed 2091 times
-
- Posts: 1
- Joined: 04 Feb 2012 15:47
Re: STM32F103C8 -> I2C1-> LCD
Which are the changes that you made to fix it