Jinzpaul4u
Full Member level 4
- Joined
- Feb 1, 2012
- Messages
- 231
- Helped
- 59
- Reputation
- 118
- Reaction score
- 60
- Trophy points
- 1,328
- Location
- India
- Activity points
- 2,822
Hi there,
Greetings!
Do any of you know why my code ain't working?
#include <p18F46J50.h> // Always include the header file
//Defaut pragma code for 18F46J50
//#pragma config WDTEN = OFF //WDT disabled (enabled by SWDTEN bit)
#pragma config PLLDIV = 3 //Divide by 3 (12 MHz oscillator input)
#pragma config STVREN = ON //stack overflow/underflow reset enabled
//#pragma config XINST = OFF //Extended instruction set disabled
#pragma config CPUDIV = OSC1 //No CPU system clock divide
#pragma config CP0 = OFF //Program memory is not code-protected
//#pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB
#pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF //Two-Speed Start-up disabled
#pragma config WDTPS = 32768 //1:32768
#pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock
//#pragma config RTCOSC = T1OSCREF //RTCC uses T1OSC/T1CKI as clock
//#pragma config DSBOREN = OFF //Zero-Power BOR disabled in Deep Sleep
//#pragma config DSWDTEN = OFF //Disabled
#pragma config DSWDTPS = 8192 //1:8,192 (8.5 seconds)
//#pragma config IOL1WAY = OFF //IOLOCK bit can be set and cleared
#pragma config MSSP7B_EN = MSK7 //7 Bit address masking
#pragma config WPFP = PAGE_1 //Write Protect Program Flash Page 0
#pragma config WPEND = PAGE_0 //Start protection at page 0
#pragma config WPCFG = OFF //Write/Erase last page protect Disabled
#pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored
#pragma config T1DIG = ON //Sec Osc clock source may be selected
#pragma config LPT1OSC = OFF //high power Timer1 mode
void ISR(void) ;
void main(void)
{
unsigned int timerValue = 1;
// Timer0 configuration
T0CONbits.TMR0ON = 0; // Stop the timer
T0CONbits.T08BIT = 0; // Run in 16-bit mode
T0CONbits.T0CS = 0; // Use system clock to increment timer
T0CONbits.PSA = 0; // A prescaler is assigned for Timer0
T0CONbits.T0PS2 = 0; // Use a 1:256 prescaler
T0CONbits.T0PS1 = 0;
T0CONbits.T0PS0 = 0;
TMR0L=timerValue ;
TMR0H=(timerValue>>8);
INTCONbits.GIEH = 1; // enable global interrupt
INTCONbits.TMR0IE = 1;// enable TIM0 interrupt
INTCONbits.TMR0IF = 0;// clear TIM0 interrupt flag
// LED configuration
TRISDbits.TRISD4 = 0; // Configure RD4, pin 2, as an output
LATDbits.LATD4=0; // pin is low
T0CONbits.TMR0ON = 1; // Start the timer
while(1){}; // Program loop
} // END MAIN
#pragma interruptlow LowISR
void LowISR(void)
{
}
////////////////////////////////////////
#pragma interruptlow HighISR
void HighISR(void)
{
ISR();
}
////////////////////////////////////////
#pragma code lowVector=0x18
void LowVector(void){_asm goto LowISR _endasm}
#pragma code highVector=0x08
void HighVector(void){_asm goto HighISR _endasm}
#pragma code
///////////////////////////////////////////////////////////////
void ISR(void)
{
T0CONbits.TMR0ON = 1; //Disable Timer0
INTCONbits.TMR0IF = 0; //Clear Timer 0 Interrupt Flag
LATDbits.LATD4 =~LATDbits.LATD4 ;// toggle the led
//write some code section here.
}
Any kind of feedback would be apperciable !
Thanks.
Greetings!
Do any of you know why my code ain't working?
#include <p18F46J50.h> // Always include the header file
//Defaut pragma code for 18F46J50
//#pragma config WDTEN = OFF //WDT disabled (enabled by SWDTEN bit)
#pragma config PLLDIV = 3 //Divide by 3 (12 MHz oscillator input)
#pragma config STVREN = ON //stack overflow/underflow reset enabled
//#pragma config XINST = OFF //Extended instruction set disabled
#pragma config CPUDIV = OSC1 //No CPU system clock divide
#pragma config CP0 = OFF //Program memory is not code-protected
//#pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB
#pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF //Two-Speed Start-up disabled
#pragma config WDTPS = 32768 //1:32768
#pragma config DSWDTOSC = INTOSCREF //DSWDT uses INTOSC/INTRC as clock
//#pragma config RTCOSC = T1OSCREF //RTCC uses T1OSC/T1CKI as clock
//#pragma config DSBOREN = OFF //Zero-Power BOR disabled in Deep Sleep
//#pragma config DSWDTEN = OFF //Disabled
#pragma config DSWDTPS = 8192 //1:8,192 (8.5 seconds)
//#pragma config IOL1WAY = OFF //IOLOCK bit can be set and cleared
#pragma config MSSP7B_EN = MSK7 //7 Bit address masking
#pragma config WPFP = PAGE_1 //Write Protect Program Flash Page 0
#pragma config WPEND = PAGE_0 //Start protection at page 0
#pragma config WPCFG = OFF //Write/Erase last page protect Disabled
#pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored
#pragma config T1DIG = ON //Sec Osc clock source may be selected
#pragma config LPT1OSC = OFF //high power Timer1 mode
void ISR(void) ;
void main(void)
{
unsigned int timerValue = 1;
// Timer0 configuration
T0CONbits.TMR0ON = 0; // Stop the timer
T0CONbits.T08BIT = 0; // Run in 16-bit mode
T0CONbits.T0CS = 0; // Use system clock to increment timer
T0CONbits.PSA = 0; // A prescaler is assigned for Timer0
T0CONbits.T0PS2 = 0; // Use a 1:256 prescaler
T0CONbits.T0PS1 = 0;
T0CONbits.T0PS0 = 0;
TMR0L=timerValue ;
TMR0H=(timerValue>>8);
INTCONbits.GIEH = 1; // enable global interrupt
INTCONbits.TMR0IE = 1;// enable TIM0 interrupt
INTCONbits.TMR0IF = 0;// clear TIM0 interrupt flag
// LED configuration
TRISDbits.TRISD4 = 0; // Configure RD4, pin 2, as an output
LATDbits.LATD4=0; // pin is low
T0CONbits.TMR0ON = 1; // Start the timer
while(1){}; // Program loop
} // END MAIN
#pragma interruptlow LowISR
void LowISR(void)
{
}
////////////////////////////////////////
#pragma interruptlow HighISR
void HighISR(void)
{
ISR();
}
////////////////////////////////////////
#pragma code lowVector=0x18
void LowVector(void){_asm goto LowISR _endasm}
#pragma code highVector=0x08
void HighVector(void){_asm goto HighISR _endasm}
#pragma code
///////////////////////////////////////////////////////////////
void ISR(void)
{
T0CONbits.TMR0ON = 1; //Disable Timer0
INTCONbits.TMR0IF = 0; //Clear Timer 0 Interrupt Flag
LATDbits.LATD4 =~LATDbits.LATD4 ;// toggle the led
//write some code section here.
}
Any kind of feedback would be apperciable !
Thanks.