mmmary
Newbie level 5
Hi , i'm doing a project with pic16f1805 , i use a library rs485 from micro c for pic , i need to use interruption in reception of data i simulate with proteus the data is transmitting from master but the 's no interrupt for receive .please can someone help me this is my code : .
Code:
char Dummy ;
char dat[10];
char cnt [10] ;
int i,j ;
sbit rs485_rxtx_pin at RB6_bit; // set transcieve pin
sbit rs485_rxtx_pin_direction at TRISB6_bit;
bit etat ;
bit etat_1;
bit etat_2;
void interrupt (void)
{
if (INTCON.IOCIF==1)
{
if ((PORTA.f2==1 ) && (IOCAF.IOCAF2 ==1))
{PORTC.f6= 1;
PORTC.f7= 0;
etat=1;
Dummy=PORTA ;
IOCAF.IOCAf2=0 ;
}
if ((PORTA.f3==1 ) && (IOCAF.IOCAF3 ==1))
{PORTC.f7= 1;
PORTC.f6= 0;
etat_1=1;
Dummy=PORTA ;
IOCAF.IOCAf3=0 ;
}
if ((PORTA.f0==1 ) && (IOCAF.IOCAF0 ==1))
{PORTC.f3= 1;
PORTC.f4= 0;
Dummy=PORTA ;
IOCAF.IOCAf0=0 ;
}
if ((PORTA.f1==1 ) && (IOCAF.IOCAF1 ==1))
{PORTC.f3= 0;
PORTC.f4= 1;
Dummy=PORTA ;
IOCAF.IOCAf1=0 ;
}
if ((PORTB.f4==1 ) && (IOCBF.IOCBF4 ==1))
{PORTC.f7= 0;
PORTC.f6= 0;
etat_2=1;
Dummy=PORTB ;
IOCBF.IOCBf4=0 ;
}
INTCON.IOCIF=0;
}
else if ( ( PIR1.RCIF==1) )
{
Dummy=RCREG;
RS485Slave_Receive(dat);
if (dat[5])
{ dat[5]=0;}
if (( dat[4] ) )
{
dat[4]=0;
switch (dat[2])
{
case 1 : 0x01 ;
PORTC.F6=1;
PORTc.F5=1;
case 2 : 0x02 ;
PORTC.F7=1;
case 3 : 0x03 ;
PORTC.F6=0;
PORTC.f7=0;
}
}
PIR1.RCIF=0;
}
}
void main() {
ANSELA=ANSELB=ANSELC=0;
CM1CON0.C1ON= CM2CON0.C2ON=0;
TRISC=0b00000111;
TRISA=0b00000111;
TRISB=0b00010000;
INTCON.GIE=1;
INTCON.IOCIE=1;
INTCON.IOCIF=0;
IOCAP=0b00001111 ;
IOCAP.IOCAP1=1;
IOCBP=0b00010000 ;
PORTC.F0=0;
PORTC.F2=0;
PORTC.F3=0;
PORTC.F4=0;
PORTC.F5=0;
PORTC.F6=0;
PORTC.F7=0;
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1;
RCIF_bit = 0;
if (PORTA.F1==1)
{PORTC.F3=0;
PORTC.F4=1;
UART1_Init(9600); // initialize UART1 module
RS485Slave_Init(160);
}
if (PORTA.F0==1)
{PORTC.F3=1;
PORTC.F4=0;
UART1_Init(9600); // initialize UART1 module
Delay_ms(5);
RS485Master_Init();
}
do {
if (etat==1)
{
dat[0] = 0xAA;
dat[1] = 0xF0;
dat[2] = 0x0F;
dat[3]=0 ;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,1,160);
PORTC.f5=1;
Delay_ms (100);
PORTC.F5=0 ;
Delay_ms (100);
}
if (etat_1==1)
{
dat[0] = 0xAA;
dat[1] = 0xF0;
dat[2] = 0xFF;
dat[3]=0 ;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,1,160);
PORTC.f5=1;
Delay_ms (100);
PORTC.F5=0 ;
Delay_ms (100);
}
if (etat_2==1)
{
dat[0] = 0xAA;
dat[1] = 0xF0;
dat[2] = 0x0F;
dat[3]=0 ;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,1,160);
PORTC.f5=1;
Delay_ms (100);
PORTC.F5=0 ;
Delay_ms (100);
}
} while(1) ;
}