PIC RB0外部中断程序
2019-04-15 11:56发布
生成海报
#include
#include
//__CONFIG (CP_OFF&WDTE_OFF& BOREN_OFF&PWRTE_OFF &FOSC_HS&WRT_OFF&LVP_OFF&CPD_OFF);
__CONFIG (CP_OFF&WDTE_OFF&BOREN_ON&PWRTE_OFF&FOSC_HS&WRT_OFF&LVP_OFF&CPD_OFF);
//__CONFIG (CP_OFF&WDTE_OFF& BOREN_OFF&PWRTE_OFF &FOSC_HS&WRT_OFF&LVP_OFF&CPD_OFF);
//__CONFIG (CP_OFF&WDTE_ON& BOREN_OFF&PWRTE_ON&FOSC_HS&WRT_OFF&LVP_OFF&CPD_OFF);
/*配置位
CP_OFF,代码保护位,程序存储器代码保护关闭;
WDTE_OFF,看门狗定时器使能位,看门狗定时器关闭,可以通过WDTCON寄存器的SWDTEN位使能;
BOREN_OFF,掉电复位选择位,掉电复位关闭;
PWRTE_OFF,上电定时器使能位,上电定时器关闭;
FOSC_HS,振荡器选择位,高速晶振或谐振器在RA6/OSC2/CLKOUT和RA7/OSC1/CLKIN;
WRT_OFF,闪存程序存储器自写使能位,写保护关闭;
LVP_OFF,低电压编程使能位,RB3引脚有数字I/O,使用MCLK上的HV(高电压)来编程;
CPD_OFF,数据代码保护位,数据存储器代码保护关闭;
*/
//__CONFIG (0x2FF2);
#define uchar unsigned char
#define uint unsigned int
#define LEDA RB3//定义灯1
#define RET RB0//定义灯1
void delay(unsigned int n);
void interrupt ISR(void);
uchar count;
main()
{
TRISB=0X01;
//
PORTB=0x09;
ANSEL=0x00;
ANSELH=0x00;
//
//
GIE = 1;
PEIE = 1; //允许外设中断
RBIE = 1;
//INTE = 1;
//IOCB = 0x01; //B0电平变化中断;
WPUB = 0X01;
OPTION_REG=0x00;
INTEDG=0;//当INTEDG位(OPTION<6>)被清零时在下降沿触发
INTE = 0;
INTF=0;
INTE = 1;
INTF=0;
//INTCON=
//WPUB = 0X0F;
//RBIF = 0;
//TRISB=0X01;
//PORTB=0X00;//红
RB3=0;//红灯
//count=0;
//RBIF = 0;
while(1)
{
if((count%2)==0)
{RB3=0;}
else
{RB3=1;}
//RB3=0;//红灯
////RET=0;
//delay(1000);
////delay(1000);
//
//RB3=1;
////RET=1;
//delay(1000);
////delay(1000);
}
}
//延时(n)ms
void delay(unsigned int n)
{
unsigned int j;
unsigned int k;
for(j=0;j0;k--)
NOP();
}
void interrupt ISR(void)
{
if(INTF==1) //电平变化中断
{
// PortB0Intrupt = PortB0Intrupt+ 1;
// PORTB = PORTB;
// RD0 = ~RD0;
// SendToPrin(&PortB0Intrupt,2);
RB3=1;//黄
count++;
INTF=0;
// RBIF = 0;
}
}
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮