PIC drivers and infrastructure

All the drivers on this site use a small set of common modules. These modules typedef basic types, implement delays and allow common access to I/O pins. Since most people already have some form of infrastructure, below are the prototypes of the the common modules used by the drivers. You can either copy and paste this to your project and implement time delay routes, or replace the instances of the below in the drivers with your equivalents.

Basic type definitions


typedef char int_8;
typedef int int_16;
typedef unsigned char uint_8;
typedef unsigned int uint_16;
typedef unsigned long uint_32;
 
// boolean type
#define FALSE (0)
#define TRUE (1)
typedef uint_8 BOOL;
#define NULL (0)

Delay routines


// delay one microsecond
#define time_delayOneUs()
 
// delay several uS
#define time_delayUs(x)
 
// delay one mS
extern void time_delayMs(int_16 ms)

Bit manipulation routines


// set / clear bits
#define sys_bitSet(bit) (bit = 1)
#define sys_bitClear(bit) (bit = 0)
 
// clear a bit and wait for it to set
#define sys_bitClearWaitSet(bit) {sys_bitClear(bit); while(!bit);}
#define sys_bitSetWaitClear(bit) {sys_bitSet(bit); while(bit);}
 
// pulse a bit
#define sys_bitSetNoWaitClear(bit) {sys_bitSet(bit); sys_bitClear(bit);}
#define sys_bitSetWaitUsClear(bit, delay) {sys_bitSet(bit); time_delayUs(delay); sys_bitClear(bit);}
#define sys_bitSetWaitMsClear(bit, delay) {sys_bitSet(bit); time_delayMs(delay); sys_bitClear(bit);}
#define sys_bitClearNoWaitSet(bit) {sys_bitClear(bit); sys_bitSet(bit);}
#define sys_bitClearWaitUsSet(bit, delay) {sys_bitClear(bit); time_delayUs(delay); sys_bitSet(bit);}
#define sys_bitClearWaitMsSet(bit, delay) {sys_bitClear(bit); time_delayMs(delay); sys_bitSet(bit);}
 
// masking routines
#define sys_getIntMsb(myInt) ((myInt >> 8) & 0xFF)
#define sys_getIntLsb(myInt) ((myInt) & 0xFF)

Miscellaneous drivers



These drivers are best used as reference.

  • I²C: Tested on a myriad of PIC16s and PIC18s. Master mode only
  • HD44780 LCD: Tested on a 2×16 LCD with a 4 bit interface
  • Nokia 7710 Dot Matrix LCD: In its current form, supports plotting the Nokia 7710 LCD with page aligned and unaligned info. Non buffered – no ~900 byte back buffer required, at the expense of not being able to write two unaligned glyphs to a single page
  • 5×7 font: A C array for 5×7 font including numbers, letters (lower case and upper case) and some symbols
  • Microchip serial EEPROMs: Support for writes that span over multiple page

Leave a comment


Name*

Email(will not be published)*

Website

Your comment*

Submit Comment

© Copyright pavius.net: no refunds - Designed by Pexeto