Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
after doing the successful 'built' i tried to 'program' the PIC. that also programmed successfully. but whenever i connect the hyperterminal it shows previous program output as i did test program on the PIC as a zigbee node. it means previous program is not erased. how can i erase the flash?
#ifndef _UARTIntC_H
#define _UARTIntC_H
#include "UARTIntC.def"
/* Constants found in .def file are given readable names*/
#define TX_BUFFER_SIZE UARTINTC_TX_BUFFER_SIZE
#define RX_BUFFER_SIZE UARTINTC_RX_BUFFER_SIZE
#ifdef UARTINTC_TXON
#define TXON 1
#elif UARTINTC_TXOFF
#define TXON 0
#endif
#ifdef UARTINTC_RXON
#define RXON 1
#elif UARTINTC_RXOFF
#define RXON 0
#endif
#define TXON_AND_RXON ((TXON) & (RXON))
#define TXOFF_AND_RXON ((!(TXON)) & (RXON))
// User can change the following values and accordingly
// the ISR location in the main application.
// Can they be MPAM module parameters?
#define BRGH_VAL 1
#define TX_PRIORITY_ON 0
#define RX_PRIORITY_ON 0
// More error check to be done and the following
// code can be modified.
// If SPBRG is out of range, it won't let the
// main application be compiled and linked.
#define SPBRG_V1 (UART_CLOCK_FREQ / UARTINTC_BAUDRATE)
#define SPBRG_V2 SPBRG_V1/16
#define SPBRG_VAL (SPBRG_V2 - 1)
# if (SPBRG_VAL > 255)
#error Calculated SPBRG value is out of range
#elif (SPBRG_VAL < 10)
#error Calculated SPBRG value is out of range
#endif
struct status
{
unsigned UARTIntTxBufferFull :1;
unsigned UARTIntTxBufferEmpty :1;
unsigned UARTIntRxBufferFull :1;
unsigned UARTIntRxBufferEmpty :1;
unsigned UARTIntRxOverFlow :1;
unsigned UARTIntRxError:1;
};
extern struct status vUARTIntStatus;
// variables representing status of transmission buffer and
// transmission buffer it self are declared below
#if TXON
extern unsigned char vUARTIntTxBuffer[TX_BUFFER_SIZE];
extern unsigned char vUARTIntTxBufDataCnt;
extern unsigned char vUARTIntTxBufWrPtr;
extern unsigned char vUARTIntTxBufRdPtr;
#endif
// variables referring the status of receive buffer.
#if RXON
extern unsigned char vUARTIntRxBuffer[RX_BUFFER_SIZE];
extern unsigned char vUARTIntRxBufDataCnt;
extern unsigned char vUARTIntRxBufWrPtr;
extern unsigned char vUARTIntRxBufRdPtr;
#endif
// functions offered by this module
#if RXON
// function returns a character from receive buffer
unsigned char UARTIntGetChar(unsigned char*);
// function returns the number of characters in receive buffer
unsigned char UARTIntGetRxBufferDataSize(void);
#endif
#if TXON
// function to put a character in Transmit buffer
unsigned char UARTIntPutChar(unsigned char);
// function returns size of the empty section of Transmit buffer
unsigned char UARTIntGetTxBufferEmptySpace(void);
#endif
// Initialisation of the module
void UARTIntInit(void);
// Interrupt service routine supplied by the module.This need to be
// called from ISR of the main program.
void UARTIntISR(void);
// Other useful macros
#define mDisableUARTTxInt() PIE1bits.TXIE = 0
#define mEnableUARTTxInt() PIE1bits.TXIE = 1
#define mDisableUARTRxInt() PIE1bits.RCIE = 0
#define mEnableUARTRxInt() PIE1bits.RCIE = 1
#define mSetUARTRxIntHighPrior() \
RCONbits.IPEN = 1;\
IPR1bits.RCIP = 1
#define mSetUARTRxIntLowPrior() IPR1bits.RCIP = 0
#define mSetUARTTxIntHighPrior()\
RCONbits.IPEN = 1;\
IPR1bits.TXIP = 1
#define mSetUARTTxIntLowPrior() IPR1bits.TXIP = 0
#define mSetUART_BRGHHigh() TXSTAbits.BRGH = 1
#define mSetUART_BRGHLow() TXSTAbits.BRGH = 0
#define mSetUART_SPBRG(iBRGValue)\
RCSTAbits.SPEN = 0;\
SPBRG = iBRGValue;\
RCSTAbits.SPEN = 1
#define mSetUARTBaud(iBaudRate)\
do{\
#define SPBRG_V11 (UART_CLOCK_FREQ / UARTINTC_BAUDRATE)\
#define SPBRG_V21 SPBRG_V11/16\
#define SPBRG_VAL (SPBRG_V21 - 1)\
#if (SPBRG_VAL > 255)\
#error Calculated SPBRG value is out of range\
#elif (SPBRG_VAL < 10)\
#error Calculated SPBRG value is out of range\
#endif\
RCSTAbits.SPEN = 0;\
SPBRG = iBaudRate;\
RCSTAbits.SPEN = 1;\
}while(false)
#include "UARTIntC.h"
#include "delays.h"
#include <p18f4620.h>
void low_isr(void);
// serial interrupt taken as low priority interrupt
#pragma code uart_int_service = 0x08
void uart_int_service(void)
{
_asm goto low_isr _endasm
}
#pragma code
#pragma interruptlow low_isr save=section(".tmpdata")
void low_isr(void)
{
// call of library module function, MUST
UARTIntISR();
}
void main(void)
{
// Test data array
unsigned char cArray[10]
= { 'A','B', 'C', 'D', 'E', 'F', 'G','H','I' , 'J'};
// temporary local array
unsigned char writtenArray[10];
// local variables for all test cases and their initialisation
unsigned char chData;
unsigned char *pReadArray;
unsigned char *pWriteArray;
unsigned char j = 0;
unsigned char i = 0;
unsigned char l = 0;
unsigned char k = 0;
pReadArray = pWriteArray = writtenArray;
// call of library module , MUST
UARTIntInit();
// TEST
// Chunk of data is sent from PC to micro. Data received at micro is
// read in to temporary buffer. The data is sent back to PC. Here
// reception and transmission is done independently.
while(1)
{
l = 0;
l = UARTIntGetRxBufferDataSize();
while(l > 0)
{
if(UARTIntGetChar(pReadArray))
{
l--; pReadArray++;
if(pReadArray == (writtenArray + 10))
pReadArray = writtenArray;
}
}
if((pWriteArray < pReadArray) || ((pWriteArray - pReadArray) == 9 ))
{
if(!vUARTIntStatus.UARTIntTxBufferFull)
{
UARTIntPutChar(*pWriteArray);
i--; pWriteArray++;
if(pWriteArray == (writtenArray + 10))
pWriteArray = writtenArray;
}
}
}
}
It was used in UARTIntC.h.Pommie said:SPBRG only appears to be used in a #define (in the .h) and shouldn't have thrown an error. Or, did I miss something?
Mike.
3v0 said:It was used in UARTIntC.h.
He included UARTIntC.h prior to including p18f4620.h so SPBRG was undefined in UARTIntC.h . He needed to include p18f4620.h first.
I have run so do not have time to answer the new question.
Pommie said:You missed the point. SPBRG is only used in a #define and therefore is not evaluated in the .h file.
If I do,
#define crap nonsense
then it will compile fine unless I use crap.
As to the original error, I have no idea. I just don't understand this solution.
Mike.