include/pic24_util.h File Reference

Go to the source code of this file.

Defines

#define NUM_UART_MODS   1
#define REPORT_ERROR(msg)   reportError(ERROR_FILE_LINE(msg))
#define USE_HEARTBEAT   1
#define HB_LED   _LATB15
#define CONFIG_HB_LED()   CONFIG_RB15_AS_DIG_OD_OUTPUT()
Bitfield to struct conversion
Given a bitfield struct representing an SFR, convert this to a word (uint16) or to the high and low bytes (uint8) of that word. Note: though this looks ugly, it introduces no unexpected compiler overhead at -O1. See u16_INTTREGlast for an example.

#define BITS2WORD(sfrBitfield)   ( *((uint16*) &sfrBitfield) )
#define BITS2BYTEL(sfrBitfield)   ( ((uint8*) &sfrBitfield)[0] )
#define BITS2BYTEH(sfrBitfield)   ( ((uint8*) &sfrBitfield)[1] )

Functions

void reportError (const char *szErrorMessage)
void printResetCause (void)
void configPinsForLowPower (void)
void configBasic (const char *psz_helloMsg)


Detailed Description

This file contains miscellaneous functions that that do not fall under any particular category.

See also pic24_util.c for details on how these functions were implemented.

Definition in file pic24_util.h.


Define Documentation

 
#define CONFIG_HB_LED (  )     CONFIG_RB15_AS_DIG_OD_OUTPUT()

Define a config function for the heartbeat pin.

Definition at line 735 of file pic24_util.h.

#define HB_LED   _LATB15

Choose a pin for the heartbeat. If USE_HEARTBEAT is false, the heartbeat is disabled.

Definition at line 733 of file pic24_util.h.

#define NUM_UART_MODS   1

Defined the number of UART modules supported by this chip. NOTE: this only works when testing #defines, not testing variable. So, don't test UxSTA; instead, test _UxRXIF which is uniquely defined for each UART. (Idea taken from the C30 peripheral library, in uart.h.)

Definition at line 646 of file pic24_util.h.

#define REPORT_ERROR ( msg   )     reportError(ERROR_FILE_LINE(msg))

Report an error on reset via reportError, also printing the file and line number where this macro was called via a call to ERROR_FILE_LINE.

Parameters:
msg Error message to report

Definition at line 697 of file pic24_util.h.

#define USE_HEARTBEAT   1

If this macro is true, heartbeat functionality is enabled. If false, heartbeat is disabled.

Definition at line 726 of file pic24_util.h.


Function Documentation

void configBasic ( const char *  sz_helloMsg  ) 

Perform basic chip configuration:

  • Configure the heartbeat
  • Configure the clock
  • Configure UART1
  • Determine and print the cause of reset
  • Print a hello message.

Parameters:
sz_helloMsg Hello message to print.

Definition at line 454 of file pic24_util.c.

void configPinsForLowPower ( void   ) 

This function puts the PIC24 in low-power mode by:

  • Configuring all digital I/O pins as inputs
  • Configuring all analog I/O pins shared with digital I/O pins to be digital only
  • Enables pullups on all pins not used by the oscillator.

WARNING: if pullups are enabled on pins used by the oscillator, the clock typically stops running. Currently, this code works for demo purposes with the FRC oscillator when used in the reset.c program. It *should* also work with primary and secondary oscillators, using conditional compiles in the code.

Definition at line 440 of file pic24_util.c.

void printResetCause ( void   ) 

Determines and prints the cause of a CPU reset. This should be called when the chip first starts up. For an example, see the configBasic function.

Definition at line 275 of file pic24_util.c.

void reportError ( const char *  sz_errorMessage  ) 

Report a critical error by recording a message in sz_lastError then resetting the chip, assuming hat printResetCause will be called during chip initialization.

Parameters:
sz_errorMessage Error message to report.
See also:
REPORT_ERROR

Definition at line 141 of file pic24_util.c.


Generated on Sun Mar 15 11:14:22 2009 for PIC24 Support Libraries by  doxygen 1.5.8