doubts about PIC microcontrollers

MaxHeadRoom

Joined Jul 18, 2013
30,661
If I knew about these things before I would have ordered all 18F instead of 16F.
For me it is all what you are comfortable with, as I mentioned before I started with 16f just because of the programs and tutorials out there were based on this, after I got a handle on the 16f I came across a copy of Dave Benson's Mov'n-on-up that explains to some degree (not all) the added features of 18f and if using asm especially, shows a lot of the advantages, which are easy to migrate to.
I would add all the 16f projects I happened to program worked well before the discovery of the LATx in the 18f's
Max.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
For me it is all what you are comfortable with, as I mentioned before I started with 16f just because of the programs and tutorials out there were based on this, after I got a handle on the 16f I came across a copy of Dave Benson's Mov'n-on-up that explains to some degree (not all) the added features of 18f and if using asm especially, shows a lot of the advantages, which are easy to migrate to.
I would add all the 16f projects I happened to program worked well before the discovery of the LATx in the 18f's
Max.
I had the same plan: starting first with the lowest that would suit me (even got a 12F to learn the very basics but didn't send it with the kit -I'm still waiting for the extra chips to arrive-), and then, if need, move up; reason why I got all 16F for now. But since had to discard the tutorials I was going to use -as they are in asm-, and the ones I'm finding now are mainly for the 18F, I'm finding all these issues.

In any case, for now it doesn't really make much difference to me whether I use LATx or PORTx; I was just asking to know why my PICs didn't have this feature, and to see if there was anything else I should know when using PORTx instead of LATx.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Another problem I'm having is with the delay macros (e.g. "__delay_ms" and "__delay_us"); the compiler can't find where they are defined and I always get a warning message "Unable to resolve identifier...", even though the programs goes through and runs well.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Show your code.

Where is the macro defined? (It needs to be defined before first use.)

John
That's what I'm trying to find out!

Take this code as an example:

Rich (BB code):
void main(void) {
     __delay_ms(1000);
}
This will generate a warning because the "__delay_ms" macro has not been defined; but if you compile it, it will run without problems.

I've been trying to track down where the delay macros are defined in the XC8 include header files, and the closest I got is to this in the "pic.h" file:

Rich (BB code):
#ifdef __PICCPRO__
/****************************************************************/
/* Built-in delay routine                    */
/****************************************************************/
#pragma intrinsic(_delay)
extern __nonreentrant void _delay(unsigned long);
// NOTE: To use the macros below, YOU must have previously defined _XTAL_FREQ
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#endif
But as you can see, those will only be defined for something called "__PICCPRO__"; which I have no idea what it is.
 

jpanhalt

Joined Jan 18, 2008
11,087
Sorry, I based my comment on your post #150 and subsequent code snippets provided in Assembly. I assumed, incorrectly, that you had decided to use Assembly. I am clueless with C.

John
 

Thread Starter

adam555

Joined Aug 17, 2013
858
The XC8 seems to have peripheral libraries only for the PIC18 family -including its PDF manual- but I can't find either the libraries or manuals for the PIC16.

Anyone knows anything about this?

Thanks
 

Thread Starter

adam555

Joined Aug 17, 2013
858
I just realized there's no point looking for the PIC16 UART library, since my PIC16 don't even have this peripheral; they have USART/EUSART/AUSART or whatever instead.

I need some sort of serial monitor; as having the output to LEDs is a nightmare.

Anyone knows if I can use the PICkit2 UART tool with the PIC16 USART/EUSART/AUSART?
 

NorthGuy

Joined Jun 28, 2014
611
I just realized there's no point looking for the PIC16 UART library, since my PIC16 don't even have this peripheral; they have USART/EUSART/AUSART or whatever instead.

I need some sort of serial monitor; as having the output to LEDs is a nightmare.

Anyone knows if I can use the PICkit2 UART tool with the PIC16 USART/EUSART/AUSART?
You don't need a library for doing UART. Read the description of the module. There are only few registers to use to organize serial communications.

You will also need some sort of hardware to connect UART to COM port.

If you want to program through UART, you will need to find (write?) a bootloader.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
You don't need a library for doing UART. Read the description of the module. There are only few registers to use to organize serial communications.

You will also need some sort of hardware to connect UART to COM port.

If you want to program through UART, you will need to find (write?) a bootloader.
The problem is that none of the PICs have a UART module; they have either an EUSART or an AUSART/SCI, which I don't know if they are the same or equivalent.

At the moment I'm just trying to see some sort of output on my PC through the PICkit2; for which I guess the easiest way is simply to use the PICkit2 UART tool, which powers and connects the device to the PC.

Connecting a PIC directly to a COM port on the PC seems miles away from where I am at the moment. :)

The Pic 16f USART can be used in synchronous or non-syncronous mode.
I have used it non-synchronous.
http://www.winpicprog.co.uk/pic_tutorial7.htm
Max.
Yes. To add to what Max said, that is your UART. If you have the PIC tools loaded, the libs should be available, just use them.
I'll try to translate Nigel's tutorial examples to C. But I'm not clear what you mean by the "PIC tools loaded"; in XC8 I'm including the "xc.h" header, and I seem to have access to other standard libraries like "stdio.h", "time.h", etc... but not the specific peripheral libraries like "usart.h"; which are exclusively for the PIC18.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
So, include the "usart.h" file.
If I do that I need to specify the library object; which I can't find in the "lib" folder.

For example: if I add "OpenUART()" to the code, I don't get an "unable to resolve identifier" error -since it's defined in the header- but I get this error when compiling:

Rich (BB code):
make[2]: *** [dist/default/production/UART_com.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
:0: error: (499) undefined symbol:
        _OpenUART(dist/default/production\UART_com.production.obj) 
nbproject/Makefile-default.mk:116: recipe for target 'dist/default/production/UART_com.production.hex' failed
make[2]: Leaving directory 'C:/Documents and Settings/Administrator/My Documents/PIC/Projects/UART_com'
nbproject/Makefile-default.mk:75: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Documents and Settings/Administrator/My Documents/PIC/Projects/UART_com'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 1s)
Regarding how to include the peripheral libraries I think I found the proper way to do it (even though they clearly state that they are only for the PIC18 family).

Instead of including each peripheral library header, you include the "plib.h", and this includes all the peripheral headers.

But I still get the error described above.
 

Brownout

Joined Jan 10, 2012
2,390
Post your code. This is how I do it, and it works, but this is for PIC18xxxxxx

Rich (BB code):
OpenUSART (USART_TX_INT_OFF & 
  USART_RX_INT_ON &
  USART_ASYNCH_MODE & 
  USART_EIGHT_BIT & 
  USART_CONT_RX & 
  USART_BRGH_HIGH, 34); //57,600 baud (56k)
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Post your code. This is how I do it, and it works, but this is for PIC18xxxxxx

Rich (BB code):
OpenUSART (USART_TX_INT_OFF & 
  USART_RX_INT_ON &
  USART_ASYNCH_MODE & 
  USART_EIGHT_BIT & 
  USART_CONT_RX & 
  USART_BRGH_HIGH, 34); //57,600 baud (56k)
I get an error if I use your function "OpenUSART"; that function is not included in any header file. The closest function available I found is "OpenUART()", which has no return and no arguments; but then, it won't compile without the lib object.

Remember that my PIC16Fs don't have an USART or an UART; one has an EUSART and the other an AUSART.
 
Top