If you tend to use the same family of PICs, and the same hardware configurations (eg port B for an LCD display, or port A for input switches etc) then you can simply make one file with all the hardware definitions in, and then include that using one line in your main code.
For example, I tend to use an 18F2620 or 18F4620 in most of my projects, and use the same LCD and pins for input switches so I have
An then save that as "hardware18F4620" and then in the main program use theCode:'******************************************************************************* ' 18F4620 config settings - for use with MPSAM '******************************************************************************* ASM __CONFIG _CONFIG1H, _OSC_HS_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM '******************************************************************************* ' LCD (20 x 4) set up '******************************************************************************* DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 4 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us '******************************************************************************* ' Defines Statements '******************************************************************************* DEFINE OSC 20 ' 18F4520, 20mhz crystal ADCON1 = $0F clear '******************************************************************************* 'Analog and Comparator settings '******************************************************************************* ADCON0 = %00000000 'AD converter module disabled ADCON1 = %00001111 'All Digital ADCON2 = %00000000 CMCON = 7 'Disable Comparators '******************************************************************************* 'Port and Register settings (interrupts) '******************************************************************************* TRISA = %00010111 TRISB = %00000011 TRISD = %00000011 T0CON = %11000111 ;----[UART Settings]------------------------------------------------------------ DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE HSER_SPBRG 8 ' 9600 Baud @ SPBRGH = 2 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 SPBRG = 8 ' 9600 Baud @ -0.03% SPBRGH = 2 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator RCIF VAR PIR1.5 ' USART receive flag Char VAR BYTE ' USART byte received GIE VAR INTCON.7 nTest var byte '******************************************************************************* ' Pins used for connections to outside world '******************************************************************************* DecButton var PORTA.0 'Press to Decrement Button SetButton var PORTA.1 'Press to Set/memorise Button IncButton var PORTA.2 'Press to Increment Button OnButton var PORTA.0 'Press to Decrement Button OffButton var PORTA.2 'Press to Increment Button H_butt VAR PORTA.2 'hour increase M_butt VAR PORTA.0 'minutes increase S_butt VAR PORTA.1 'set / memorise SCLpin var PORTC.3 'RTC pin - clk SDApin var PORTC.4 'RTC pin - data led var PORTD.4
Saves having to write out or copy and paste lots of codeCode:INCLUDE "hardware18F4620.pbp"




Bookmarks