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

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

 Open Projects
 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
/vhost/mculabs/driver_db/mcompat/files/ex1.c
    1 #include <p32xxxx.h>
    2 #include <plib.h>
    3 
    4 #include "mcompat.h"	// compatability file
    5 
    6 // define pins like we would in CCS C
    7 #define PWR_LED 	PIN_C3
    8 #define IN_RDY 		PIN_C2
    9 
   10 main()
   11 {
   12 	mOutput_drive(PIN_CX);
   13 	mOutput_drive(PWR_LED);
   14 	mOutput_high(PWR_LED);
   15 	mOutput_low(PWR_LED);
   16 
   17 	a = mInput(IN_RDY);
   18 }
   19 
   20 

And here is the complete driver source file.
 mcompat.h
/vhost/mculabs/driver_db/mcompat/files/mcompat.h
    1 /*
    2 	macro compatability defines
    3 	(C) Copyright 2009, Michael Bradley mbradley@mculabs.com
    4 
    5 	version: 0.012
    6 	This is a work in progress, so this will change!
    7 */
    8 
    9 #ifndef _MCOMPATABILITY
   10 	#define _MCOMPATABILITY 1
   11 
   12 // ***** Pin asignments *****
   13 //#ifdef IOPORT_A
   14 	#define PIN_A0 IOPORT_A, BIT_0
   15 	#define PIN_A1 IOPORT_A, BIT_1
   16 	#define PIN_A2 IOPORT_A, BIT_2
   17 	#define PIN_A3 IOPORT_A, BIT_3
   18 	#define PIN_A4 IOPORT_A, BIT_4
   19 	#define PIN_A5 IOPORT_A, BIT_5
   20 	#define PIN_A6 IOPORT_A, BIT_6
   21 	#define PIN_A7 IOPORT_A, BIT_7
   22 	#define PIN_A8 IOPORT_A, BIT_8
   23 	#define PIN_A9 IOPORT_A, BIT_9
   24 	#define PIN_A10 IOPORT_A, BIT_10
   25 	#define PIN_A11 IOPORT_A, BIT_11
   26 	#define PIN_A12 IOPORT_A, BIT_12
   27 	#define PIN_A13 IOPORT_A, BIT_13
   28 	#define PIN_A14 IOPORT_A, BIT_14
   29 	#define PIN_A15 IOPORT_A, BIT_15
   30 	#define PIN_AX IOPORT_A, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
   31 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
   32 //#endif
   33 
   34 //#ifdef IOPORT_B
   35 	#define PIN_B0 IOPORT_B, BIT_0
   36 	#define PIN_B1 IOPORT_B, BIT_1
   37 	#define PIN_B2 IOPORT_B, BIT_2
   38 	#define PIN_B3 IOPORT_B, BIT_3
   39 	#define PIN_B4 IOPORT_B, BIT_4
   40 	#define PIN_B5 IOPORT_B, BIT_5
   41 	#define PIN_B6 IOPORT_B, BIT_6
   42 	#define PIN_B7 IOPORT_B, BIT_7
   43 	#define PIN_B8 IOPORT_B, BIT_8
   44 	#define PIN_B9 IOPORT_B, BIT_9
   45 	#define PIN_B10 IOPORT_B, BIT_10
   46 	#define PIN_B11 IOPORT_B, BIT_11
   47 	#define PIN_B12 IOPORT_B, BIT_12
   48 	#define PIN_B13 IOPORT_B, BIT_13
   49 	#define PIN_B14 IOPORT_B, BIT_14
   50 	#define PIN_B15 IOPORT_B, BIT_15
   51 	#define PIN_BX IOPORT_B, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
   52 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
   53 //#endif
   54 
   55 //#ifdef IOPORT_C
   56 	#define PIN_C0 IOPORT_C, BIT_0
   57 	#define PIN_C1 IOPORT_C, BIT_1
   58 	#define PIN_C2 IOPORT_C, BIT_2
   59 	#define PIN_C3 IOPORT_C, BIT_3
   60 	#define PIN_C4 IOPORT_C, BIT_4
   61 	#define PIN_C5 IOPORT_C, BIT_5
   62 	#define PIN_C6 IOPORT_C, BIT_6
   63 	#define PIN_C7 IOPORT_C, BIT_7
   64 	#define PIN_C8 IOPORT_C, BIT_8
   65 	#define PIN_C9 IOPORT_C, BIT_9
   66 	#define PIN_C10 IOPORT_C, BIT_10
   67 	#define PIN_C11 IOPORT_C, BIT_11
   68 	#define PIN_C12 IOPORT_C, BIT_12
   69 	#define PIN_C13 IOPORT_C, BIT_13
   70 	#define PIN_C14 IOPORT_C, BIT_14
   71 	#define PIN_C15 IOPORT_C, BIT_15
   72 	#define PIN_CX IOPORT_C, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
   73 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
   74 //#endif
   75 
   76 //#ifdef IOPORT_D
   77 	#define PIN_D0 IOPORT_D, BIT_0
   78 	#define PIN_D1 IOPORT_D, BIT_1
   79 	#define PIN_D2 IOPORT_D, BIT_2
   80 	#define PIN_D3 IOPORT_D, BIT_3
   81 	#define PIN_D4 IOPORT_D, BIT_4
   82 	#define PIN_D5 IOPORT_D, BIT_5
   83 	#define PIN_D6 IOPORT_D, BIT_6
   84 	#define PIN_D7 IOPORT_D, BIT_7
   85 	#define PIN_D8 IOPORT_D, BIT_8
   86 	#define PIN_D9 IOPORT_D, BIT_9
   87 	#define PIN_D10 IOPORT_D, BIT_10
   88 	#define PIN_D11 IOPORT_D, BIT_11
   89 	#define PIN_D12 IOPORT_D, BIT_12
   90 	#define PIN_D13 IOPORT_D, BIT_13
   91 	#define PIN_D14 IOPORT_D, BIT_14
   92 	#define PIN_D15 IOPORT_D, BIT_15
   93 	#define PIN_DX IOPORT_D, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
   94 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
   95 //#endif
   96 
   97 
   98 //#ifdef IOPORT_E
   99 	#define PIN_E0 IOPORT_E, BIT_0
  100 	#define PIN_E1 IOPORT_E, BIT_1
  101 	#define PIN_E2 IOPORT_E, BIT_2
  102 	#define PIN_E3 IOPORT_E, BIT_3
  103 	#define PIN_E4 IOPORT_E, BIT_4
  104 	#define PIN_E5 IOPORT_E, BIT_5
  105 	#define PIN_E6 IOPORT_E, BIT_6
  106 	#define PIN_E7 IOPORT_E, BIT_7
  107 	#define PIN_E8 IOPORT_E, BIT_8
  108 	#define PIN_E9 IOPORT_E, BIT_9
  109 	#define PIN_E10 IOPORT_E, BIT_10
  110 	#define PIN_E11 IOPORT_E, BIT_11
  111 	#define PIN_E12 IOPORT_E, BIT_12
  112 	#define PIN_E13 IOPORT_E, BIT_13
  113 	#define PIN_E14 IOPORT_E, BIT_14
  114 	#define PIN_E15 IOPORT_E, BIT_15
  115 	#define PIN_EX IOPORT_E, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
  116 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
  117 //#endif
  118 
  119 //#ifdef IOPORT_F
  120 	#define PIN_F0 IOPORT_F, BIT_0
  121 	#define PIN_F1 IOPORT_F, BIT_1
  122 	#define PIN_F2 IOPORT_F, BIT_2
  123 	#define PIN_F3 IOPORT_F, BIT_3
  124 	#define PIN_F4 IOPORT_F, BIT_4
  125 	#define PIN_F5 IOPORT_F, BIT_5
  126 	#define PIN_F6 IOPORT_F, BIT_6
  127 	#define PIN_F7 IOPORT_F, BIT_7
  128 	#define PIN_F8 IOPORT_F, BIT_8
  129 	#define PIN_F9 IOPORT_F, BIT_9
  130 	#define PIN_F10 IOPORT_F, BIT_10
  131 	#define PIN_F11 IOPORT_F, BIT_11
  132 	#define PIN_F12 IOPORT_F, BIT_12
  133 	#define PIN_F13 IOPORT_F, BIT_13
  134 	#define PIN_F14 IOPORT_F, BIT_14
  135 	#define PIN_F15 IOPORT_F, BIT_15
  136 	#define PIN_FX IOPORT_F, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
  137 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
  138 //#endif
  139 
  140 //#ifdef IOPORT_G
  141 	#define PIN_G0 IOPORT_G, BIT_0
  142 	#define PIN_G1 IOPORT_G, BIT_1
  143 	#define PIN_G2 IOPORT_G, BIT_2
  144 	#define PIN_G3 IOPORT_G, BIT_3
  145 	#define PIN_G4 IOPORT_G, BIT_4
  146 	#define PIN_G5 IOPORT_G, BIT_5
  147 	#define PIN_G6 IOPORT_G, BIT_6
  148 	#define PIN_G7 IOPORT_G, BIT_7
  149 	#define PIN_G8 IOPORT_G, BIT_8
  150 	#define PIN_G9 IOPORT_G, BIT_9
  151 	#define PIN_G10 IOPORT_G, BIT_10
  152 	#define PIN_G11 IOPORT_G, BIT_11
  153 	#define PIN_G12 IOPORT_G, BIT_12
  154 	#define PIN_G13 IOPORT_G, BIT_13
  155 	#define PIN_G14 IOPORT_G, BIT_14
  156 	#define PIN_G15 IOPORT_G, BIT_15
  157 	#define PIN_GX IOPORT_G, (BIT_15|BIT_14|BIT_13|BIT_12|BIT_11|BIT_10|BIT_9|BIT_8|
  158 	                          BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0)
  159 //#endif
  160 
  161 
  162 // ***** Macros to be similar to CCS C *****
  163 
  164 #define mOutput_drive(mParam) PORTSetPinsDigitalOut(mParam)
  165 #define mOutput_high(mParam) PORTSetBits(mParam)
  166 #define mOutput_low(mParam) PORTClearBits(mParam)
  167 
  168 #define mInput(mParam) PORTReadBits(mParam)
  169 
  170 
  171 #endif
  172 






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