Economy of scale.
Buy 100,000 chips that will do for all displays at say $0.10 each, or buy 50,000 of one chip at, say, $0.15 and 50,000 of another chip at $0.15 each.
(figures purely fictional - for illustration only)
You do the maths.
While it's not 100% perfect for every display, it does mean that they are cheaper, which is good for all of us.
Your code is missing some initialization commmands.
lcd_init from http://www.8051projects.net/lcd-interfacing/lcd-4-bit-programming.php actually sends this sequence:
void initHD44780_4bit(void)
{
// D7-D4 connected, D3-D0 no connect. High nybble is sent first. Function set DL=0.
// HD44780 command 0x30-0x33 = Function set: DL=1_8 bit interface, N=0_1 line, F=0_5x7 font
sendHD44780command(0x30);
// HD44780 command 0x20-0x23 = Function set: DL=0_4 bit interface, N=0_1 line, F=0_5x7 font
sendHD44780command(0x20);
// HD44780 command 0x28-0x2B = Function set: DL=0_4 bit interface, N=1_2 lines, F=0_5x7 font
sendHD44780command(0x28); //4-bit, 2 line, 5x7 dots
// HD44780 command 0x0C = Display On/Off Control: D=1_display enabled, C=0_hide cursor, B=0_unblinking cursor
sendHD44780command(0x0C); // Display ON cursor OFF
// HD44780 command 0x06 = Entry mode set: I/D=1_increment, S=0_noShift no display shift
sendHD44780command(0x06); // Set entry mode (Auto increment)
// HD44780 command 0x80-0xBF = display line 1
sendHD44780command(0x80); // Bring cursor to line 1
}
Note that in "nybble mode" (4-bit interface), the most significant nybble is sent first. So I strongly suggest you swap your writeToBus arguments, putting the MSB first... that makes it easier to understand when reading the HD44780 data sheet.
// suggested wrapper method for Mattia_98's writeToBus function -- MarkU
void sendHD44780command(char data)
{
digitalWrite(RS, 0);//Turn RS Mode off
writeToBus(
((data >> 0) & 0x0F), // low nybble is send second
((data >> 4) & 0x0F) // high nybble is sent first
);
}
// suggested wrapper method for Mattia_98's writeToBus function -- MarkU
void sendHD44780data(char data)
{
digitalWrite(RS, 1);//Turn RS Mode on
writeToBus(
((data >> 0) & 0x0F), // low nybble is send second
((data >> 4) & 0x0F) // high nybble is sent first
);
}
Then after the initial call to initHD44780_4bit()
, you should send some data, so you can see whether the display is actually working.
// send test message to HD44780
void helloWorld(void)
{
sendHD44780data('H');
sendHD44780data('e');
sendHD44780data('l');
sendHD44780data('l');
sendHD44780data('o');
sendHD44780data(' ');
sendHD44780data('w');
sendHD44780data('o');
sendHD44780data('r');
sendHD44780data('l');
sendHD44780data('d');
sendHD44780data('!');
}
This should be enough to get you started.
Cheers -- Mark
Best Answer
Save your samples into an array, then plot each ADC value as the y value, and increment the x value.
Something like the code below (
int8_t = unsigned char typedef
):You can interpolate between the pixels if desired (you need a draw_line function - google for code), then do something like: