Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC18F4680 LCD not working.

Status
Not open for further replies.

rahulmr

Junior Member level 1
Joined
Feb 21, 2007
Messages
16
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,434
Hi all,

I am having a PIC18f4680 with which I am trying to write on LCD. I am using the xLCD library and has just modified the portB to PORTD. Created a new header xLCDMod.h and copied all the XLCD.h contents to that and modified the port to PORTD. Also added copy of all the *.c files of the XLCD in the project and made the reference to xLCDMod.h and compiled.

Now that I am not able to make the LCD display the actual items that I am writing to. I am sure that the PORT change is not causing the issue as some characters are shown and is kind of scrambled and displayed in some random orders. Sometimes only 1 character is shown. I tried out many config setting but nothing worked. I am using a PIC dev board, with 20 MHz crystal.

I am not able to fully understand whether these issues are because of the crystal config or not. Can someone please help me . I am posting the code .

I have removed the config bits for now and just kept only 3 . What all config bits to be set just for the LCD ?


Code:
#include<stdio.h>
#include<stdlib.h>
#include<delays.h>
#include "XLCDMod.h"// XLCD header customized for PORTD




// PIC18F4680 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1H
#pragma config OSC = HS         // Oscillator Selection bits (HS oscillator)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = BOHW     // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (VBOR set to 2.1V)

// CONFIG2H
#pragma config WDT = ON         // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config BBSIZ = 1024     // Boot Block Size Select bits (1K words (2K bytes) Boot Block)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (00C000-00FFFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (00C000-00FFFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)




#define _XTAL_FREQ=20000000


void init_XLCD();
void DelayFor18TCY();
void DelayPORXLCD();
void DelayXLCD();

void main() {
    
    
    init_XLCD();


    while (BusyXLCD());
    SetDDRamAddr(0x00);

    putsXLCD("123456777");
    
    while (1) {
    }
}

void init_XLCD() {
    OpenXLCD(FOUR_BIT & LINES_5X7);
    while (BusyXLCD());
    WriteCmdXLCD(0x06);
    while (BusyXLCD());
    WriteCmdXLCD(0x0C);
}

void DelayFor18TCY() {
    //Delay10TCYx(2);      
    //return;
    Nop();Nop();Nop();Nop();
    Nop();Nop();Nop();Nop();
    Nop();Nop();
    return;

}

void DelayPORXLCD() {
    Delay1KTCYx(75); // Delay of 15ms
    // Cycles = (TimeDelay * Fosc) / 4
    // Cycles = (15ms * 20MHz) / 4
    // Cycles = 75,000
    return;
}

void DelayXLCD() {
    Delay1KTCYx(25); // Delay of 5ms
    // Cycles = (TimeDelay * Fosc) / 4
    // Cycles = (5ms * 20MHz) / 4
    // Cycles = 25,000
    return;
}
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,512
Could you post your customized version of the xLCDMod.h header file?

When reviewing your configuration register settings, I noticed you have the watchdog timer enable, however I do not see any indication you've attempted to "kick the dog" directly in main(). Are you servicing the watchdog timer periodic routine call? Typically, during the majority of code development the watchdog timer is disable.

Also, have you run simulations using the stopwatch feature to test your implementations of the required delay routines produce reasonable delay durations.

You may also want to output a series of test pattern strings to LCD, consisting of consecutive alphanumeric characters to test both the LCD and connections.

BigDog
 

rahulmr

Junior Member level 1
Joined
Feb 21, 2007
Messages
16
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,434
Thanks for the reply
I am posting the project as a zip file. Also I have tested the same in proteus and it is working fine.
I am having some issues doubts here, I have the 20MHz crystal in my development board and this code is written considering that in mind.
But when I set the PIC Processor Frequency in the pic properties to 20Mhz , it is not working. but when I set the frequency to 4 MHz in the properties in the proteus it is working.

Can you please help me to figure out the problem. I have spent enough time in this :(

In the LCD in the development board, I am seeing only 3 characters and it starts from second position in line 1


Code is attached below.
 

Attachments

  • ProjectUSARTLCD18F.X.7z
    185.4 KB · Views: 4
Last edited by a moderator:

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,512
The first task is to disable the watchdog timer in the configuration register settings:

Code:
// CONFIG2H
#pragma config WDT = [COLOR="#FF0000"]OFF[/COLOR]         // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

If you wish to fully implement a watchdog timer in the final application, then make you typically make it one of the last items on the "TODO" list.

In the future, please use the "Manage Attachment" feature to upload files, rather than external file sharing services.


BigDog
 

rahulmr

Junior Member level 1
Joined
Feb 21, 2007
Messages
16
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,434
Thank you. I was not having the permission to upload as attachment . that is why i uploaded to file sharing.

yes, I have disabled the WDT and even then it has not difference.
Only in proteus it works fine where as in actual development board it is not.
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,259
Helped
380
Reputation
760
Reaction score
376
Trophy points
83
Activity points
13,617
Might not be the problem but:
- drop the includes for stdio.h and stdlib.h - they might have a place in programming a PC etc but are almost never needed for an embedded system
- put the include for xc.h first - this is used to set things up for the rest of the program
What is the development board you mention? Is it a purchased one such as an Explorer 16 or is it a breadboard with your own crystal and capacitors etc?
If the latter then have you connected power and ground to both sets of pins, are there bypass capacitors in place, what size capacitors do you have on the crystal? These are some of the "common" problems people have that cause instability. One other big thing is the capacitance between tracks on a breadboard - you may be better off using a 5MHz crystal and the 4x PLL if you really need a clock speed of 20MHz as experience has shown that 20MHZ crystals in a breadboard can be hard to get going properly.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top