Anybody got an XLCD working on a PIC24FV32KA304 - Page 1
Forum section: electronics / general

author: kolbep
author_rank: Frequent Contributor
timestamp: April 25, 2015, 10:37:03 am
content: HiHas anybody got an External LCD working on the PIC24FV32 Series PICS?I used to use C18 Libs on the PIC18f2420 without problems, but I cannot seem to find a lib that will work on the PIC24 series.Even trying to port the XLCD.h libraries has me pulling my hair out.This is my first attempt at using the 16bit series, so I need some guidance.Thanks

author: AlexDavidson
author_rank: Contributor
timestamp: April 25, 2015, 12:24:26 pm
content: I’ve done that for dsPIC30F, but I didn’t use xlcd. I found it fairly straightforward to work from the LCD datasheet and write my own routines. The main problem I had was realising that the LCD bias voltage must be correct otherwise the screen will always be blank…

author: kolbep
author_rank: Frequent Contributor
timestamp: April 25, 2015, 03:48:35 pm
content: Guess that will be the easiest and quickest.At least I have figured out the Library that has the __delay_ms(x) in it, so I can at least have my timings right.

author: mazurov
author_rank: Frequent Contributor
timestamp: April 25, 2015, 04:22:47 pm
content: This is how I've done it on PIC24 using EPMP ->http://www.circuitsathome.com/mcu/driving-a-character-lcd-using-pic24-enhanced-parallel-master-port.

author: BloodyCactus
author_rank: Frequent Contributor
timestamp: April 25, 2015, 06:14:37 pm
content: xlcd.h should be a drop in. define your pins. done. what problems are you having?

author: kolbep
author_rank: Frequent Contributor
timestamp: April 25, 2015, 07:30:21 pm
content: Ok, Let me run through this.Here is my code (trimmed a bit of the unrelated stuff out)Code:#include <stdio.h>#include <stdlib.h>#include "p24FV32KA302.h"#include <libpic30.h>#include <xc.h>#include <xlcd.h>// EDITED OUT FUSE BITSvoid DelayFor18TCY( void ) { __delay_ms(100); return;};void DelayPORXLCD ( void ) { __delay_ms(100); return;}; //Can Be 15msvoid DelayXLCD ( void ) { __delay_ms(100); return;}; //Can Be 5msint main(int argc, char** argv) {TRISA=0x00;TRISB=0x00;OpenXLCD( FOUR_BIT & LINES_5X7);while(1){};return (EXIT_SUCCESS);}I then get an error where I have included xlcd.hCode:File C:\PICS\PIC24FVKA302TEST.X\xlcd.h From project PIC24FVKA302TEST but there is an unresolved #include "p18cxxx.h" in included C:\PICS\PIC24FVKA302TEST.X\xlcd.hI then go into xlcd.h and comment out the include of the p18c file :Code://#include "p18cxxx.h"Then I try to compile, and get the following errors :Code:In file included from C:/PICS/PIC24FVKA302TEST.X/MAIN.c:15:0:C:/PICS/PIC24FVKA302TEST.X/xlcd.h:76:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:81:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:86:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:106:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:111:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:121:1: error: storage class specified for unnamed parameterC:/PICS/PIC24FVKA302TEST.X/xlcd.h:126:22: warning: type defaults to 'int' in declaration of 'rom'C:/PICS/PIC24FVKA302TEST.X/xlcd.h:126:26: error: expected ';', ',' or ')' before 'char'C:/PICS/PIC24FVKA302TEST.X/MAIN.c:66:0: warning: "DATA_PORT" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:34:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:67:0: warning: "TRIS_DATA_PORT" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:35:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:72:0: warning: "RW_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:40:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:73:0: warning: "TRIS_RW" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:41:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:75:0: warning: "RS_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:43:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:76:0: warning: "TRIS_RS" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:44:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:78:0: warning: "E_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:46:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:79:0: warning: "TRIS_E" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:47:0: note: this is the location of the previous definitionnbproject/Makefile-default.mk:164: recipe for target 'build/default/production/_ext/726147975/MAIN.o' failedwhich seems to be prototypes (if I look into xlcd.h)Code:76 void OpenXLCD(PARAM_SCLASS unsigned char);81 void SetCGRamAddr(PARAM_SCLASS unsigned char);but I see PARAM_SCLASS is defined in line 70Code:#define PARAM_SCLASS autoSo I tried removing PARAM_SCLASS from all those lines eg :Code:76 void OpenXLCD(unsigned char);81 void SetCGRamAddr(unsigned char);Then I try to compile, and get :Code:"C:\Program Files\Microchip\xc16\v1.23\bin\xc16-gcc.exe" C:/PICS/PIC24FVKA302TEST.X/MAIN.c -o build/default/production/_ext/726147975/MAIN.o -c -mcpu=24FV32KA302 -MMD -MF "build/default/production/_ext/726147975/MAIN.o.d" -g -omf=elf -I"C:/PICS/PIC24FVKA302TEST.X" -I"C:/PICS/PIC24FVKA302TEST.X/xlcd" -O0 -msmart-io=1 -Wall -msfr-warn=offC:/PICS/PIC24FVKA302TEST.X/MAIN.c:66:0: warning: "DATA_PORT" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:34:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:67:0: warning: "TRIS_DATA_PORT" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:35:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:72:0: warning: "RW_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:40:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:73:0: warning: "TRIS_RW" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:41:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:75:0: warning: "RS_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:43:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:76:0: warning: "TRIS_RS" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:44:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:78:0: warning: "E_PIN" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:46:0: note: this is the location of the previous definitionC:/PICS/PIC24FVKA302TEST.X/MAIN.c:79:0: warning: "TRIS_E" redefinedC:/PICS/PIC24FVKA302TEST.X/xlcd.h:47:0: note: this is the location of the previous definition"C:\Program Files\Microchip\xc16\v1.23\bin\xc16-gcc.exe" C:/PICS/PIC24FVKA302TEST.X/openxlcd.c -o build/default/production/_ext/726147975/openxlcd.o -c -mcpu=24FV32KA302 -MMD -MF "build/default/production/_ext/726147975/openxlcd.o.d" -g -omf=elf -I"C:/PICS/PIC24FVKA302TEST.X" -I"C:/PICS/PIC24FVKA302TEST.X/xlcd" -O0 -msmart-io=1 -Wall -msfr-warn=offC:/PICS/PIC24FVKA302TEST.X/openxlcd.c:1:21: fatal error: p18cxxx.h: No such file or directorySo I go into openxlcd.c and busyxlcd.c and comment out the include for the p18c files, as well as the include for delays.h that is in openxlcd.c, and try to recompileCode:C:/PICS/PIC24FVKA302TEST.X/openxlcd.c: In function 'OpenXLCD':C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:28:9: error: 'PORTB' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:28:9: note: each undeclared identifier is reported only once for each function it appears inC:/PICS/PIC24FVKA302TEST.X/openxlcd.c:29:9: error: 'TRISB' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:35:9: error: 'TRISAbits' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:36:9: error: 'TRISBbits' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:38:9: error: 'LATAbits' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:39:9: error: 'LATBbits' undeclared (first use in this function)C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:46:4: warning: implicit declaration of function 'Delay10KTCYx'make: *** [build/default/production/_ext/726147975/openxlcd.o] Error 255I did not have any of these problems when using XLCD.h on the 8 bit micros with C18 compiler....

author: hans
author_rank: Super Contributor
timestamp: April 25, 2015, 08:04:59 pm
content: Probably need to include xc.h instead of the p18cxxxx.h to clear the register definitions errors.If you were to upgrade to the XC8 compiler, you would be having the same deal. Luckily xc.h is the same include for all PICs, from PIC10's to PIC32's.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: April 26, 2015, 08:38:14 am
content: Quote from: kolbep on April 25, 2015, 07:30:21 pmAll those errors are caused by trying to use PIC18 code on a PIC24.There is a version of xlcd for PIC24 included with XC16. The header files "xlcd.h" and "delay.h" are in the 'support\peripheral_30F_24H_33F' folder, and the source code is in the archive "peripheral_30F_24H_33F.zip" in the 'src' folder.That's the good news. The bad news is that it only works with 24H/30F/33F chips which have a PORTD. I have modified these files to make them more generic (changed pins assignments to PORTB, removed chip family checks etc.). I don't have a 24FV32KA304 to test this code on, but it compiles fine so it should work.Pins are assigned in 'xlcd.h' and timing delays in 'delay.h' (note: set Fcy to the actual instruction cycle frequency!). Put the folder 'xlcd' in your project directory, and add it to the project's source files. You can then edit the header files to set the pins you want to use and required timing. Having a local copy also allows you to tweak the code to suit a particular LDC module. In the main program you just have to include "xlcd/xlcd.h", like this:-Code:#include <stdio.h>#include <stdlib.h>#include <xc.h>#include "xlcd/xlcd.h"// EDITED OUT FUSE BITSint main(int argc, char** argv) {OpenXLCD(FOUR_BIT & TWO_LINE);while(1){};return (EXIT_SUCCESS);}

author: kolbep
author_rank: Frequent Contributor
timestamp: April 26, 2015, 05:20:52 pm
content: Thanks for that. You have been a great help.It does compile without a hitch.Tomorrow I will try it on the breadboard, and let you know..P

author: 22swg
author_rank: Frequent Contributor
timestamp: April 27, 2015, 08:45:34 am
content: kolbep.. Current project PIC24VF32KA302 ,, great chip... I stay away from libs ! this is my code for an 8x1 line lcd ( all display strings are 8 bytes and go to lcd 0x80 ) PIC at 8Mhz Port A0-A3 = data , has RTCC and 5 switches .Yes my code is that of a 4 year old...Code:#define LCD_RS LATBbits.LATB0#define LCD_EN LATBbits.LATB1#define LCD_DATA LATAchar lcd_config[]={0x33,0x32,0x28,0x08,0x0C,0x06,0x01};-------------------------------------------------------------------void lcd_print(char *dline){// send char address 80 = line 1LCD_RS = 0;LCD_EN = 0;LCD_DATA = 0x08;LCD_strobe();LCD_DATA = 0x00;LCD_strobe();DLYm(2);LCD_RS = 1;LCD_EN = 0;unsigned int x;unsigned char display;for(x=0;x<8;x++){display = dline >> 4;LCD_DATA = display;LCD_strobe();display = dline & 0x0F ;LCD_DATA = display;LCD_strobe();DLY_100u();}}-----------------------------------------------------------------------------//char lcd_config[]={0x33,0x32,0x28,0x08,0x0C,0x06,0x01};/* initialise the LCD - put into 4 bit mode */void lcd_init(){unsigned int x;unsigned char ddata;DLYm(300); // wait 300mSec after power applied,LCD_RS = 0;LCD_EN = 0;for(x=0;x<7;x++){ddata = lcd_config >> 4;LCD_DATA = ddata;LCD_strobe();ddata = lcd_config & 0x0F ;LCD_DATA = ddata;LCD_strobe();DLYm(2);}}void LCD_strobe(){LCD_EN = 1;Nop();Nop();Nop();LCD_EN = 0;}

author: kolbep
author_rank: Frequent Contributor
timestamp: April 28, 2015, 05:42:06 am
content: I could not get the libs to work,and I decided that for the time being, it will be better for debugging if I have it communicating to Hyperterminal on my pc. So I have put the XLCD on the back burner, and worked yesterday afternoon on getting the UART working.The UART is working fine now,so I was trying the ADC, just to give an output to the terminal. But I do not have something right yet. The ADC code I tried has its output as an UINT array. Trying different things in the printf statement hasn't gotten me a result displayed yet.Actually, come to think of it, the code hangs when it is checking for the Conversion Complete flags...P

author: diyaudio
author_rank: Frequent Contributor
timestamp: April 28, 2015, 09:54:16 pm
content: Quote from: kolbep on April 25, 2015, 10:37:03 amI think the XLCD library needs to be re-complied, as you making changes to the LCD parameters in the header. I don't even think the C18 Libs are 100% compatible, as it wasn't written in XC "Hi-Tech" but Microchips now old and outdated C18 complier.Its better to just read the datasheet and write a C driver, it much more clean and simpler.