|
|
View previous topic :: View next topic |
Author |
Message |
myloudharim
Joined: 13 Nov 2017 Posts: 10 Location: philly
|
LCD2x16 Custom Character does not work |
Posted: Sat Dec 19, 2020 9:15 pm |
|
|
Hello everyone, i wanna try replicate and display custom character on a 2x16 lcd. I inspired from some examples shared by members of view topic
but without success, all of examples i saw are not working. Anybody knows why, do i have any mistake on my code?
I include LCD.c
EN --->RD0
RS --->RD1
RW--->RD2
D0 : D3 --->GND
D4 --->RD4
D5---->RD5
D6---->RD6
D7---->RD7
here is my code
Code: |
#include "W:\CCS Projects\16f877_LCD_2x16.h"
#include <lcd.c>
//-----------------------------------------------------------
const int8 lcd_custom_chars[] =
{
// Char Number 1 -- Degrees
0b00001100, // ....OO..
0b00010010, // ...O..O.
0b00010010, // ...O..O.
0b00001100, // ....OO..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
};
void lcd_load_custom_chars(void)
{
int8 i;
lcd_send_byte(0, 0x40); // Set address counter pointing to CGRAM address 0.
// Load custom lcd character data into CGRAM.
// It can only hold a maximum of 8 custom characters.
for(i = 0; i < 8; i++)
{
lcd_send_byte(1, lcd_custom_chars[i]);
}
// Set address counter pointing back to the DDRAM.
lcd_send_byte(0, 0x80);
}
//-----------------------------------------------------------
void main(){
lcd_init();
lcd_gotoxy(1,1);
lcd_load_custom_chars();
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sun Dec 20, 2020 2:15 am |
|
|
OK. You have loaded a custom character, but you don't show where
you ask the display to show this. Your new character is character 0. Now to
send 0 to the display, you have to use a hex or octal escape, to output this.
So, something like:
Code: |
//load your character, then
printf(lcd_putc,"\FCustom = \000");
|
Sends the 000 character to be displayed.
As a comment, I'd suggest you add a little delay before you initialise the
display at the start of your code. A lot of LCD's need a bit more time than
the PIC to wake up... |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Tue Dec 22, 2020 8:38 am |
|
|
Here's code I used many years ago which is probably the same as yours based on what I see...
Question: Can you display anything on the LCD? Can you display "Hello"? When/if that works, the go to the next step of creating custom characters...
Code: |
//************************************
In your .h file:
//************************************
#define LEFT_ARROW 0
#define RIGHT_ARROW 1
#define YOUR_NEXT_CHAR1 2
#define YOUR_NEXT_CHAR2 3
... and so on up to 7 (0-8)...
const int8 lcd_custom_chars[] =
{
// Char 0 -- Left arrow
0b00000001, // ---....O
0b00000011, // ---...OO
0b00000101, // ---..O.O
0b00001001, // ---.O..O
0b00000101, // ---..O.O
0b00000011, // ---...OO
0b00000001, // ---....O
0b00000000, // --------
// Char 1 -- Right arrow
0b00010000, // ---O....
0b00011000, // ---OO...
0b00010100, // ---O.O..
0b00010010, // ---O..O.
0b00010100, // ---O.O..
0b00011000, // ---OO...
0b00010000, // ---O....
0b00000000, // --------
// Char 2 -- YOUR_NEXT_CHAR1
... put bit pattern here
// Char 3 -- YOUR_NEXT_CHAR2
... put bit pattern here
// add more here following the pattern above...
}
void lcd_LoadCustomChars( void );
//************************************
In your .c file:
//************************************
main()
{
// Whatever code
lcd_init();
lcd_LoadCustomChars();
// Whatever code
// When you want to use it:
lcd_gotoxy( 1, 1 );
lcd_putc( LEFT_ARROW );
lcd_gotoxy( 5, 1 );
lcd_putc( RIGHT_ARROW );
lcd_gotoxy( 10, 1 );
lcd_putc( YOUR_NEXT_CHAR1 );
lcd_gotoxy( 15, 1 );
lcd_putc( YOUR_NEXT_CHAR2 );
// Whatever code
}
//---------------------------------------
// lcd_LoadCustomChars
//
// Load custom characters in LCD CGRAM.
//
//---------------------------------------
void lcd_LoadCustomChars( void )
{
int8 i;
// Set address counter pointing to CGRAM address 0.
lcd_send_byte( 0, 0x40 );
// Load custom lcd character data into CGRAM.
// It can only hold a maximum of 8 custom characters.
for(i = 0; i < sizeof( lcd_custom_chars ); i++)
{
lcd_send_byte( 1, lcd_custom_chars[i] );
}
// Set address counter pointing back to the DDRAM.
lcd_send_byte(0, 0x80);
}
|
I think that's pretty much it. This was for the <EA DIP204-4NLED> LCD display but they're pretty much all the same based-off the HD44780.
Ben |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|