Author Topic: Question on use of _CONFIG directive in asm coding  (Read 3113 times)

0 Members and 1 Guest are viewing this topic.

Offline EENG

  • Contributor
  • Posts: 21
Question on use of _CONFIG directive in asm coding
« on: January 22, 2012, 05:53:50 am »
Hallo

I am busy getting familiar with the whole asm code structure for programming the pic PIC 12F675 in my PIC KIT 1 demo board. I am a first time programmer. At the very top of the asm file it starts like this (question will follow):

;********************************************
list      p=12F675   ; list directive to define processor
#include <p12f675.inc>   ; processor specific variable definitions

__CONFIG  _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

;**********************************

I then went and opened the p12f675.inc file to try to understand what the _COINFIG values were and I got the following (my question will follow below):


;====================================================================
;
;       Configuration Bits
;
;====================================================================

_CPD_ON                      EQU     H'3EFF'
_CPD_OFF                     EQU     H'3FFF'
_CP_ON                       EQU     H'3F7F'
_CP_OFF                      EQU     H'3FFF'
_BODEN_ON                    EQU     H'3FFF'
_BODEN_OFF                   EQU     H'3FBF'
_MCLRE_ON                    EQU     H'3FFF'
_MCLRE_OFF                   EQU     H'3FDF'
_PWRTE_OFF                   EQU     H'3FFF'
_PWRTE_ON                    EQU     H'3FEF'
_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'



Question: Can someone please help me understand what exactly the _CONFIG does in asm coding? My first impression is that its setting up the microprocesor with pre-assigned values so that the microprocessor will operate in a predetermined way. An analogy of _CONFIG in my mind would be for example when a person drives a car. He/she must first sit  in the car seat, adjust the car seat, put the seatbelt on,insert the keys into the ignition (i.e. all pre driving configuration requirements) and ONLY then start the car.....am I understanding correctly?

If the micro needs to be pre-configured  before the main ASM SW body starts, then why not simply use the MOVLW and MOVWF functions to do the configuration? In otherwords, why the emphasis on using the underscore config (_CONFIG)  followed by underscore CP _OFF  etc i.e. _CONFIG _CP_OFF? What exactly does the "_" preceeding the text tell the processor to do?



 

Offline mobbarley

  • Regular Contributor
  • *
  • Posts: 200
  • Country: au
Re: Question on use of _CONFIG directive in asm coding
« Reply #1 on: January 22, 2012, 06:11:32 am »
Pics have one or more CONFIG registers which set some hardware related options usually needed at power up. You can only change these registers at the time the PIC is programmed.

The __CONFIG stuff is a macro that sets the relevant config bits in the HEX file that is to be programmed. Each option is a number, you are combining the numbers (bits).

Your pic has one config register - see 'Section 9.1 Configuration Bits' for info on what they do. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/41190G.pdf


As an example, for your pic:
_CP_OFF is the 'Code Protection bit' and would equal 64 (0b01000000),
 _CPD_OFF would equal 128 (0b10000000).
When these numbers are combined you get both bits set: 192 (0b11000000).

However, the config bits in the inc files are written as complements (inverted) - this is why they are combined with an AND (&) instead of an OR (|)

This is how the bits in the config register are set.

« Last Edit: January 22, 2012, 06:16:58 am by mobbarley »
 

Offline EENG

  • Contributor
  • Posts: 21
Re: Question on use of _CONFIG directive in asm coding
« Reply #2 on: January 22, 2012, 06:47:46 am »
Hallo

Thanks for the reference link to section 9.1 in the data sheet. Its making sense now.

Much appreciated
 

Offline Graham1904

  • Contributor
  • Posts: 7
Re: Question on use of _CONFIG directive in asm coding
« Reply #3 on: January 22, 2012, 09:59:53 am »
You can also get help from opening the PICxxxxx.inc file and this (at the bottom) gives you the "names" of the _CONFIG definitions.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf