|
|
View previous topic :: View next topic |
Author |
Message |
pg1995
Joined: 05 Apr 2014 Posts: 31
|
working with 16x2 LCD |
Posted: Fri Aug 08, 2014 8:43 pm |
|
|
Hi
These are the details:
PIC 18F46K22
PIC C Compiler (v5.008)
PICKit 3
Using internal oscillator @64 MHz with PLL enabled
Please have a look on the video below.
This is the video w1.
This is the video w2.
This is the Proteus simulation of w2.
Let's focus only on "w2".
This is the code I was using for video "w2".
Code: |
#include <18f46k22.h>
#fuses PLLEN, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT,NOLVP, INTRC
#use delay(internal=64000000)
#include <flex_lcd_original.c>
void main() {
delay_ms(500);
lcd_init();
printf(lcd_putc, "\f");
output_low(pin_D7);
while(TRUE) {
output_toggle(pin_d7);
delay_ms(5000);
delay_ms(5000);
printf(lcd_putc,"\fHello on first");
delay_ms(5000);
printf(lcd_putc,"\nBye on second");
}
}
|
The flex_lcd_original is the code by PCM programmer for 16x2 LCD from this post.
My main question is about flex_lcd_original driver but before that I need to confirm few other things.
Are the settings below correct. I need to run internal oscillator at 64 MHZ.
Code: |
#fuses PLLEN, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, INTRC
#use delay(internal=64000000)
|
By the way, I don't really know the exact difference between "INTRC" and "INTRC_IO" but in my case INTRC_IO was creating problems. What could be the reason? I have read that using INTRC_IO leaves both oscillator pins to be used as normal IO pins. This post might be helpful here. Thank you.
Best wishes
PG |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Aug 09, 2014 9:09 am |
|
|
All the 'regulars' here KNOW Proteus is FULL of bugs, errors and faulty DRCs so it's no surprise it doesn't work.....
somethings that are horribly wrong with the 'simulation'
1) no power to PIC
2) PIC not grounded
3) no current limiting resistor for LED
4) Vee of LCD tied low, though 'some' LCD modules this is OK, most need +-.5VEE
That compiler version is 'beta', very young and has bugs.
intrc_io, means use the internal RC oscillator AND allow the 'clock' pins to be used for I/O purposes.
Normally the first program you create is the simple '1Hz flashing LED' program.It confirms that hardware and software are correct.Until that happens, there's no point adding LCD functions.
so
recode/recompile/retest/report back
jay |
|
|
pg1995
Joined: 05 Apr 2014 Posts: 31
|
|
Posted: Sat Aug 09, 2014 7:54 pm |
|
|
Thanks a lot.
Anyway, my question wasn't about Proteus simulation. Perhaps, you missed the other videos where I showed the same circuit in real hardware. Proteus doesn't provide Vdd and Vss pins. In hardware I did use a resistor with LED.
Reporting back: LED was blinking at the intended frequency so the code had been compiled correctly.
Best wishes
PG |
|
|
shahrokh_m
Joined: 30 Jun 2014 Posts: 8
|
|
Posted: Sat Sep 13, 2014 5:56 am |
|
|
Hi,
I want to print custom character on LCD 2x16 with LCD.c lib. please help me...
thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Sep 13, 2014 8:36 am |
|
|
super simple to create 'custom characters'
0) Do NOT 'hijack another's thread...it's bad form
1) Download the datasheet for your LCD module
2) read the chapter they have on creating custom characters
3) cut code/compile/test on REAL hardware ! Do NOT use Proteus( It's BUSTED !!)
every LCD module I've used in the past 20+ years has had good documentation on creating custom characters as well as using the RAM for 'external ' storage.
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
shahrokh_m
Joined: 30 Jun 2014 Posts: 8
|
|
Posted: Sat Sep 13, 2014 3:52 pm |
|
|
temtronic wrote: | super simple to create 'custom characters'
0) Do NOT 'hijack another's thread...it's bad form
1) Download the datasheet for your LCD module
2) read the chapter they have on creating custom characters
3) cut code/compile/test on REAL hardware ! Do NOT use Proteus( It's BUSTED !!)
every LCD module I've used in the past 20+ years has had good documentation on creating custom characters as well as using the RAM for 'external ' storage.
hth
jay |
thanks a lot my friend.
i don't use Proteus. why Proteus? my assembled hardware is right here!
in LCD.C Driver, is a
" void lcd_set_cgram_char(unsigned int8 which, unsigned int8 *ptr) "
where i can't understand how its work? could you help me?
Code: |
void lcd_set_cgram_char(unsigned int8 which, unsigned int8 *ptr)
{
unsigned int i;
which <<= 3;
which &= 0x38;
lcd_send_byte(0, 0x40 | which); //set cgram address
for(i=0; i<8; i++)
{
lcd_send_byte(1, *ptr++);
}
#if defined(LCD_EXTENDED_NEWLINE)
lcd_gotoxy(g_LcdX+1, g_LcdY+1); //set ddram address
#endif
}
|
i just want to preview some symbol and i have this symbol code.
but how can i use this symbol code and "lcd_set_cgram_char" ??
(excuse me,my english grammer is not good!)
thanks a gain <3 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
shahrokh_m
Joined: 30 Jun 2014 Posts: 8
|
|
Posted: Sun Sep 14, 2014 12:43 am |
|
|
Dear friend, Thank you for your kindness, i use the Search page, but i can't find my answer.
This link code don't work. I try it several times. (flex_lcd.c lib not working, i don't know why? CCS compile code successful and hex file generated, but lcd don't show anything. In software, i have changed LCD pin connection according my assembled board)
http://www.ccsinfo.com/forum/viewtopic.php?t=40565
I want to use LCD.c lib and "lcd_set_cgram_char" function.
thanks a lot. <3 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Sep 14, 2014 5:05 am |
|
|
flex_lcd.c is the driver that PCM_P wrote and posted in the 'code library', the other forum, on this website.
You can use the 'search' feature of this forum, located just above. It's important for you to learn how to use it as there is a LOT of great information available !!
jay |
|
|
shahrokh_m
Joined: 30 Jun 2014 Posts: 8
|
|
Posted: Sun Sep 14, 2014 1:13 pm |
|
|
Finally i can....
Thank you my dear friends.
Below code can preview custom character on LCD 2x16, just with "LCD.C" library!!
Code: |
#include <lcd.c>
#define LCD_ENABLE_PIN PIN_D0
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#define UP_ARROW 0
#define DOWN_ARROW 1
#define DEGREES 2
void lcd_load_custom_chars(void);
//==========================
void main()
{
int8 temperature;
lcd_init();
lcd_load_custom_chars();
temperature = 72; // In degrees Fahrenheit
// Octal numbers 000 to 007 must be used with the "escape"
// backslash to display a custom char with printf.
// The line below displays the degrees symbol with \002.
// The "F" is for Fahrenheit. The "%3d" displays the
// temperature. The \f clears the LCD before displaying
// anything.
// Display temperature on top line of LCD.
printf(lcd_putc, "\f %3d \002F \n", temperature);
// Display up/down arrows on right side of LCD.
lcd_gotoxy(16,1); // Go to last position on top row
lcd_putc(UP_ARROW);
lcd_gotoxy(16,2); // Go to last position on bottom row
lcd_putc(DOWN_ARROW);
lcd_gotoxy(3,2);
lcd_putc(3); // Ali
lcd_gotoxy(5,2);
lcd_putc(4);
lcd_gotoxy(6,2);
lcd_putc("=3.1415");
while(1);
}
//=============================================
// Functions
// This table holds the data for the LCD custom chars.
// Only 3 chars were created below. The 5 other blank
// chars can be edited to create more custom chars.
const int8 lcd_custom_chars[] =
{
// Char Number 0 -- Up Arrow
0b00000100, // .....O..
0b00001110, // ....OOO.
0b00011111, // ...OOOOO
0b00000100, // .....O..
0b00000100, // .....O..
0b00000100, // .....O..
0b00000100, // .....O..
0b00000000, // ........
// Char Number 1 -- Down Arrow
0b00000100, // .....O..
0b00000100, // .....O..
0b00000100, // .....O..
0b00000100, // .....O..
0b00011111, // ...OOOOO
0b00001110, // ....OOO.
0b00000100, // .....O..
0b00000000, // ........
// Char Number 2 -- Degrees
0b00001100, // ....OO..
0b00010010, // ...O..O.
0b00010010, // ...O..O.
0b00001100, // ....OO..
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// Char Number 3 -- Ali
0b00001000, // ....O...
0b00001011, // ....O.OO
0b00001010, // ....O.O.
0b00011111, // ...OOOOO
0b00010000, // ...O....
0b00011111, // ...OOOOO
0b00000000, // ........
0b00000000, // ........
// Char Number 4 -- Pi
0b00000000, // ........
0b00000001, // .......O
0b00011111, // ...OOOOO
0b00001010, // ....O.O.
0b00001010, // ....O.O.
0b00001010, // ....O.O.
0b00001001, // ....O..O
0b00010000, // ...O....
// Char Number 5 -- Blank
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// Char Number 6 -- Blank
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
// Char Number 7 -- Blank
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000, // ........
0b00000000 // ........
};
void lcd_load_custom_chars(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);
}
|
Thank you all |
|
|
|
|
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
|