14-bit configuration word in PIC16F877

Status
Not open for further replies.

JAMAL JIMI

Member level 1
Joined
Dec 14, 2013
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
233
How to program the 14-bit wide configuration word in the PIC16F877 at location 2007h in the program memory........Can any one please give me the assembly example....???
 

The configuration bits can be properly set by using the Assembler Directive with proper bitmasks, example:

Code:
__CONFIG _LVP_OFF & _DEBUG_OFF & _CP_OFF & _CPD_OFF & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

The specific bitmasks for a particular PIC model can be obtain by referencing its specific INC file.

Reference: P16F877.INC

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
...
;==========================================================================
;
;       Configuration Bits
;
;   NAME            Address
;   CONFIG            2007h
;
;==========================================================================
 
; The following is an assignment of address values for all of the
; configuration registers for the purpose of table reads
_CONFIG          EQU  H'2007'
 
;----- CONFIG Options --------------------------------------------------
_LP_OSC              EQU  H'3FFC'    ; LP oscillator
_XT_OSC              EQU  H'3FFD'    ; XT oscillator
_HS_OSC              EQU  H'3FFE'    ; HS oscillator
_RC_OSC              EQU  H'3FFF'    ; RC oscillator
 
_WDT_OFF             EQU  H'3FFB'    ; WDT disabled
_WDT_ON              EQU  H'3FFF'    ; WDT enabled
 
_PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
_PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled
 
_CP_All              EQU  H'0FCF'    ; 0000h to 1FFFh code protected
_CP_HALF             EQU  H'1FDF'    ; 1000h to 1FFFh code protected
_CP_UPPER_256        EQU  H'2FEF'    ; 1F00h to 1FFFh code protected
_CP_OFF              EQU  H'3FFF'    ; Code protection off
 
_BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
_BODEN_ON            EQU  H'3FFF'    ; BOR enabled
 
_LVP_OFF             EQU  H'3F7F'    ; RB3 is digital I/O, HV on MCLR must be used for programming
_LVP_ON              EQU  H'3FFF'    ; RB3/PGM pin has PGM function; low-voltage programming enabled
 
_CPD_ON              EQU  H'3EFF'    ; Data EEPROM memory code-protected
_CPD_OFF             EQU  H'3FFF'    ; Code Protection off
 
_WRT_ENABLE_OFF      EQU  H'3DFF'    ; Unprotected program memory may not be written to by EECON control
_WRT_ENABLE_ON       EQU  H'3FFF'    ; Unprotected program memory may be written to by EECON control
 
_DEBUG_ON            EQU  H'37FF'    ; In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
_DEBUG_OFF           EQU  H'3FFF'    ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
 
...
...



There are some significant differences between the PIC16F877 and the PIC16F877A ensure which particular version you are utilizing.

Additional details are available in the following tutorial:



BigDog
 
What is meant by the word 'EQU'.......I never used this word before...

- - - Updated - - -

What is meant by the word 'EQU'.......I never used this word before...
 

Hi,

As well as looking at the .INC file as mentioned by BigDog, also look in the TEMPLATES folder which gives you a bit of stater code for each chip.
However do check the code, as the Config line for the 877 has LVP=ON, normally it is OFF.

Below is a simple assembler example just high lighting the key Config Parameters / changes to the Default from the .Inc file

Code:
;       progam to flash all of PortB pins on and off every 4 seconds
; 		based on a 4 mhz crystal


		list p=16f877
		include p16f877.inc
		__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON & _LVP_OFF
	
		cblock 0X20			; specify user regiaters ( easier than EQU)
		d1
		d2
		d3
		COUNT
		endc



		org 	0x000
		GOTO	Main



Main	CLRF	PORTB		; Set portb,c,d to digital outputs
		CLRF   	PORTC
		CLRF 	PORTD
		BANKSEL TRISA
		CLRF	TRISB
		CLRF 	TRISC
		CLRF 	TRISD
		BANKSEL 0

		

LOOP						; main program looP
		CALL	DELAY4s		; call this subrutine
		MOVLW   0xFF
		MOVWF	PORTB		; Set  port HIGH

		CALL	DELAY4s

		MOVLW   0x00
		MOVWF	PORTB		; Set  port LOW
		GOTO	LOOP		


;  SUBROUTINES
	
DELAY4s						; 4 SECOND DELAY
		movlw	0x23
		movwf	d1
		movlw	0xB9
		movwf	d2
		movlw	0x09
		movwf	d3
Delay_0
		decfsz	d1, f
		goto	dly1
		decfsz	d2, f
dly1	goto	dly2
		decfsz	d3, f
dly2	goto	Delay_0
	

		return

		END					; END OF PROGRAM CODE
 
What is meant by the word 'EQU'.......I never used this word before...

Reference: MPASM™ Assembler, MPLINK™ Object Linker, MPLIB™ Object Librarian User’s Guide, Section: 4.27 equ – DEFINE AN ASSEMBLER CONSTANT, Page: 81

The Assembler Directive EQU simply assigns the bitmask labels, _LVP_OFF, _DEBUG_OFF, _CP_OFF, _CPD_OFF, etc ...., numerical bitmask values which are then bitwise AND'd to form the final bitmask passed to the __CONFIG Assembler Directive, which in turn utilizes the bitmask to set the Configuration Register, address location 2007h, to the required state.


BigDog
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…