Author Topic: Anybody got an XLCD working on a PIC24FV32KA304  (Read 5800 times)

0 Members and 1 Guest are viewing this topic.

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Anybody got an XLCD working on a PIC24FV32KA304
« on: April 25, 2015, 10:37:03 am »
Hi
Has 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
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline AlexDavidson

  • Contributor
  • Posts: 20
  • Country: au
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #1 on: April 25, 2015, 12:24:26 pm »
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…
 

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #2 on: April 25, 2015, 03:48:35 pm »
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.

====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #3 on: April 25, 2015, 04:22:47 pm »
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline BloodyCactus

  • Frequent Contributor
  • **
  • Posts: 482
  • Country: us
    • Kråketær
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #4 on: April 25, 2015, 06:14:37 pm »
xlcd.h should be a drop in. define your pins. done. what problems are you having?
-- Aussie living in the USA --
 

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #5 on: April 25, 2015, 07:30:21 pm »
Ok, Let me run through this.
Here is my code (trimmed a bit of the unrelated stuff out)
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include "p24FV32KA302.h"
#include <libpic30.h>
#include <xc.h>
#include <xlcd.h>

// EDITED OUT FUSE BITS

void DelayFor18TCY( void ) { __delay_ms(100); return;};
void DelayPORXLCD ( void ) { __delay_ms(100); return;}; //Can Be 15ms
void DelayXLCD ( void ) { __delay_ms(100); return;}; //Can Be 5ms

int 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.h
Code: [Select]
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.h

I then go into xlcd.h and comment out the include of the p18c file :
Code: [Select]
//#include "p18cxxx.h"
Then I try to compile, and get the following errors :
Code: [Select]
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 parameter
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:81:1: error: storage class specified for unnamed parameter
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:86:1: error: storage class specified for unnamed parameter
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:106:1: error: storage class specified for unnamed parameter
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:111:1: error: storage class specified for unnamed parameter
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:121:1: error: storage class specified for unnamed parameter
C:/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" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:34:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:67:0: warning: "TRIS_DATA_PORT" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:35:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:72:0: warning: "RW_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:40:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:73:0: warning: "TRIS_RW" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:41:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:75:0: warning: "RS_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:43:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:76:0: warning: "TRIS_RS" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:44:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:78:0: warning: "E_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:46:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:79:0: warning: "TRIS_E" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:47:0: note: this is the location of the previous definition
nbproject/Makefile-default.mk:164: recipe for target 'build/default/production/_ext/726147975/MAIN.o' failed

which seems to be prototypes (if I look into xlcd.h)
Code: [Select]
76 void OpenXLCD(PARAM_SCLASS unsigned char);
81 void SetCGRamAddr(PARAM_SCLASS unsigned char);

but I see PARAM_SCLASS is defined in line 70

Code: [Select]
#define PARAM_SCLASS auto

So I tried removing PARAM_SCLASS from all those lines eg :
Code: [Select]
76 void OpenXLCD(unsigned char);
81 void SetCGRamAddr(unsigned char);

Then I try to compile, and get :
Code: [Select]
"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=off
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:66:0: warning: "DATA_PORT" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:34:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:67:0: warning: "TRIS_DATA_PORT" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:35:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:72:0: warning: "RW_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:40:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:73:0: warning: "TRIS_RW" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:41:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:75:0: warning: "RS_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:43:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:76:0: warning: "TRIS_RS" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:44:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:78:0: warning: "E_PIN" redefined
C:/PICS/PIC24FVKA302TEST.X/xlcd.h:46:0: note: this is the location of the previous definition
C:/PICS/PIC24FVKA302TEST.X/MAIN.c:79:0: warning: "TRIS_E" redefined
C:/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=off
C:/PICS/PIC24FVKA302TEST.X/openxlcd.c:1:21: fatal error: p18cxxx.h: No such file or directory

So 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 recompile

Code: [Select]
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 in
C:/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[2]: *** [build/default/production/_ext/726147975/openxlcd.o] Error 255

I did not have any of these problems when using XLCD.h on the 8 bit micros with C18 compiler....

====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1712
  • Country: 00
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #6 on: April 25, 2015, 08:04:59 pm »
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.
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 628
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #7 on: April 26, 2015, 08:38:14 am »
I then get an error where I have included xlcd.h
Code: [Select]
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.h
...
All 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: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#include "xlcd/xlcd.h"

// EDITED OUT FUSE BITS

int main(int argc, char** argv) {

    OpenXLCD(FOUR_BIT & TWO_LINE);

    while(1){};

    return (EXIT_SUCCESS);
}
   
« Last Edit: April 26, 2015, 08:40:57 am by Bruce Abbott »
 

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #8 on: April 26, 2015, 05:20:52 pm »
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
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #9 on: April 27, 2015, 08:45:34 am »
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: [Select]

#define LCD_RS LATBbits.LATB0
#define LCD_EN LATBbits.LATB1
#define LCD_DATA LATA

char lcd_config[]={0x33,0x32,0x28,0x08,0x0C,0x06,0x01};

-------------------------------------------------------------------
void lcd_print(char *dline)
{
    // send char address 80 = line 1
    LCD_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[x] >> 4;
        LCD_DATA = display;
        LCD_strobe();
        display = dline[x] & 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[x] >> 4;
        LCD_DATA = ddata;
        LCD_strobe();
        ddata = lcd_config[x] & 0x0F ;
        LCD_DATA = ddata;
        LCD_strobe();
        DLYm(2);
   
    }
   
}

void LCD_strobe()
{
  LCD_EN = 1;
  Nop();
  Nop();
  Nop();
  LCD_EN = 0;   
}

Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #10 on: April 28, 2015, 05:42:06 am »
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
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline diyaudio

  • Frequent Contributor
  • **
  • !
  • Posts: 683
  • Country: za
Re: Anybody got an XLCD working on a PIC24FV32KA304
« Reply #11 on: April 28, 2015, 09:54:16 pm »
Hi
Has 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

I 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.   

   

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf