0
\$\begingroup\$

I am struggling to drive an LCD with a PIC18LF27K42.

The functions are all OK. They are working fine with a PIC18F14K50 with the same clock of 4MHz.

I suspect the error is in my configuration bits. I did review it without success.

Thanks for your help

I am using the following pin definitions:

define ENL      LATCbits.LATC7 (OUT)

define RW       LATCbits.LATC6 (OUT)

define RS       LATCbits.LATC5 (OUT)

define DB7      LATAbits.LATA3 (OUT)

define DB6      LATAbits.LATA2 (OUT)

define DB5      LATAbits.LATA1 (out)

define DB4      LATAbits.LATA0 (out)

Before running the main() I am doing the following initialization:

PORTA   = 0x00;
LATA    = 0x00;
ANSELA  = 0x00;
TRISA   = 0xF0;
PORTB   = 0x00;
LATB    = 0x00;
ANSELB  = 0x00;
TRISB   = 0x1F;
PORTC   = 0x00;
LATC    = 0x00;
ANSELC  = 0x00;
TRISC   = 0x1F;

CONFIGURATION BITS

// CONFIG 1L

 #pragma  config  FEXTOSC = HS

 #pragma  config  RSTOSC  = EXTOSC

 // CONFIG 1H

 #pragma  config  CLKOUTEN= OFF

 #pragma  config  PR1WAY  = ON

 #pragma  config  CSWEN   = OFF

 #pragma  config  FCMEN   = ON


// CONFIG 2L

 #pragma  config  MCLRE   = EXTMCLR

 #pragma  config  PWRTS   = PWRT_OFF

 #pragma  config  MVECEN  = OFF

 #pragma  config  IVT1WAY = OFF

 #pragma  config  LPBOREN = OFF

 #pragma  config  BOREN   = OFF

 // CONFIG 2H

 #pragma  config  BORV    = VBOR_2P45

 #pragma  config  ZCD     = OFF      

 #pragma  config  PPS1WAY = OFF

 #pragma  config  STVREN  = ON

 #pragma  config  DEBUG   = OFF

 #pragma  config  XINST   = OFF

 // CONFIG 3L

 #pragma  config  WDTCPS  = WDTCPS_31

 #pragma  config  WDTE    = OFF

 // CONFIG 3H

 #pragma  config  WDTCWS  = WDTCWS_0

 #pragma  config  WDTCCS  = LFINTOSC

 // CONFIG 4L 

 #pragma  config  BBSIZE  = BBSIZE_512

 #pragma  config  BBEN    = OFF

 #pragma  config  SAFEN   = OFF

 #pragma  config  WRTAPP  = OFF

 // CONFIG 4H

 #pragma  config  WRTB    = OFF

 #pragma  config  WRTC    = OFF

 #pragma  config  WRTD    = OFF

 #pragma  config  WRTSAF  = OFF

 #pragma  config  LVP     = ON

 // CONFIG 5L

 #pragma  config    CP      = OFF
\$\endgroup\$
3
  • \$\begingroup\$ Someone might be able to find the problem, using the information you've supplied. However, while you're waiting... Have you used an oscilloscope or logic analyser to monitor the LCD interface to the MCU and compare the behaviour / timing etc. between your working (PIC18F14K50) config, and failing (PIC18LF27K42) config? If you find a difference in, for example, the timing of the various signals, that could lead your investigation in a different direction than if you see no changes in the signals at all. Please add any results from your investigation so far, like those. \$\endgroup\$
    – SamGibson
    Commented Jul 21, 2018 at 13:08
  • \$\begingroup\$ @SamGibson, Thank you for your reply, but unfortunatly i do not have an oscilloscope. The timing should be the same (i assume) as i am using the same clock and the same code. \$\endgroup\$
    – topic
    Commented Jul 21, 2018 at 16:43
  • \$\begingroup\$ Thanks. "The timing should be the same (i assume)" Understood, timing is just one example - we'd check the overall behaviour of all the signals. If everything was the same, then the new config would also work - but it doesn't. Therefore something is different, and looking at the LCD interface signals would be a quick way to identify the type of difference, and therefore identify the area of code to investigate. Although 'scopes & logic analysers each have limitations, they allow troubleshooting to be "data driven" and avoid guessing due to lack of info. Anyway, sincere good luck! \$\endgroup\$
    – SamGibson
    Commented Jul 21, 2018 at 20:14

1 Answer 1

1
\$\begingroup\$

I am too new here to post a comment. What I can do is post an answer.

This link is to my Github repository that is an MPLABX project using the XC8 compiler to custom craft a demo application to your specifications.

I do not have a PIC18LF27K42 to test it on in real hardware.

Perhaps it can work for you, please give it a try and let me know.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for the link and files. The program works well ! \$\endgroup\$
    – topic
    Commented Jul 28, 2018 at 9:35
  • \$\begingroup\$ I have noticed an error in my #pragma config BORV = VBOR_2P45. I have corrected it but now the LCD behaving in a strange way. All lines are displaying the first CGRAM character ... \$\endgroup\$
    – topic
    Commented Jul 28, 2018 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.