Products > Programming

PIC ports and C

<< < (3/4) > >>


Using GPIObits.GP2 and TRISIO2 worked a treat.

I still can see how you can tell this from any data provided. I looked in the XC8 included file for the 12F683 and all it had (apart from disclaimer bumph) was:

; Code-generator required, PIC12F683 Definitions
; SFR Addresses
fsr equ 04h
fsr0 equ 04h
indf equ 00h
indf0 equ 00h
pc equ 02h
pcl equ 02h
pclath equ 0Ah
status equ 03h

... nothing about GPIO, etc. and nothing was there within MPLAB X in the source files or other directories.

Nothing in #define s ? :-//

I did go to put MPLAB X IDE v5.25 on this PC but when I say saw it was a 900 MB DL I didn't bother. :)

you looked in the wrong file.  try pic12f683.h


--- Quote ---That's a royal PITA because of the port bit definitions.  Instead, its better to #define pins named by function and localize the brain damage by avoiding all use of PORTA vs GPIO and TRISA vs TRISIO except in your hardware.h
--- End quote ---
Yeah, Ian. I do that, too. But sometimes ports and registers are important to the software for byte instructions/manipulations to save instruction cycles and/or where state changes must happen at the same time,  rather than serially.

You can do those things through this additional layer, as well, but then you need more defines (and more cumbersome code, which is the cost for pin flexibility).

PORTA vs GPIO at least keeps things the same across devices.

--- Quote --- #define HB_LED         LATBbits.LATB6            // Used for heartbeat
 #define ADC1         LATDbits.LATD5
--- End quote ---
In order to do more involved/minute/direct stuffs, you might end up needing more defines ala:
#define HB_LED.port  PORTA
#define HB_LED.tris   TRISA
#define    LATA
#define   4
#define HB_LED        PORTA,4
Even in your defines, you don't have to write/think GPIO/TRISIO, anymore, once you have defined it to PORTA/TRISA.

Cheers StillTrying - I don't blame you: it's a big, messy install. Not sure where "#define s" is to be found.

Thank you Ian.M I just looked at the first file with 12F683 in it.  :-[
From info in the file you suggested (though I don't understand it all) I used GP2 instead of GPIObits.GP2 and that worked too! Brill.


[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Go to full version