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
}
} |