pic 18f458 interupts
Discussion in "PIC Microcontroller Discussion" started by kingrosekhan123 Jul 17, 2012.
Thu Jul 19 2012, 09:40 pm
@ kingrosekhan123
when timer overflow it will automatically go to a piece of code
here we will check interrupt occur due to what reason
when timer overflow it will automatically go to a piece of code
void chk_isr(void)
{
if (INTCONbits.TMR0IF==1)
T0_ISR();
}
here we will check interrupt occur due to what reason
Thu Jul 19 2012, 10:55 pm
#include <P18f458.h>
//#include <delay.h>
#pragma config PWRT =OFF
#pragma config BOR =OFF
#pragma config DEBUG =OFF
#pragma config OSC =HS // 4MHz Crystal, (HS oscillator)
#pragma config WDT =OFF // watch dog timer off
#pragma config LVP =OFF // Low voltage program off
void chk_isr(void);
void chk_data(void);
#pragma interrupt chk_isr
void chk_isr(void)
{if(INTCONbits.INT0IF==0)
chk_data();
}
#pragma code my_HiPrio_int=0x08
void my_HiPrio_int(void)
{_asm
GOTO chk_isr
_endasm
}
#pragma code
void main()
{
TRISBbits.TRISB6=1;
TRISBbits.TRISB0=0;
INTCONbits.INT0IF=0;
INTCONbits.INT0IE=1;
INTCONbits.GIE=1;
}
void chk_data(void)
{TRISBbits.TRISB6=1;
INTCONbits.INT0IF=0;
}
i wrote this code for,when INT0 is become 1 then RB6=1
but its not working
please see my code
//#include <delay.h>
#pragma config PWRT =OFF
#pragma config BOR =OFF
#pragma config DEBUG =OFF
#pragma config OSC =HS // 4MHz Crystal, (HS oscillator)
#pragma config WDT =OFF // watch dog timer off
#pragma config LVP =OFF // Low voltage program off
void chk_isr(void);
void chk_data(void);
#pragma interrupt chk_isr
void chk_isr(void)
{if(INTCONbits.INT0IF==0)
chk_data();
}
#pragma code my_HiPrio_int=0x08
void my_HiPrio_int(void)
{_asm
GOTO chk_isr
_endasm
}
#pragma code
void main()
{
TRISBbits.TRISB6=1;
TRISBbits.TRISB0=0;
INTCONbits.INT0IF=0;
INTCONbits.INT0IE=1;
INTCONbits.GIE=1;
}
void chk_data(void)
{TRISBbits.TRISB6=1;
INTCONbits.INT0IF=0;
}
i wrote this code for,when INT0 is become 1 then RB6=1
but its not working
please see my code
Fri Jul 20 2012, 11:55 am
void TIMER0_INIT(void)//Function for using Timer0 interrupt for 20ms to check key pressed
{
INTCON=0X20;
T0CON=0X06; //Set PSA for Bypassing Prescalor
TMR0H=0xFE;
TMR0L=0x4F;
INTCONbits.TMR0IF=0;
INTCONbits.TMR0IE=1;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;
T0CONbits.TMR0ON=1;
}
Take a look of init function read the datasheet of Microcontroller and related registers which you have to configure for timer interrupt.
{
INTCON=0X20;
T0CON=0X06; //Set PSA for Bypassing Prescalor
TMR0H=0xFE;
TMR0L=0x4F;
INTCONbits.TMR0IF=0;
INTCONbits.TMR0IE=1;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;
T0CONbits.TMR0ON=1;
}
Take a look of init function read the datasheet of Microcontroller and related registers which you have to configure for timer interrupt.
Fri Jul 20 2012, 05:13 pm
@ kingrosekhan123
In chk_data function u making a PORTB pin 6 as a input it should be output not an input
second thing is that here it should be PORT not a TRISB
now try the above code i hope it will work
#include <P18f458.h> #pragma config PWRT =OFF #pragma config BOR =OFF #pragma config DEBUG =OFF #pragma config OSC =HS // 4MHz Crystal, (HS oscillator) #pragma config WDT =OFF // watch dog timer off #pragma config LVP =OFF // Low voltage program off void chk_isr(void); void chk_data(void); #pragma interrupt chk_isr void chk_isr(void) { if(INTCONbits.INT0IF==0) chk_data(); } #pragma code my_HiPrio_int=0x08 void my_HiPrio_int(void) {_asm GOTO chk_isr _endasm } #pragma code void main(void) { TRISBbits.TRISB6=0; TRISBbits.TRISB0=0; INTCONbits.INT0IF=0; INTCONbits.INT0IE=1; INTCONbits.PEIE=1; INTCONbits.GIE=1; } void chk_data(void) { PORTBbits.RB6=1; INTCONbits.INT0IF=0; }
In chk_data function u making a PORTB pin 6 as a input it should be output not an input
second thing is that here it should be PORT not a TRISB
now try the above code i hope it will work
Powered by e107 Forum System