16F886 Config & Defines


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1

    Default 16F886 Config & Defines

    Having got a 16F88 project to work thanks to all the members on here i'm back on another project.

    The most confusing aspect of the whole thing is getting the chip config settings and defines correct
    to start with.
    The actual program is usually a doodle in comparison. I've tried to digest the 16F886 datasheet and have cribed quite a lot of code from other threads. But there aren't many exmples specifically for the 16F886. the learning curve for the config is so steep you could become totally frustrated if it was not for forums such as this

    I want the chip to run at 8mhz using the internal oscillator, and I would like to use the crystal pins at a
    later stage.

    I want 10bit analogue inputs on AN0 to AN3

    No comparators.

    portA 0,1,2,3 analog inputs. Rest as outputs
    portB all outputs
    portC all inputs

    I use the PM assembler.

    Can anyone show me an example or two of the config/defines for a similar setup.

    I've come up with the following so far.

    Code:
    @ DEVICE PIC16F886,LVP_OFF
    @ DEVICE PIC16F886,FCMEN_OFF
    @ DEVICE PIC16F886,IESO_OFF
    @ DEVICE PIC16F886,BOR_OFF
    @ DEVICE PIC16F886,CPD_OFF
    @ DEVICE PIC16F886,CP_OFF
    @ DEVICE PIC16F886,MCLRE_OFF
    @ DEVICE PIC16F886,PWRTE_ON
    @ DEVICE PIC16F886,WDT_OFF
    @ DEVICE PIC16F886,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F886,WRT_OFF
    @ DEVICE PIC16F886,MCLR_OFF
    @ DEVICE PIC16F886,BOD_OFF
    @ DEVICE PIC16F886,PROTECT_OFF
    
    
    	Define OSC 8			'Set PicBasic Pro processor speed to 8 Mhz (Must match oscillator value)  
    	OSCCON = %01110001 		'Internal 8 mhz Osc
    
    	CM1CON0 = 0 			'Comparator Off
    	CM2CON0 = 0 			'Comparator Off
    
    
    'Define ADCIN parameters
    
    	Define ADC_BITS 10 		'Set number of bits in result (10)
    	Define ADC_CLOCK 3 		'Set clock source (3=rc)
    	Define ADC_SAMPLEUS 50 	'Set sampling time in microseconds (50us)
    
    	include "modedefs.bas"	'Allows the use of the serin/serout command
    I realise there is still a lot missing from this.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    My second effort.

    Code:
    @ DEVICE PIC16F886,LVP_OFF
    @ DEVICE PIC16F886,FCMEN_OFF
    @ DEVICE PIC16F886,IESO_OFF
    @ DEVICE PIC16F886,BOR_OFF
    @ DEVICE PIC16F886,CPD_OFF
    @ DEVICE PIC16F886,CP_OFF
    @ DEVICE PIC16F886,MCLRE_OFF
    @ DEVICE PIC16F886,PWRTE_ON
    @ DEVICE PIC16F886,WDT_OFF
    @ DEVICE PIC16F886,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F886,WRT_OFF
    @ DEVICE PIC16F886,MCLR_OFF
    @ DEVICE PIC16F886,BOD_OFF
    @ DEVICE PIC16F886,PROTECT_OFF
    
    
    	Define OSC 8			'Set PicBasic Pro processor speed to 8 Mhz (Must match oscillator value)  
    	OSCCON = %01110001 		'Internal 8 mhz Osc
    
    	CM1CON0 = 0 			'Comparator Off
    	CM2CON0 = 0 			'Comparator Off
    	
    	TRISA = %11111111 		'SET PORTA AS INPUTS
    	TRISB = %00000000 		'SET PORTB AS OUTPUTS
    	TRISC = %11111111 		'SET PORTC AS INPUTS
    	
    	ANSEL = %00001111		'SET INPUTS AN0-AN3 AS ANALOG INPUTS
    	
    	ADCON0 = %01000001		'SETUP ADC CONVERTER MODULE FOSC/8 & ENABLE ADC MODULE
    	ADCON1 = %10000000		'SETUP ADC RIGHT JUSTIFY SET REFV to VDD & VSS 
    
    
    'Define ADCIN parameters
    
    	Define ADC_BITS 10 		'Set number of bits in result (10)
    	Define ADC_CLOCK 3 		'Set clock source (3=rc)
    	Define ADC_SAMPLEUS 50 		'Set sampling time in microseconds (50us)
    
    	include "modedefs.bas"		'Allows the use of the serin/serout command

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not use PM, so this is how I set it up using MPASM.

    Code:
    @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    
       OSCCON = %01110000
       DEFINE OSC 8
       CM1CON0 = 0 			'Comparator Off
       CM2CON0 = 0 			'Comparator Off
    	
       TRISA = %11111111 		'SET PORTA AS INPUTS
       TRISB = %00000000 		'SET PORTB AS OUTPUTS
       TRISC = %11111111 		'SET PORTC AS INPUTS
       ANSEL = %00001111		'SET INPUTS AN0-AN3 AS ANALOG INPUTS
       ADCON1 = %10000000		'SETUP ADC RIGHT JUSTIFY SET REFV to VDD & VSS 
    
    'Define ADCIN parameters
    	Define ADC_BITS 10 		'Set number of bits in result (10)
    	Define ADC_CLOCK 3 		'Set clock source (3=rc)
    	Define ADC_SAMPLEUS 50 		'Set sampling time in microseconds (50us)
    Not much different than yours...
    Dave
    Always wear safety glasses while programming.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Code:
    @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    Not much different than yours...
    Can you explain __config _CONFIG1 ?

    I understand the other statements on that line.

    Thanks peter

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    _CONFIG1 is for configuration word 1. If you take a look in your C:\Program Files\Microchip\MPASM Suite and look at the .inc file for the chip you are using, at the bottom of the inc file, you will see:

    Code:
    ;==========================================================================
    ;
    ;       Configuration Bits
    ;
    ;==========================================================================
    _CONFIG1                     EQU     H'2007'
    _CONFIG2                     EQU     H'2008'
    
    ;----- Configuration Word1 ------------------------------------------------
    
    _DEBUG_ON                    EQU     H'1FFF'
    _DEBUG_OFF                   EQU     H'3FFF'
    _LVP_ON                 EQU     H'3FFF'
    _LVP_OFF             EQU     H'2FFF'
    _FCMEN_ON                    EQU     H'3FFF'
    _FCMEN_OFF                   EQU     H'37FF'
    _IESO_ON                     EQU     H'3FFF'
    _IESO_OFF                    EQU     H'3BFF'
    _BOR_ON                      EQU     H'3FFF'
    _BOR_NSLEEP                  EQU     H'3EFF'
    _BOR_SBODEN                  EQU     H'3DFF'
    _BOR_OFF                     EQU     H'3CFF'
    _CPD_ON                      EQU     H'3F7F'
    _CPD_OFF                     EQU     H'3FFF'
    _CP_ON                       EQU     H'3FBF'
    _CP_OFF                      EQU     H'3FFF'
    _MCLRE_ON                    EQU     H'3FFF'
    _MCLRE_OFF                   EQU     H'3FDF'
    _PWRTE_ON                    EQU     H'3FEF'
    _PWRTE_OFF                   EQU     H'3FFF'
    _WDT_ON                      EQU     H'3FFF'
    _WDT_OFF                     EQU     H'3FF7'
    _LP_OSC                      EQU     H'3FF8'
    _XT_OSC                      EQU     H'3FF9'
    _HS_OSC                      EQU     H'3FFA'
    _EC_OSC                      EQU     H'3FFB'
    _INTRC_OSC_NOCLKOUT          EQU     H'3FFC'
    _INTRC_OSC_CLKOUT            EQU     H'3FFD'
    _EXTRC_OSC_NOCLKOUT          EQU     H'3FFE'
    _EXTRC_OSC_CLKOUT            EQU     H'3FFF'
    _INTOSCIO                    EQU     H'3FFC'
    _INTOSC                      EQU     H'3FFD'
    _EXTRCIO                     EQU     H'3FFE'
    _EXTRC                       EQU     H'3FFF'
    
    ;----- Configuration Word2 ------------------------------------------------
    
    _WRT_OFF                     EQU     H'3FFF'    ; No prog memmory write protection
    _WRT_256                     EQU     H'3DFF'    ; First 256 prog memmory write protected
    _WRT_1FOURTH                 EQU     H'3BFF'    ; First quarter prog memmory write protected
    _WRT_HALF                    EQU     H'39FF'    ; First half memmory write protected
    
    _BOR21V                      EQU     H'3EFF'
    _BOR40V                      EQU     H'3FFF'
    A couple of the configs are in configuration word 2. This gives Mpasm what it needs to know. If you were setting WRT_OFF, you would have to put it in another config line, like:

    Code:
    
    @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    @ __config _CONFIG2, _WRT_OFF
    Here is some slightly condensed config info:
    http://www.picbasic.co.uk/forum/cont...o-your-Program

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts