请问版主:1、PIC18F25K80的IO口RC0,RC1,RC2不能实现高低电平翻转,怎么回事?
2、CAN总线的不能实现接收中断怎么回事?源程序如下:
#pragma code low_vector=0x0018
void low_interrput(void)
{
if(INTCONbits.TMR0IF)
{
_asm GOTO timer0_isr _endasm
}
else
{
_asm GOTO CAN_isr _endasm
}
}
#pragma code
#pragma interruptlow CAN_isr
void CAN_isr(void)
{
// if(PIR3&0x01==0x01)
if(RXB0CONbits.RXFUL)
{
PIR3=0; //清接收中断标志
RxMessage->StdId=((u16)RXB0SIDH<<3)|(RXB0SIDL>>5);
RxMessage->DLC=RXB0DLC;
RxMessage->Data0= RXB0D0;
RxMessage->Data1=RXB0D1;
RxMessage->Data2=RXB0D2;
RxMessage->Data3=RXB0D3;
RxMessage->Data4=RXB0D4;
RxMessage->Data5=RXB0D5;
RxMessage->Data6=RXB0D6;
RxMessage->Data7=RXB0D7;
can_receive_flag =1 ;
RXB0CONbits.RXFUL=0; //打开接收缓冲器来接收新信息
}
// if(PIR3&0x02==0x02)
if(RXB1CONbits.RXFUL)
{
PIR3=0; //清接收中断标志
RXB1CONbits.RXFUL=0; //打开接收缓冲器来接收新信息
RxMessage->StdId=((u16)RXB1SIDH<<3)|(RXB1SIDL>>5);
RxMessage->DLC=RXB1DLC;
RxMessage->Data0=RXB1D0;
RxMessage->Data1=RXB1D1;
RxMessage->Data2=RXB1D2;
RxMessage->Data3=RXB1D3;
RxMessage->Data4=RXB1D4;
RxMessage->Data5=RXB1D5;
RxMessage->Data6=RXB1D6;
RxMessage->Data7=RXB1D7;
can_receive_flag =1 ;
}
}
//***************************
// CAN初始化 (Fosc/TQ)/(2*Fbus)=(BRP+1)
//***************************
void CAN_100k_INIT(void)
{
int a=0 ;
CANCON=0X80; //设置配置模式
while( CANSTAT&0X80==0) ; //等待进入配置模式
// Init device specific hardware for CAN
ECANCON =0X00; //扩展模式,扩展接收buffer0
CIOCON = 0x20; //设置IO口为CAN模式
LATBbits.LATB2 = 1;
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 1;
LATBbits.LATB5 = 1;
TRISBbits.TRISB5 = 0;
PORTBbits.RB5 = 0;
BRGCON1 =0x04 ;//SJW =1TQ;BRP=4;(100K)
BRGCON2 =0XB1; //随意编程,总线采样1次,SP1 =7TQ,PRS =2TQ
BRGCON3 =0X05; //SP2 =6TQ,不使能CAN BUS WAKEUP
RXB0CON =0X00; //只接受过滤器匹配的ID号信息
RXB1CON =0X00; //只接受过滤器匹配的ID号信息
RXB0SIDH=0X00; //设置接收缓冲器0 的标识符
RXB0SIDL=0X00;
RXB0DLC=0X00; //设置接收缓冲器0 的数据区长度
RXB0D0=0X00; //初始化接收缓冲器0 的数据区数据
RXB0D1=0X00;
RXB0D2=0X00;
RXB0D3=0X00;
RXB0D4=0X00;
RXB0D5=0X00;
RXB0D6=0X00;
RXB0D7=0X00;
RXF0SIDH=0x575>>3;//初始化接收滤波器0 和接收屏蔽,
RXF0SIDL=(0x575&0X07)<<5&0xf7;
RXF1SIDH=0x621>>3;//初始化接收滤波器0 和接收屏蔽,
RXF1SIDL=(0x621&0X07)<<5&0xf7;
RXF2SIDH=0x5c1>>3;;//初始化接收滤波器0 和接收屏蔽,
RXF2SIDL=(0x5c1&0X07)<<5&0xf7;
RXF3SIDH=0x470>>3;//初始化接收滤波器0 和接收屏蔽,
RXF3SIDL=(0x470&0X07)<<5&0xf7;
RXF4SIDH=0x635>>3;//初始化接收滤波器0 和接收屏蔽,
RXF4SIDL=(0x635&0X07)<<5&0xf7;
RXF5SIDH=0x527>>3;//初始化接收滤波器0 和接收屏蔽,
RXF5SIDL=(0x527&0X07)<<5&0xf7;
RXM0SIDH=0xff ;//0Xff;
RXM0SIDL=0xff;//0Xff;
RXM1SIDH=0xff;//0Xff;
RXM1SIDL=0xff;//0Xff;
CANCON=0X00; //设置CAN为正常自监听操作模式
while(CANSTAT!=0){;}
PIE3=0X03; //使能接收缓冲器0 的接收中断
IPR3=0X00; //接收缓冲器0 的接收中断为最高优先级
PIR3=0X00; //初始化CAN的中断,清所有中断标志
}
配置的使能缓冲器0和1中断,但是程序在仿真的过程中看寄存器PIE3却是0x02.明明写的时候0x03怎么变成0X02了,其他地方没有设置PIE3的。请高手们指点。
|