:: Home :: Code Snippets :: Drivers :: Projects :: About ::
 Main Menu
  Home
  Code Snippets
  About

 Open Drivers
 EA-DOGM - LCD Display Driver
 PIC32 mcompat - PIC32 mcompat
 qTask - Queued Task Manager
 _build - Embedded build information

 Open Projects
 fplCore - Self contained controller
 uProfiler - uController uProfiller
 oLogic - Oscilloscope Logic Viewer
 oLogic 1.4 - NEW Logic Viewer
 SSX32 - Serial Servo Driver



 Sources
Prototyping
  PicStuff
  Sparkfun

Equipment
  Saelig
  Tequipment

Supply House
  Jameco
  Mouser
  Digikey
  Allied Electronics
  Clearwater Technologies

Miscellaneous
  BCM
  N34D Blog

PIC32 Macro compatability defines

This is a work in progress for me. I have become spoiled by CCS C compiler, and I always have trouble jumping from one C compiler to another, even from Visual C to Linux GCC.

So, I decided to see if I can make a set of macros, and defines that will allow me to use C32 (microchip mplab) similar to CCS C, as well as minimize any porting issues of projects.

So this is what I have so far....
 Driver Specs
version: 0.012
mcu: PIC32
compiler: C32

 Files
mcompat.h
ex1.c

mcompat.zip - All files


A simple view of how to use it
 Example Usage
#include <p32xxxx.h>
#include <plib.h>

#include "mcompat.h"	// compatability file

// define pins like we would in CCS C
#define PWR_LED 	PIN_C3
#define IN_RDY 		PIN_C2

main()
{
	mOutput_drive(PIN_CX);
	mOutput_drive(PWR_LED);
	mOutput_high(PWR_LED);
	mOutput_low(PWR_LED);

	a = mInput(IN_RDY);
}



And here is the complete driver source file.
 mcompat.h
/*
	macro compatability defines
	(C) Copyright 2009, Michael Bradley mbradley@mculabs.com

	version: 0.012
	This is a work in progress, so this will change!
*/

#ifndef _MCOMPATABILITY
	#define _MCOMPATABILITY 1

// ***** Pin asignments *****
//#ifdef IOPORT_A
	#define PIN_A0 IOPORT_A, BIT_0
	#define PIN_A1 IOPORT_A, BIT_1
	#define PIN_A2 IOPORT_A, BIT_2
	#define PIN_A3 IOPORT_A, BIT_3
	#define PIN_A4 IOPORT_A, BIT_4
	#define PIN_A5 IOPORT_A, BIT_5
	#define PIN_A6 IOPORT_A, BIT_6
	#define PIN_A7 IOPORT_A, BIT_7
	#define PIN_A8 IOPORT_A, BIT_8
	#define PIN_A9 IOPORT_A, BIT_9
	#define PIN_A10 IOPORT_A, BIT_10
	#define PIN_A11 IOPORT_A, BIT_11
	#define PIN_A12 IOPORT_A, BIT_12
	#define PIN_A13 IOPORT_A, BIT_13
	#define PIN_A14 IOPORT_A, BIT_14
	#define PIN_A15 IOPORT_A, BIT_15
	#define PIN_AX IOPORT_A, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif

//#ifdef IOPORT_B
	#define PIN_B0 IOPORT_B, BIT_0
	#define PIN_B1 IOPORT_B, BIT_1
	#define PIN_B2 IOPORT_B, BIT_2
	#define PIN_B3 IOPORT_B, BIT_3
	#define PIN_B4 IOPORT_B, BIT_4
	#define PIN_B5 IOPORT_B, BIT_5
	#define PIN_B6 IOPORT_B, BIT_6
	#define PIN_B7 IOPORT_B, BIT_7
	#define PIN_B8 IOPORT_B, BIT_8
	#define PIN_B9 IOPORT_B, BIT_9
	#define PIN_B10 IOPORT_B, BIT_10
	#define PIN_B11 IOPORT_B, BIT_11
	#define PIN_B12 IOPORT_B, BIT_12
	#define PIN_B13 IOPORT_B, BIT_13
	#define PIN_B14 IOPORT_B, BIT_14
	#define PIN_B15 IOPORT_B, BIT_15
	#define PIN_BX IOPORT_B, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif

//#ifdef IOPORT_C
	#define PIN_C0 IOPORT_C, BIT_0
	#define PIN_C1 IOPORT_C, BIT_1
	#define PIN_C2 IOPORT_C, BIT_2
	#define PIN_C3 IOPORT_C, BIT_3
	#define PIN_C4 IOPORT_C, BIT_4
	#define PIN_C5 IOPORT_C, BIT_5
	#define PIN_C6 IOPORT_C, BIT_6
	#define PIN_C7 IOPORT_C, BIT_7
	#define PIN_C8 IOPORT_C, BIT_8
	#define PIN_C9 IOPORT_C, BIT_9
	#define PIN_C10 IOPORT_C, BIT_10
	#define PIN_C11 IOPORT_C, BIT_11
	#define PIN_C12 IOPORT_C, BIT_12
	#define PIN_C13 IOPORT_C, BIT_13
	#define PIN_C14 IOPORT_C, BIT_14
	#define PIN_C15 IOPORT_C, BIT_15
	#define PIN_CX IOPORT_C, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif

//#ifdef IOPORT_D
	#define PIN_D0 IOPORT_D, BIT_0
	#define PIN_D1 IOPORT_D, BIT_1
	#define PIN_D2 IOPORT_D, BIT_2
	#define PIN_D3 IOPORT_D, BIT_3
	#define PIN_D4 IOPORT_D, BIT_4
	#define PIN_D5 IOPORT_D, BIT_5
	#define PIN_D6 IOPORT_D, BIT_6
	#define PIN_D7 IOPORT_D, BIT_7
	#define PIN_D8 IOPORT_D, BIT_8
	#define PIN_D9 IOPORT_D, BIT_9
	#define PIN_D10 IOPORT_D, BIT_10
	#define PIN_D11 IOPORT_D, BIT_11
	#define PIN_D12 IOPORT_D, BIT_12
	#define PIN_D13 IOPORT_D, BIT_13
	#define PIN_D14 IOPORT_D, BIT_14
	#define PIN_D15 IOPORT_D, BIT_15
	#define PIN_DX IOPORT_D, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif


//#ifdef IOPORT_E
	#define PIN_E0 IOPORT_E, BIT_0
	#define PIN_E1 IOPORT_E, BIT_1
	#define PIN_E2 IOPORT_E, BIT_2
	#define PIN_E3 IOPORT_E, BIT_3
	#define PIN_E4 IOPORT_E, BIT_4
	#define PIN_E5 IOPORT_E, BIT_5
	#define PIN_E6 IOPORT_E, BIT_6
	#define PIN_E7 IOPORT_E, BIT_7
	#define PIN_E8 IOPORT_E, BIT_8
	#define PIN_E9 IOPORT_E, BIT_9
	#define PIN_E10 IOPORT_E, BIT_10
	#define PIN_E11 IOPORT_E, BIT_11
	#define PIN_E12 IOPORT_E, BIT_12
	#define PIN_E13 IOPORT_E, BIT_13
	#define PIN_E14 IOPORT_E, BIT_14
	#define PIN_E15 IOPORT_E, BIT_15
	#define PIN_EX IOPORT_E, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif

//#ifdef IOPORT_F
	#define PIN_F0 IOPORT_F, BIT_0
	#define PIN_F1 IOPORT_F, BIT_1
	#define PIN_F2 IOPORT_F, BIT_2
	#define PIN_F3 IOPORT_F, BIT_3
	#define PIN_F4 IOPORT_F, BIT_4
	#define PIN_F5 IOPORT_F, BIT_5
	#define PIN_F6 IOPORT_F, BIT_6
	#define PIN_F7 IOPORT_F, BIT_7
	#define PIN_F8 IOPORT_F, BIT_8
	#define PIN_F9 IOPORT_F, BIT_9
	#define PIN_F10 IOPORT_F, BIT_10
	#define PIN_F11 IOPORT_F, BIT_11
	#define PIN_F12 IOPORT_F, BIT_12
	#define PIN_F13 IOPORT_F, BIT_13
	#define PIN_F14 IOPORT_F, BIT_14
	#define PIN_F15 IOPORT_F, BIT_15
	#define PIN_FX IOPORT_F, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif

//#ifdef IOPORT_G
	#define PIN_G0 IOPORT_G, BIT_0
	#define PIN_G1 IOPORT_G, BIT_1
	#define PIN_G2 IOPORT_G, BIT_2
	#define PIN_G3 IOPORT_G, BIT_3
	#define PIN_G4 IOPORT_G, BIT_4
	#define PIN_G5 IOPORT_G, BIT_5
	#define PIN_G6 IOPORT_G, BIT_6
	#define PIN_G7 IOPORT_G, BIT_7
	#define PIN_G8 IOPORT_G, BIT_8
	#define PIN_G9 IOPORT_G, BIT_9
	#define PIN_G10 IOPORT_G, BIT_10
	#define PIN_G11 IOPORT_G, BIT_11
	#define PIN_G12 IOPORT_G, BIT_12
	#define PIN_G13 IOPORT_G, BIT_13
	#define PIN_G14 IOPORT_G, BIT_14
	#define PIN_G15 IOPORT_G, BIT_15
	#define PIN_GX IOPORT_G, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
//#endif


// ***** Macros to be similar to CCS C *****

#define mOutput_drive(mParam) PORTSetPinsDigitalOut(mParam)
#define mOutput_high(mParam) PORTSetBits(mParam)
#define mOutput_low(mParam) PORTClearBits(mParam)

#define mInput(mParam) PORTReadBits(mParam)


#endif







:: Home :: Resources :: PIC Microcontrollers ::
:: 10F :: 12F :: 16F :: 18F :: 24F :: 24H :: 30F :: 33F ::
(C) Copyright 2009 mculabs.com - contact: info@mculabs.com
0.0035009384155273