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.

[PIC] help regarding PIC p18f1330

Status
Not open for further replies.

ruben91

Junior Member level 3
Joined
Nov 17, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
209
i am new to pic18f1330, i have written a code to test that the pic18f1330 works fine, but i can't get it work even for simple led on/off coding, please help me regarding this. I have attacted th code together with the connection of my pic. scared it was the wrong part..thank you

Code:
#include <p18f1330.h>
#pragma config OSC=INTIO2
#pragma config WDT = OFF
#pragma config DEBUG=ON
void main ()
{
	TRISB=1; // switch
	TRISA=0; // LED
	
	while(1)
	{
		if(PORTBbits.RB1==0)
			PORTHbits.RA0=1;// light on
		else
			PORTAbits.RA0=0;// light off
	}
}

11.jpg
 

Are you using C18 or XC8 COmpiler ? If using XC8 Compiler then include XC.h file. Also include the line


Code C - [expand]
1
#define _XTAL_FREQ 4000000



Try this code. Disable ADC by configuring ANSELx ot ADCONx registers. Disable Comparator using CMxCOMx or CMCON registers.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <p18f1330.h>
 
#pragma config OSC=INTIO2
#pragma config WDT = OFF
#pragma config DEBUG = ON
 
void main ()
{
    TRISB=1; // switch
    TRISA=0; // LED
    
    while(1)
    {
        if(LATBbits.LATB1 == 0)
        //Add 30 ms delay here
        while(LATBbits.LATB1 == 0)
            LATAbits.LATA0 = 1;// light on
        else
            LATAbits.LATA0 = 0;// light off
    }
}



- - - Updated - - -

Are you using C18 or XC8 COmpiler ? If using XC8 Compiler then include XC.h file. Also include the line


Code C - [expand]
1
#define _XTAL_FREQ 4000000



Try this code. Disable ADC by configuring ANSELx ot ADCONx registers. Disable Comparator using CMxCOMx or CMCON registers.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <p18f1330.h>
 
#pragma config OSC=INTIO2
#pragma config WDT = OFF
#pragma config DEBUG = ON
 
void main ()
{
    TRISB=1; // switch
    TRISA=0; // LED
    
    while(1)
    {
        if(LATBbits.LATB1 == 0)
        //Add 30 ms delay here
        while(LATBbits.LATB1 == 0)
            LATAbits.LATA0 = 1;// light on
        else
            LATAbits.LATA0 = 0;// light off
    }
}

 

Are you using C18 or XC8 COmpiler ? If using XC8 Compiler then include XC.h file. Also include the line


Code C - [expand]
1
#define _XTAL_FREQ 4000000



Try this code. Disable ADC by configuring ANSELx ot ADCONx registers. Disable Comparator using CMxCOMx or CMCON registers.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <p18f1330.h>
 
#pragma config OSC=INTIO2
#pragma config WDT = OFF
#pragma config DEBUG = ON
 
void main ()
{
    TRISB=1; // switch
    TRISA=0; // LED
    
    while(1)
    {
        if(LATBbits.LATB1 == 0)
        //Add 30 ms delay here
        while(LATBbits.LATB1 == 0)
            LATAbits.LATA0 = 1;// light on
        else
            LATAbits.LATA0 = 0;// light off
    }
}



- - - Updated - - -

Are you using C18 or XC8 COmpiler ? If using XC8 Compiler then include XC.h file. Also include the line


Code C - [expand]
1
#define _XTAL_FREQ 4000000



Try this code. Disable ADC by configuring ANSELx ot ADCONx registers. Disable Comparator using CMxCOMx or CMCON registers.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <p18f1330.h>
 
#pragma config OSC=INTIO2
#pragma config WDT = OFF
#pragma config DEBUG = ON
 
void main ()
{
    TRISB=1; // switch
    TRISA=0; // LED
    
    while(1)
    {
        if(LATBbits.LATB1 == 0)
        //Add 30 ms delay here
        while(LATBbits.LATB1 == 0)
            LATAbits.LATA0 = 1;// light on
        else
            LATAbits.LATA0 = 0;// light off
    }
}


thank you sir, i wil try it. i'm using mplab ide wit c18 compiler and pickit2. is my conection for circuit is correct?

- - - Updated - - -

its still not fuctioning sir.. :(

- - - Updated - - -

is my circuit diagram is correct??
 

In the config settings set DEBUG = OFF

Here I am attaching mikroC PRO PIC code. Test it in hardware and reply. LED toggles on button press and release.
 

Attachments

  • PIC18F1330 LED Blink.rar
    51.9 KB · Views: 52
  • led_blink.png
    led_blink.png
    20 KB · Views: 59
Last edited:
Better still, never mention the DEBUG config setting in your code. It is just about the only config setting that you should never play with yourself.
The reason is that this setting is controlled by the MPLAB(x) IDE depending on whether you build for 'debug' or 'release'.
While your code might seem to work (in that the LED will turn on and off when you push the button. However you really should look at including debouncing code (or hardware) on the push button input; if you try to use your current technique in a situation where receiving multiple 'switches' can impact on the item you are controlling (i.e. 1 push to increment a temperature by 1 degree - without debouncing you will step up the temperature by any number of degrees for each "push" and similarly on release).
Susan
 
In the config settings set DEBUG = OFF

Here I am attaching mikroC PRO PIC code. Test it in hardware and reply. LED toggles on button press and release.

Thank you sir.. its working fine now... thanks alot!!
MY PROBLEM WAS THE DEBUG config and also the connection of my push button..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top