![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hy, am getting this error message while building a project on MPLAB v8.0
Error - could not find definition of symbol 'SPBRG' in file 'C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o'. i checcked and found that p18f4620.h defines this SPBRG. what could be possible error cause. thanks |
|
|
|
|
|
|
(permalink) |
|
Does you program have the line
#include <p18f4620.h> A quick and dirty way to figure out if the .h is being included is to create a syntax error in the .h file. Just type sdfsdfsfsf or similar junk at the start of the file. Be sure to remove junk once inclusion is verified.
__________________
search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, Homepage The 15 Minute Printed Circuit Board! (+drill time) |
|
|
|
|
|
|
(permalink) |
|
you are right. the p18f4620.h is not included. no syntext error shows.
but the source file UARTIntC.c contains th efollowing lines: #include "UARTIntC.h" // target specific file will go here #include <p18f4620.h> so p18f4620.h should included. if not then what modification should be done. Another confusion is that i put all .c , .lkr and .h file in a folder named project ISR on the desktop. Then why execution of the following 2 lines shows the C:\Program Files\Microchip\MPASM Suite Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4620 "UARTIntC.c" -fo="C:\DOCUME~1\Khan\Desktop\PROJEC~1\UARTIntC.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- Executing: "C:\Program Files\Microchip\MPASM Suite\_mplink.exe" "C:\Program Files\Microchip\MPASM Suite\LKR\18f4620.lkr" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o" /o"test1.cof" /M"test1.map" /W |
|
|
|
|
|
|
(permalink) |
|
Post the code, be sure to use CODE tags generated by # in the editor menu. It is between the quote and the "<>" icons.
I am guessing that there are #ifdefs in the code that are keeping the include from working. The files shown in the MPLAB project window are used in the build. Remove the current files under lkr and headers and add the files from your project directory. They will have the same names but come from different places.
__________________
search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, Homepage The 15 Minute Printed Circuit Board! (+drill time) |
|
|
|
|
|
|
(permalink) |
|
I am not sure whether you really ask to post this code i used in UARTIntC.C .
Sorry if i misunderstood. Code:
#include "UARTIntC.h"
// target specific file will go here
#include <p18f4620.h>
// status flags of receive and transmit buffers
struct status vUARTIntStatus;
// variable definitions
#if TXON
unsigned char vUARTIntTxBuffer[TX_BUFFER_SIZE];
unsigned char vUARTIntTxBufDataCnt;
unsigned char vUARTIntTxBufWrPtr;
unsigned char vUARTIntTxBufRdPtr;
#endif
#if RXON
unsigned char vUARTIntRxBuffer[RX_BUFFER_SIZE];
unsigned char vUARTIntRxBufDataCnt;
unsigned char vUARTIntRxBufWrPtr;
unsigned char vUARTIntRxBufRdPtr;
#endif
/*********************************************************************
* Function: void UARTIntInit(void)
* PreCondition: None
* Input: None
* Output: None
* Side Effects: None
* Stack Requirements: 1 level deep
* Overview: This function initialises UART peripheral.This
* function need to be called before using
* UARTIntPutChar and UARTIntGetChar functions to
* send and receive the characters.
********************************************************************/
void UARTIntInit(void)
{
// Intialising the status variables and circular buffer
// variables .
#if TXON
vUARTIntStatus.UARTIntTxBufferFull = 0;
vUARTIntStatus.UARTIntTxBufferEmpty = 1;
vUARTIntTxBufDataCnt = 0;
vUARTIntTxBufWrPtr = 0;
vUARTIntTxBufRdPtr = 0;
#endif
#if RXON
vUARTIntStatus.UARTIntRxBufferFull = 0;
vUARTIntStatus.UARTIntRxBufferEmpty = 1;
vUARTIntStatus.UARTIntRxError = 0;
vUARTIntStatus.UARTIntRxOverFlow = 0;
vUARTIntRxBufDataCnt = 0;
vUARTIntRxBufWrPtr = 0;
vUARTIntRxBufRdPtr = 0;
#endif
/* Initialising BaudRate value */
SPBRG = SPBRG_VAL;
TXSTAbits.BRGH = BRGH_VAL;
/* Initialising TX/RX port pins */
#if TXON
TRISCbits.TRISC6 = 0;
#endif
#if RXON
TRISCbits.TRISC7 = 1;
#endif
/* Setting priority */
#if TX_PRIORITY_ON
RCONbits.IPEN = 1;
IPR1bits.TXIP = 1;
#else
IPR1bits.TXIP = 0;
#endif
#if RX_PRIORITY_ON
RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
#else
IPR1bits.RCIP = 0;
#endif
/* Enabling Transmitter or Receiver */
#if TXON
TXSTAbits.TXEN = 1;
#endif
#if RXON
RCSTAbits.CREN = 1;
#endif
/* Enabling Serial Port */
RCSTAbits.SPEN = 1;
/* Enable the TX and RX. Interrupt */
#if TXON
PIE1bits.TXIE = 1;
#endif
#if RXON
PIE1bits.RCIE = 1;
#endif
/* Setting Global interrupt pins */
#if ((TX_PRIORITY_ON)|(RX_PRIORITY_ON))
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
#else
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
#endif
}
/*********************************************************************
* Function: unsigned char UARTIntPutChar(unsigned char)
* PreCondition: UARTIntInit()function should have been called.
* Input: unsigned char
* Output: unsigned char
* 0 - single character is successfully
* added to transmit buffer.
* 1 - transmit buffer is full and the
* character could not be added to
* transmit buffer.
*
* Side Effects: None
* Stack Requirements: 1 level deep
* Overview: This function puts the data in to transmit
* buffer. Internal implementation wise ,
* it places the argument data in transmit buffer
* and updates the data count and write pointer
* variables.
*
********************************************************************/
#if TXON
unsigned char UARTIntPutChar(unsigned char chCharData)
{
/* check if its full , if not add one */
/* if not busy send data */
if(vUARTIntStatus.UARTIntTxBufferFull)
return 0;
//critical code , disable interrupts
PIE1bits.TXIE = 0;
vUARTIntTxBuffer[vUARTIntTxBufWrPtr] = chCharData;
vUARTIntStatus.UARTIntTxBufferEmpty = 0;
vUARTIntTxBufDataCnt ++;
if(vUARTIntTxBufDataCnt == TX_BUFFER_SIZE)
vUARTIntStatus.UARTIntTxBufferFull = 1;
vUARTIntTxBufWrPtr++;
if(vUARTIntTxBufWrPtr == TX_BUFFER_SIZE)
vUARTIntTxBufWrPtr = 0;
PIE1bits.TXIE = 1;
return 1;
}
/*********************************************************************
* Function: unsigned char UARTIntGetTxBufferEmptySpace(void)
* PreCondition: UARTIntInit()function should have been called.
* Input: None
* Output: unsigned char
* 0 - There is no empty space in
* transmit buffer.
* number - the number of bytes of empty
* space in transmit buffer.
*
*
* Side Effects: None
* Stack Requirements: 1 level deep
* Overview: This function returns the number of bytes
* of free space left out in transmit buffer at
* the calling time of this function. It helps
* the user to further write data in to transmit
* buffer at once, rather than checking transmit
* buffer is full or not with every addition of
* data in to the transmit buffer.
********************************************************************/
unsigned char UARTIntGetTxBufferEmptySpace(void)
{
if(vUARTIntTxBufDataCnt < TX_BUFFER_SIZE)
return(TX_BUFFER_SIZE-vUARTIntTxBufDataCnt);
else
return 0;
}
#endif
/*********************************************************************
* Function: unsigned char UARTIntGetChar(unsigned char*)
* PreCondition: UARTIntInit()function should have been called.
* Input: unsigned char*
* Output: unsigned char
* 0 - receive buffer is empty and the
* character could not be read from
* the receive buffer.
* 1 - single character is successfully
* read from receive buffer.
* Side Effects: None
* Stack Requirements: 1 level deep
* Overview: This function reads the data from the receive
* buffer. It places the data in to argument and
* updates the data count and read pointer
* variables of receive buffer.
*
********************************************************************/
#if RXON
unsigned char UARTIntGetChar(unsigned char *chTemp)
{
if( vUARTIntStatus.UARTIntRxBufferEmpty)
return 0;
//critical code, disabling interrupts here keeps the
//access pointer values proper.
PIE1bits.RCIE = 0;
vUARTIntStatus.UARTIntRxBufferFull = 0;
*chTemp = vUARTIntRxBuffer[vUARTIntRxBufRdPtr];
vUARTIntRxBufDataCnt--;
if(vUARTIntRxBufDataCnt == 0 )
vUARTIntStatus.UARTIntRxBufferEmpty = 1;
vUARTIntRxBufRdPtr++;
if(vUARTIntRxBufRdPtr == RX_BUFFER_SIZE)
vUARTIntRxBufRdPtr = 0;
PIE1bits.RCIE = 1;
return 1;
}
/*********************************************************************
* Function: unsigned char UARTIntGetRxBufferDataSize(void)
* PreCondition: UARTIntInit()function should have been called.
* Input: None
* Output: unsigned char
* number - the number of bytes
* of data in receive buffer.
* Side Effects: None
* Stack Requirements: 1 level deep
* Overview: This function returns the number of bytes
* of data available in receive buffer at
* the calling time of this function. It helps
* the user to read data from receive buffer
* at once, rather than checking receive buffer
* is empty or not with every read of data from
* receive buffer.
********************************************************************/
unsigned char UARTIntGetRxBufferDataSize(void)
{
return vUARTIntRxBufDataCnt;
}
#endif
/*********************************************************************
* Function: void UARTIntISR(void)
* PreCondition: UARTIntInit() function should have been called.
* Input: None
* Output: None
* Side Effects: None
* Stack Requirements: 2 level deep
* Overview: This is the Interrupt service routine which is
* called in the user application's ISR portion.
* This function actually sends the data from
* transmit buffer to USART and updates the data
* count and read pointer variables of transmit
* buffer. For the receive portion, it reads the
* data from USART and places the data in to
* receive buffer (if no errors occured) and
* updates data count and write pointer variables
* of receive buffer. If the receive buffer is
* full and it receives more data error flag is
* set.If frame errors(FERR) occur it sets the
* error flag. If over flow errors(OERR) occurs,
* it clears and sets the CREN bit, so that
* USART can receive further data.
********************************************************************/
void UARTIntISR(void)
{
#if RXON
unsigned char chTemp;
#endif
#if TXON
if(PIR1bits.TXIF & PIE1bits.TXIE)
{
if(!vUARTIntStatus.UARTIntTxBufferEmpty)
{
TXREG = vUARTIntTxBuffer[vUARTIntTxBufRdPtr];
if(vUARTIntStatus.UARTIntTxBufferFull)
vUARTIntStatus.UARTIntTxBufferFull = 0;
vUARTIntTxBufDataCnt--;
if(vUARTIntTxBufDataCnt == 0)
vUARTIntStatus.UARTIntTxBufferEmpty = 1;
vUARTIntTxBufRdPtr++;
if(vUARTIntTxBufRdPtr == TX_BUFFER_SIZE)
vUARTIntTxBufRdPtr = 0;
}
else
{
PIE1bits.TXIE = 0;
}
}
#endif
#if TXON_AND_RXON
else if( PIR1bits.RCIF & PIE1bits.RCIE)
#elif TXOFF_AND_RXON
if( PIR1bits.RCIF & PIE1bits.RCIE)
#endif
#if RXON
{
if(RCSTAbits.FERR) /* FERR error condition */
{
chTemp = RCREG;
vUARTIntStatus.UARTIntRxError = 1;
}
else if (RCSTAbits.OERR) /* OERR error condition */
{
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
chTemp = RCREG;
vUARTIntStatus.UARTIntRxError = 1;
}
else if ( vUARTIntStatus.UARTIntRxBufferFull)
{
chTemp = RCREG;
vUARTIntStatus.UARTIntRxOverFlow = 1;
}
else if(!vUARTIntStatus.UARTIntRxBufferFull)
{
vUARTIntStatus.UARTIntRxOverFlow = 0;
vUARTIntStatus.UARTIntRxBufferEmpty = 0;
vUARTIntRxBuffer[vUARTIntRxBufWrPtr] = RCREG;
vUARTIntRxBufDataCnt ++;
if(vUARTIntRxBufDataCnt == RX_BUFFER_SIZE)
vUARTIntStatus.UARTIntRxBufferFull = 1;
vUARTIntRxBufWrPtr++;
if(vUARTIntRxBufWrPtr == RX_BUFFER_SIZE)
vUARTIntRxBufWrPtr = 0;
}
}
#endif
}
|
|
|
|
|
|
|
(permalink) |
|
I was looking for #ifdefs that would keep the .h from being included. Not the problem.
So the next thing would be that you are not compiling the UARTIntC.C that you edited. If you have a syntax error in UARTIntC.C will the compiler find it?
__________________
search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, Homepage The 15 Minute Printed Circuit Board! (+drill time) |
|
|
|
|
|
|
(permalink) |
|
i have added a c file named UARTIntC_main.c as a source file. this would be my main file that will call the ISR.
any change in UARTIntC.c shows as a syntax error. means compiler can trace it. the UARTIntC_main.c test code is as follows: Code:
#include "UARTIntC.h"
#include <p18fxxx.h>
void main (void)
{
SPBRG=15 // setup the USART for 19200 baud @ 20 MHz
TXSTA = 0x20; // setup USART transmit
RCSTA = 0x90; // setup USART receive
IPR1bits.TXIP = 1; // Use high priority interrupt
UARTIntISR(); // call of library module function
UARTIntInit(); // call of library module
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable all interrupts
}
/*********************************************************************
* Function: void UART_ISR(void)
*
* PreCondition: UART interrupt has occured
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: None
*
* Note: This function is supposed to be called in the ISR
* context.
********/
void UART_ISR(void)
{
// NOTE: All local variables used here should be declared static
static BYTE rxdata;
while (1) // loop forever
{
if(PIR1bits.RCIF) // Check for USART interrupt
{
rxdata = RCREG; // Get the byte
PIR1bits.RCIF = 0; // Clear the interrupt flag so we don't keep entering this ISR
// Copy the byte into the local FIFO, if it won't cause an overflow
if(RXHeadPtr != RXTailPtr - 1)
{
if((RXHeadPtr != vUARTRXFIFO + sizeof(vUARTRXFIFO)) || (RXTailPtr != vUARTRXFIFO))
{
*RXHeadPtr++ = i;
if(RXHeadPtr >= vUARTRXFIFO + sizeof(vUARTRXFIFO))
RXHeadPtr = vUARTRXFIFO;
}
}
}
}
}
|
|
|
|
|
|
|
(permalink) |
|
Have you got the right processor selected under the Configure->Select Device menu?
That's the reason I don't like #include <p18fxxx.h> Mike. |
|
|
|
|
|
|
(permalink) |
|
yap, i have selected PIC 18f4620. also have modified the UARTIntC_main.c test code and change #include <p18fxxx.h> to #include <p18f4620.h>
|
|
|
|
|
|
|
(permalink) |
|
the error message 'could not find definition of symbol SPBRG' still exists
|
|
|
|
|
|
|
(permalink) |
|
Am I right in thinking that p18f4620.h is still not included?
In mplab with MCC18 there is a icon that will export a makefile. It is near the build/make/buildall icons. Use it to generate a makefile which will tell you exactly which files are included and from where. It should tell you what you are doing wrong. If not post the output.
__________________
search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, Homepage The 15 Minute Printed Circuit Board! (+drill time) |
|
|
|
|
|
|
(permalink) |
|
I got the following. But don't get any idea exactly where is the problem.
Make: The target "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o" is out of date. Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4620 "UARTIntC.c" -fo="C:\DOCUME~1\Khan\Desktop\PROJEC~1\UARTIntC.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- Make: The target "C:\Documents and Settings\Khan\Desktop\project ISR\test1.cof" is out of date. Executing: "C:\Program Files\Microchip\MPASM Suite\_mplink.exe" "C:\Documents and Settings\Khan\Desktop\project ISR\18f4620.lkr" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o" /o"test1.cof" /M"test1.map" /W MPLINK 4.14, Linker Copyright (c) 2007 Microchip Technology Inc. Error - could not find definition of symbol 'SPBRG' in file 'C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o'. Errors : 1 Link step failed. BUILD FAILED: Mon Feb 18 20:52:04 2008 |
|
|
|
|
|
|
(permalink) |
|
You do not follow instruction well. That could be part of the problem
I asked you to post the exported MAKEFILE. Where is it??? To illustrate what to look for I have provided this one. Code:
# Exported from MPLAB IDE project `JuneBugDemoP.mcp' on Wed Feb 06 14:56:24 2008. "JuneBugDemoP.cof" : "demo3.o" "C:\MCC18\bin\mplink.exe" /l"C:\MCC18\lib" "C:\MCC18\lkr\18f1320i.lkr" "G:\CCS\LESSONS\JuneBugDemo\demo3.o" /o"JuneBugDemoP.cof" /M"JuneBugDemoP.map" /W "demo3.o" : "demo3.c" "G:\CCS\LESSONS\JuneBugDemo\demo3.c" "C:\MCC18\h\p18f1320.h" "C:\MCC18\bin\mcc18.exe" -p=18F1320 "demo3.c" -fo="demo3.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- clean : del "demo3.o" "JuneBugDemoP.cof" "JuneBugDemoP.cod" "JuneBugDemoP.hex" "JuneBugDemoP.lst" Code:
"demo3.o" : "demo3.c" "G:\CCS\LESSONS\JuneBugDemo\demo3.c" "C:\MCC18\h\p18f1320.h" The files have full path name. If you can read this you know what the build is trying to do. All the automagic GUI stuff is nice but when things go bad look at the makefile.
__________________
search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, Homepage The 15 Minute Printed Circuit Board! (+drill time) |
|
|
|
|
|
|
(permalink) |
|
i just change the position #include "UARTIntC.h" after #include <p18f4620.h>.
surprisingly get 'BUILD SUCCEEDED' thanks a lot |
|
|
|
|
|
|
(permalink) |
|
This is the makefile
Code:
# Exported from MPLAB IDE project `test 2.mcp' on Tue Feb 19 12:08:45 2008. "test 2.lib" : "UARTIntC.o" "C:\Program Files\Microchip\MPASM Suite\mplib.exe" /c "test 2.lib" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.o" "UARTIntC.o" : "UARTIntC.c" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.c" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.h" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.c" "C:\Documents and Settings\Khan\Desktop\project ISR\UARTIntC.def" "C:\MCC18\h\p18f4620.h" "C:\MCC18\bin\mcc18.exe" -p=18F4620 "UARTIntC.c" -fo="C:\DOCUME~1\Khan\Desktop\PROJEC~1\UARTIntC.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- clean : del "UARTIntC.o" "test 2.lib" |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Speedometer | Kiko | Micro Controllers | 131 | 29th November 2007 05:33 PM |
| PIC16F877 ADC programming with PicBasic Compiler | Erwin_Macaraig | Micro Controllers | 10 | 4th November 2004 10:46 AM |
| Symbol definition error in MPLAB IDE (for pic16f84) | trailrider | Micro Controllers | 7 | 28th September 2004 09:45 AM |
| Switcher CAD III help | zachtheterrible | General Electronics Chat | 6 | 1st August 2004 01:04 AM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 02:55 AM |