PIC16F628 | Hi-Tech C| Interrupt based UART Problem

Thread Starter

HallMark

Joined Apr 3, 2011
89
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.

Rich (BB code):
        TXSTA = 0x24;    
 SYNC = 0;     
SPEN = 1;     
TXEN = 1;     
BRGH = 1;     
SPBRG = 129;      
SREN = 0;     
RCIE = 1;        // Interrupt Enable     
CREN = 1;     
GIE = 1;
 

t06afre

Joined May 11, 2009
5,934
What do you plan to do, then you receive something on the UART. Here is the framewrok for an ISR in HI-Tech C
Rich (BB code):
#include <htc.h>
/*
 * Interrupt test for PIC 
 *
 * Copyright (C)1997 HI-TECH Software.
 * Freely distributable.
 */
static volatile long count;
static volatile bit bad_intr;
static void interrupt
isr(void)   // Here be interrupt function - the name is
    // unimportant.
{
 if(!T0IF)  // Was this a timer overflow?
  bad_intr = 1; // NO! Shock horror!
 count++;  // Add 1 to count - insert idle comment
 T0IF = 0;  // Clear interrupt flag, ready for next
 PORTB ^= 1;  // toggle bit 0 of Port B, to show we're alive
}
void
main(void)
{
 /* setup stuff */
 T0CS = 0;  // Timer increments on instruction clock
 TRISB = 0xFE;  // Port B bit 0 is output 
 T0IE = 1;  // Enable interrupt on TMR0 overflow
 GIE = 1;  // Global interrupt enable
 for(;;)
  CLRWDT(); // Idly kick the dog may not be needed if WDT is not enabled
                  //If your app do not need WTD do not use it
}
 

Thread Starter

HallMark

Joined Apr 3, 2011
89
What do you plan to do, then you receive something on the UART. Here is the framewrok for an ISR in HI-Tech C
Rich (BB code):
#include <htc.h>
/*
 * Interrupt test for PIC 
 *
 * Copyright (C)1997 HI-TECH Software.
 * Freely distributable.
 */
static volatile long count;
static volatile bit bad_intr;
static void interrupt
isr(void)   // Here be interrupt function - the name is
    // unimportant.
{
 if(!T0IF)  // Was this a timer overflow?
  bad_intr = 1; // NO! Shock horror!
 count++;  // Add 1 to count - insert idle comment
 T0IF = 0;  // Clear interrupt flag, ready for next
 PORTB ^= 1;  // toggle bit 0 of Port B, to show we're alive
}
void
main(void)
{
 /* setup stuff */
 T0CS = 0;  // Timer increments on instruction clock
 TRISB = 0xFE;  // Port B bit 0 is output 
 T0IE = 1;  // Enable interrupt on TMR0 overflow
 GIE = 1;  // Global interrupt enable
 for(;;)
  CLRWDT(); // Idly kick the dog may not be needed if WDT is not enabled
                  //If your app do not need WTD do not use it
}
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.
 
Top