các anh ơi cho em hỏi đoạn code này đúng hay sai. nếu sai thì chỉ dùm
#include"P24FJ128GA306.h"
#define LED_1 LATBbits.RB0
#define LED_2 LATBbits.RB1
#define LED_1 PORTBbits.RB0
#define LED_2 PORTBbits.RB1
#define BUT_1 PORTBbits.RB2
#define BUT_2 PORTBbits.RB3
//function prototype
void CONFIG_EXINT(void);//funtion use to configure intterrupt module
void ExINT_isr(void);//interrupt service program
int main()
{
TRISB=0X00C0;//pin RB2,RB3 la pin in
CONFIG_EXINT();
while(1)
{
//other code
}
}
void CONFIG_EXINT(void)
{
// config
_INT1IE=1;//cho phep ngat
_INT1IF=0;//
_INT1IP=1;//muc ngat uu tien
INTCON2 = 0x0004;// dia chi vecto ngat
}
#pragma code interrupt_vector=0x0004
void interrupt_vector()
{
_asm
goto ExINT_isr
_endasm
}
# pragma Interrupt ExINT_isr
void ExINT_isr()
{
if((PORTBbits.RB2==0)&&(PORTBbits.RB3==0))
{
LED_1=1;//ca hai led deu sang
LED_2=1;
_INT1IF=0;//reset flag
}
else if(PORTBbits.RB2==0)//neu co su kien nhan nut BUT_0
{
LED_1=1;
LED_2=0;
_INT1IF=0;//reset flag
}
else if(PORTBbits.RB3==0)// neu nhan nut RB_1
{
LED_1=0;
LED_2=1;
_INT1IF=0;//reset flag
}
else
{
LED_1=0;
LED_2=0;
}
}
#include"P24FJ128GA306.h"
#define LED_1 LATBbits.RB0
#define LED_2 LATBbits.RB1
#define LED_1 PORTBbits.RB0
#define LED_2 PORTBbits.RB1
#define BUT_1 PORTBbits.RB2
#define BUT_2 PORTBbits.RB3
//function prototype
void CONFIG_EXINT(void);//funtion use to configure intterrupt module
void ExINT_isr(void);//interrupt service program
int main()
{
TRISB=0X00C0;//pin RB2,RB3 la pin in
CONFIG_EXINT();
while(1)
{
//other code
}
}
void CONFIG_EXINT(void)
{
// config
_INT1IE=1;//cho phep ngat
_INT1IF=0;//
_INT1IP=1;//muc ngat uu tien
INTCON2 = 0x0004;// dia chi vecto ngat
}
#pragma code interrupt_vector=0x0004
void interrupt_vector()
{
_asm
goto ExINT_isr
_endasm
}
# pragma Interrupt ExINT_isr
void ExINT_isr()
{
if((PORTBbits.RB2==0)&&(PORTBbits.RB3==0))
{
LED_1=1;//ca hai led deu sang
LED_2=1;
_INT1IF=0;//reset flag
}
else if(PORTBbits.RB2==0)//neu co su kien nhan nut BUT_0
{
LED_1=1;
LED_2=0;
_INT1IF=0;//reset flag
}
else if(PORTBbits.RB3==0)// neu nhan nut RB_1
{
LED_1=0;
LED_2=1;
_INT1IF=0;//reset flag
}
else
{
LED_1=0;
LED_2=0;
}
}