hello,
it seems you have a TEXTE LCD ...
so the only way to do bargraph is to define 8 caracters in CGRAM to represent the 8 steps
inside one char ..
you have 20 chars wide LCD => you can get 8x20=160 steps into your bargraph
new 1rst char have only one pixel wide , 8 pixels Height
second char have 2 pixel wide ... 8 pixel height
..and so on
last is a black cractere 8x8
The value to display must be sclaled before to 160 (full range)
then you divide your value by 8 , to write this number of char ( plain char) on the line (if >=1)
following by the rest (of division) to select the CGRAM charctere by %8 (modulo 8)
and add it as last char on the line
(needs some limits checking to do in software .)
example of char definition
on my LCD2119 I2C ..
not used here for bargraph ...
Code:
void Cree_8_cars_CGRAM()
{
unsigned char b1,b2;
I2C1_Start();
I2C1_Wr(LCD_ADR); // i2c slave Adress
I2C1_Wr(0x00);
// Cde Set_CGRAM address to 0 => (0x40 + adresse=0 )
I2C1_Wr(0x40);
// I2C1_Start();
I2C1_Repeated_Start() ;
I2C1_Wr(LCD_ADR); // i2c slave Adress
I2C1_Wr(0x40);// set CGRAM adress
// blanc
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
I2C1_Wr(0b00000000);
// degre C
I2Cx_Wr(0b00000000);
I2Cx_Wr(0b00001110);
I2Cx_Wr(0b00010001);
I2Cx_Wr(0b00001110);
I2Cx_Wr(0b00000000);
I2Cx_Wr(0b00000000);
I2Cx_Wr(0b00000000);
I2Cx_Wr(0b00000000);
// The Euro currency character can be recognized by the 0/1 pattern (see Figure 48)
I2C1_Wr(0x06); // 00110
I2C1_Wr(0x09); // 01001
I2C1_Wr(0x08); // 01000
I2C1_Wr(0x1E); // 11110
I2C1_Wr(0x1E); // 11110
I2C1_Wr(0x08); // 01000
I2C1_Wr(0x09); // 01001
I2C1_Wr(0x06); // 00110
// petit rectangle
I2C1_Wr(0b0000000);
I2C1_Wr(0b0000000);
I2C1_Wr(0b0011111);
I2C1_Wr(0b0010001);
I2C1_Wr(0b0011111);
I2C1_Wr(0b0000000);
I2C1_Wr(0b0000000);
I2C1_Wr(0b0000000);
I2C1_Stop();
}