PIC16F628 | Hi-Tech C| Interrupt based UART Problem

Discussion in 'Embedded Systems and Microcontrollers' started by HallMark, Mar 16, 2012.

  1. HallMark

    Thread Starter Member

    Apr 3, 2011
    89
    5
    Hello,

    I am Using PIC16F628A and Hi-Tech Compiler for MPLAB I want to write routine for UART in which i want Receiving interrupt based,
    Here is Initialization i have done for UART. . . .

    Transmission works Perfectly and even polling based receiving works fine can anybody give me code for interrupt based routine please.

    Code ( (Unknown Language)):
    1.         TXSTA = 0x24;    
    2.  SYNC = 0;    
    3. SPEN = 1;    
    4. TXEN = 1;    
    5. BRGH = 1;    
    6. SPBRG = 129;      
    7. SREN = 0;    
    8. RCIE = 1;        // Interrupt Enable    
    9. CREN = 1;    
    10. GIE = 1;
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What do you plan to do, then you receive something on the UART. Here is the framewrok for an ISR in HI-Tech C
    Code ( (Unknown Language)):
    1.  
    2. #include <htc.h>
    3. /*
    4.  * Interrupt test for PIC
    5.  *
    6.  * Copyright (C)1997 HI-TECH Software.
    7.  * Freely distributable.
    8.  */
    9. static volatile long count;
    10. static volatile bit bad_intr;
    11. static void interrupt
    12. isr(void)   // Here be interrupt function - the name is
    13.     // unimportant.
    14. {
    15.  if(!T0IF)  // Was this a timer overflow?
    16.   bad_intr = 1; // NO! Shock horror!
    17.  count++;  // Add 1 to count - insert idle comment
    18.  T0IF = 0;  // Clear interrupt flag, ready for next
    19.  PORTB ^= 1;  // toggle bit 0 of Port B, to show we're alive
    20. }
    21. void
    22. main(void)
    23. {
    24.  /* setup stuff */
    25.  T0CS = 0;  // Timer increments on instruction clock
    26.  TRISB = 0xFE;  // Port B bit 0 is output
    27.  T0IE = 1;  // Enable interrupt on TMR0 overflow
    28.  GIE = 1;  // Global interrupt enable
    29.  for(;;)
    30.   CLRWDT(); // Idly kick the dog may not be needed if WDT is not enabled
    31.                   //If your app do not need WTD do not use it
    32. }
    33.  
     
    HallMark likes this.
  3. HallMark

    Thread Starter Member

    Apr 3, 2011
    89
    5
    Thanks a lot t06afre for your support Now I am able to figure out problem actually in initialization I was enabling PEIE bit for the peripheral interrupt. After Enabling that one It works perfectly.

    Thanks again.
     
Loading...