Skip to content

Instantly share code, notes, and snippets.

@cv007
Last active January 14, 2018 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cv007/853d29f6972dd3758f982bb8b1809f38 to your computer and use it in GitHub Desktop.
Save cv007/853d29f6972dd3758f982bb8b1809f38 to your computer and use it in GitHub Desktop.
/*------------------------------------------------------------------------------
___ ___ ___ ___ _ _ ___ ___
| \ | __|| __||_ _|| \| || __|/ __|
| |) || _| | _| | | | .` || _| \__ \
|___/ |___||_| |___||_|\_||___||___/
------------------------------------------------------------------------------*/
//my pin macros
#define _PIN_SET(pt,pn,v) LAT##pt##pn = v
#define _PIN_TOGGLE(pt,pn) LAT##pt##pn = ~LAT##pt##pn
#define _PIN_VALUE(pt,pn) R##pt##pn
#define _PIN_IO(pt,pn,v) TRIS##pt##pn = v
#define _PIN_PU(pt,pn,v) WPU##pt##pn = v
#define _PIN_DRIVE(pt,pn,v) HID##pt##pn = v
#define _PIN_DRAIN(pt,pn,v) OD##pt##pn = v
//instead of using ANS##pt##pn = m; , use byte method on ANSELx register
//as not all pins analog - this will result in set/clear of a ANSELx bit
//(if bit not implemented, no harm done and will keep PIN_INIT always happy)
#define _PIN_MODE(pt,pn,v) do{ if( v ) ANSEL##pt |= 1<<pn; \
else ANSEL##pt &= ~(1<<pn); } while(0)
#define _PIN_INIT(pt,pn,m,io,pu,v) _PIN_SET(pt,pn,v); _PIN_PU(pt,pn,pu); \
_PIN_MODE(pt,pn,m); _PIN_IO(pt,pn,io)
#define _PPS_OUT(pt,pn,v) R##pt##pn##PPS = v
#define _PPSA 0
#define _PPSB 1
#define _PPSC 2
#define _PPS_IN(r,pt,pn) r = _PPS##pt << 3 | pn
#define _PIN_LETTER(pt,pn) pt
#define _PIN_NUMBER(pt,pn) pn
//need to expand pp
#define PIN_SET(pp,v) _PIN_SET(pp,v)
#define PIN_TOGGLE(pp) _PIN_TOGGLE(pp)
#define PIN_VALUE(pp) _PIN_VALUE(pp)
#define IO_IN 1
#define IO_OUT 0
#define PIN_IO(pp,v) _PIN_IO(pp,v)
#define PU_ON 1
#define PU_OFF 0
#define PIN_PU(pp,v) _PIN_PU(pp,v)
#define DRIVE_HIGH 1
#define DRIVE_NORMAL 0
#define PIN_DRIVE(pp,v) _PIN_DRIVE(pp,v)
#define DRAIN_OPEN 1
#define DRAIN_NORMAL 0
#define PIN_DRAIN(pp,v) _PIN_DRAIN(pp,v)
#define MODE_ANA 1
#define MODE_DIG 0
#define PIN_MODE(pp,v) _PIN_MODE(pp,v)
#define PIN_INIT(pp,m,io,pu,v) _PIN_INIT(pp,m,io,pu,v)
#define PPS_OUT(pp,v) _PPS_OUT(pp,v)
#define PPS_IN(r,pp) _PPS_IN(r,pp)
#define PIN_LETTER(pp) _PIN_LETTER(pp)
#define PIN_NUMBER(pp) _PIN_NUMBER(pp)
//pps output values
#define PPS_LATxy 0
#define PPS_CCP1_OUT 9
//rx pin
#define RX_PIN B,5
#define LED_A B,2
#define LED_B B,4
//rx pin
PIN_INIT( RX_PIN, MODE_DIG, IO_IN, PU_ON, 1 );
PPS_IN( RX1DTPPS, RX_PIN );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment