Discussion in "PIC Microcontroller Discussion" started by    kingrosekhan123    Jul 17, 2012.
Thu Jul 19 2012, 09:40 pm
#11
@ kingrosekhan123
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
#12
#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
Fri Jul 20 2012, 11:55 am
#13
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.
Fri Jul 20 2012, 05:13 pm
#14
@ kingrosekhan123
#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

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm
oriminna
Sat May 04 2024, 08:28 pm
scaneraNom
Sat May 04 2024, 02:21 am
gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am