Continue to Site

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.

Need Help doing C Language Programming for PIC18F4520 MPLAB lCD 3

Status
Not open for further replies.
Next thing to try is the attached new pintest.hex

Same program, but depends on the 4MHz canned oscillator working correctly.

LEDs will flash a little faster.
 

Attachments

  • pintest.rar
    290 bytes · Views: 53

Then I would think that there is a problem with the 4MHz canned oscillator Y2 or the circuitry around it.

Check that the square corner on the oscillator matches the square corner on the diagram underneath.

J7 must be left open - no link.

Nothing fitted into socket Y1
 

yup . the words on Y2 will be upside down, I just remove J7 AND y1 is empty . but still nothing there.
 

Then all I can think is that you have a faulty canned oscillator, faulty board or faulty PIC18F4520.

Can't think of anything else to try.
 

actually what you point out make sense , i have double check all the old and new version of the schematic and the RW Pin from the LCD is all link to RD5 of uC . my teacher has also point out that there might be a chance that the PIC18F4520 may be faulty..

- - - Updated - - -

:hexreader , do u have the c file for the first pintest trial ?
 

do you have the c file for the first pintest trial ?
I wrote pintest in mikroC pro, so it will not be of use to you.


I found this code on my hard drive though. Untested, but looks about right:

Code:
// C test program for PICDEM2 plus green with PIC18F4520 and 10MHz xtal

#include    <p18cxxx.h>

// prototypes
void delays(unsigned int seconds);

//#pragma config OSC      = HSPLL     // 10MHz xtal x4 = 40MHz
//#pragma config OSC      = HS
#pragma config OSC      = INTIO67   // internal oscillator
#pragma config FCMEN    = OFF       // Fail-Safe Clock Monitor disabled
#pragma config IESO     = OFF       // Oscillator Switchover mode disabled
#pragma config PWRT     = ON        // power up timer enabled
#pragma config BOREN    = SBORDIS   // Brown-out Reset enabled in hardware only (SBOREN is disabled) 
#pragma config WDT      = OFF       // WDT disabled
#pragma config MCLRE    = ON        // MCLR pin enabled; RE3 input pin disabled
#pragma config LPT1OSC  = OFF       // Timer1 configured for higher power operation
#pragma config PBADEN   = OFF       // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config CCP2MX   = PORTC     // CCP2 input/output is multiplexed with RC1
#pragma config STVREN   = ON        // Stack full/underflow will cause Reset
#pragma config LVP      = OFF       // Single-Supply ICSP disabled 
#pragma config XINST    = OFF       // Instruction set extension and Indexed Addressing mode disabled
// code protect - don't care

void main(void)
{

    TRISA = 0x00;   // all output
    TRISB = 0x00;   // all output
    TRISC = 0x00;   // all output
    TRISD = 0x00;   // all output
    TRISE = 0x00;   // all output
    LATA = 0xFF;    // LED on, to show life
    LATB = 0xFF;    // LED on, to show life
    LATC = 0xFF;    // LED on, to show life
    LATD = 0xFF;    // LED on, to show life
    LATE = 0xFF;    // LED on, to show life
    
   
	while(1)        // loop forever at end to prevent reset
	{
    	LATA = 0x55;    // pattern 1
    	LATB = 0x55;    // pattern 1
    	LATC = 0x55;    // pattern 1
    	LATD = 0x55;    // pattern 1
    	LATE = 0x55;    // pattern 1
    	delays(1);      // time to see LEDs
    	LATA = 0xaa;    // pattern 2
    	LATB = 0xaa;    // pattern 2
    	LATC = 0xaa;    // pattern 2
    	LATD = 0xaa;    // pattern 2
    	LATE = 0xaa;    // pattern 2
    	delays(1);      // time to see LEDs
   	}	
}

// delay for n seconds
void delays(unsigned int seconds)
{
unsigned long l,m,n;

    for( n = 0 ; n < seconds ; n++)
    {
        for( m = 0 ; m < 5 ; m++)
        {
            for( l = 0 ; l < 200 ; l++);
        }
    }
}
 

sorry but what does this mean ? #include <p18cxxx.h> what is cxxx?
 

sorry but what does this mean ? #include <p18cxxx.h> what is cxxx?
Much the same thing as p18F4520.h, but a generic file that chooses the the correct processor file for you.

You can substitute:

#include <p18F4520.h>

.. if you prefer
 

the code cant work, omg i scared the uC got problem
 

Try this hex file (attached)

It lights LEDs and puts characters on the LCD, but uses internal oscillator.
 

Attachments

  • mon18.rar
    13 KB · Views: 44

my teacher gave me this code for this microchip pic18f46k22 , he say its almost similiar to change some of the codes . can u help me take a look and advise me how do i change ..

- - - Updated - - -

// C test program for PICDEM2 plus green with PIC18F4520 and 10MHz xtal

#include <p18cxxx.h>

// prototypes
void delays(unsigned int seconds);

//#pragma config OSC = HSPLL // 10MHz xtal x4 = 40MHz
//#pragma config OSC = HS
#pragma config OSC = INTIO67 // internal oscillator
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF // Oscillator Switchover mode disabled
#pragma config PWRT = ON // power up timer enabled
#pragma config BOREN = SBORDIS // Brown-out Reset enabled in hardware only (SBOREN is disabled)
#pragma config WDT = OFF // WDT disabled
#pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled
#pragma config LPT1OSC = OFF // Timer1 configured for higher power operation
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config CCP2MX = PORTC // CCP2 input/output is multiplexed with RC1
#pragma config STVREN = ON // Stack full/underflow will cause Reset
#pragma config LVP = OFF // Single-Supply ICSP disabled
#pragma config XINST = OFF // Instruction set extension and Indexed Addressing mode disabled
// code protect - don't care

void main(void)
{

TRISA = 0x00; // all output
TRISB = 0x00; // all output
TRISC = 0x00; // all output
TRISD = 0x00; // all output
TRISE = 0x00; // all output
LATA = 0xFF; // LED on, to show life
LATB = 0xFF; // LED on, to show life
LATC = 0xFF; // LED on, to show life
LATD = 0xFF; // LED on, to show life
LATE = 0xFF; // LED on, to show life


while(1) // loop forever at end to prevent reset
{
LATA = 0x55; // pattern 1
LATB = 0x55; // pattern 1
LATC = 0x55; // pattern 1
LATD = 0x55; // pattern 1
LATE = 0x55; // pattern 1
delays(1); // time to see LEDs
LATA = 0xaa; // pattern 2
LATB = 0xaa; // pattern 2
LATC = 0xaa; // pattern 2
LATD = 0xaa; // pattern 2
LATE = 0xaa; // pattern 2
delays(1); // time to see LEDs
}
}

// delay for n seconds
void delays(unsigned int seconds)
{
unsigned long l,m,n;

for( n = 0 ; n < seconds ; n++)
{
for( m = 0 ; m < 5 ; m++)
{
for( l = 0 ; l < 200 ; l++);
}
}
}

hey hexreader, your above code u gave me appear fine...
 

Attachments

  • LCDdisplay.zip
    49 KB · Views: 49

Then it looks like you have a problem with the canned oscillator, the PIC's oscillator input, or your board.

Have you tried unplugging the crystal oscillator module Y2 to see if one of the legs is broken off?
 

...and the oscillator Y2 is fitted the right way round? (square corner of the oscillator Y2 matches the square corner on the outline shown on the board)
 

yup. my teacher just show me a demo of the same uC and the same board, it manage to display some words there
 

Then I am out of ideas.

Just cannot think of anything else for you to try.

Your board seems to work OK with internal oscillator, but not with on-board 4MHz canned oscillator, but I do not know why.
 

how to start the temperature part ? i managed to display some words already..
 

:hexreader , can you help me checked if the codes are correct..
It is supposed to display "LCD Test" on the upper line of the LCD and "P6 PROJECT" on the bottom line of the LCD.
But is not working at all. thank you for the help
 

Attachments

  • pichw.zip
    53.8 KB · Views: 42

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top