I am trying to use pic18f2455 and I could not manage to use it in a simple way.
I am new to pic programming and any helpful advice would be greatly appreciated.
Attached is the simplified schematic of my circuit.
I also attached the configuration file config.h that I am using. Its main parts being :
#pragma config FOSC = INTOSCIO_EC
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF
Now a simple program like the following would not light my LED :
#include<xc.h>
#include "config.h"
void main() {
TRISBbits.TRISB0 = 0;
LATBbits.LATB0 = 0;
for(int i=0; i<50; ++i){}
LATBbits.LATB0 = 1;
for( ; ; ){}
}
I managed to isolate the problem and I suspect a constant Power-on-Reset which I think I can show with the following code, which lets the LED constantly lit :
void main() {
TRISBbits.TRISB0 = 0;
if(RCONbits.POR == 0){
LATBbits.LATB0 = 1;
}else{
LATBbits.LATB0 = 0;
}
RCONbits.POR = 1;
for(int i=0; i<50; ++i){}
LATBbits.LATB0 = 0;
for( ; ; ){}
}
Any help will be appreciated. Thanks!!
I am new to pic programming and any helpful advice would be greatly appreciated.
Attached is the simplified schematic of my circuit.
I also attached the configuration file config.h that I am using. Its main parts being :
#pragma config FOSC = INTOSCIO_EC
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF
Now a simple program like the following would not light my LED :
#include<xc.h>
#include "config.h"
void main() {
TRISBbits.TRISB0 = 0;
LATBbits.LATB0 = 0;
for(int i=0; i<50; ++i){}
LATBbits.LATB0 = 1;
for( ; ; ){}
}
I managed to isolate the problem and I suspect a constant Power-on-Reset which I think I can show with the following code, which lets the LED constantly lit :
void main() {
TRISBbits.TRISB0 = 0;
if(RCONbits.POR == 0){
LATBbits.LATB0 = 1;
}else{
LATBbits.LATB0 = 0;
}
RCONbits.POR = 1;
for(int i=0; i<50; ++i){}
LATBbits.LATB0 = 0;
for( ; ; ){}
}
Any help will be appreciated. Thanks!!
Attachments
-
8.7 KB Views: 31
-
4.3 KB Views: 18