Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Usart receive interrupt

Status
Not open for further replies.

ragi

Junior Member level 3
Joined
Nov 18, 2015
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
251
Hi all,

I never used interrupt function before and want to use interrupt for usart receiver i.e I just for to glow an LED or set a flag whenever a byte or string is recieved. Help me in writing the code for this.

Thanks in advance.
 

You also need to tell us which processor you are using, which language you are using and which assembler/compiler you are using.

As Easyrider83 points out, there are plenty of examples and for many different processors if you search.

Brian.
 

Here is an example using pic18f4520 and mikro c.
Code:
void interrupt() iv 0x0008 ics ICS_AUTO
{
  Max_Control=0;
                   if(RCIF_bit==1){
                               if ((RCSTA.OERR )/*&& (RCIE_bit==1)*/){
                               RCSTA.CREN = 0;
                               Nop();
                               Nop();
                               RCSTA.CREN = 1;
                               Garbage=RCREG;
                               Garbage=RCREG;
                               RCIF_bit=0;
                               }
                   else{
                               sdata=RCREG;
                               input_string[index]=sdata;
                         }
                  }
}

void main{

TXSTA  = 0b00100000;
     RCSTA = 0b10010000;

     BAUDCON.BRG16 = 0;
     TXSTA.BRGH    = 0;
     //SPBRGH:SPBRG = 129;   //for 20MHz crystal
     SPBRG = 12;   //for 8MHz crystal

     /*UART1_Init(9600);
     Delay_ms(200);*/
     IPR1.RCIP = 1;
     IPR1.TXIP = 1;
     RCON.IPEN = 1;
     PIE1 = 0b00100000;  //RCIE bit enabled
     RCIP_bit=1;    // see IPR1
     while(1){

    }

}
 
  • Like
Reactions: ragi

    ragi

    Points: 2
    Helpful Answer Positive Rating
set receive pin as input pin ex.TRISBbits.TRISB7=1;
Enable reception RCSTAbits.CREN=1;
enable reception interrupt
enable global interrupt.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top