Hi, i have problem in serial interrupt,,when i initialize "gie=1" , it not take isr....then how can i write the code for interrupt...it's urgent plz help me....
Hi, i have problem in serial interrupt,,when i initialize "gie=1" , it not take isr....then how can i write the code for interrupt...it's urgent plz help me....
did you Enable external interrupts INTE from RB0 did you make portb as output...once post your main function so that i can found out error in your code..
CHECK THIS CODE This code will read in the UART data and store the result
in an array.
unsigned cnt, cnt1;
char rxchar, i = 0, flag = 0; // Variable for storing the data from UART and array counter
unsigned char rxarray[80]; // array to store the received charaters
unsigned short j;
void interrupt() {
if (PIR1.RCIF) { // test the interrupt for uart rx
rxchar = Uart1_Read(); //
rxarray = rxchar;
i++;
// ******************************************************
// Only select one of the following statements
if (rxchar == 36) { // select this if looking for a terminating character
flag = 1;
} // end if (rxchar == "$")
PIR1.RCIF = 0; // clear RCIF
} // end if (PIR1.RCIF)
}
void main() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
UART1_Init(9600);
Delay_ms(500); // Wait for UART module to stabilize
PIE1.RCIE = 1; //enable USART receiver interrupt bit
INTCON.PEIE = 1; //enable peripheral interrupt bit
INTCON.GIE = 1; //enable global interrupt bit
while (1) {
if (flag ==1) {
j = 0;
while(j < i) {
Uart1_Write(rxarray[j]);
j++;
} // end while(rxarray)
i = 0;
flag = 0;
} // end if (flag)
}
}
In this example there is no check agianst buffer overflow and framing errors.