• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

need little clarification about the code

Status
Not open for further replies.

wejos

Member
1. what are the 0x0c, 0x0d and 0x0e (commented as general purpose register) given in the code below? because i cannot find them in the 16f84 registry. Do they act there as variables?

tmr0 equ 0x01 ; Timer/counter register
status equ 0x03 ; Status word register. See Easy PIC'n p. 145
portA equ 0x05 ; Port A register
portB equ 0x06 ; Port B register
intCon equ 0x0b ; Interrupt control register
rcvReg equ 0x0c ; General purpose register
count equ 0x0d ; General purpose register
temp equ 0x0e ; General purpose register
optReg equ 0x81 ; File register in Bank 1
trisA equ 0x85 ; File register in Bank 1. See Easy PIC'n p. 145
trisB equ 0x86 ; File register in Bank 1. See Easy PIC'n p. 145

2. can i do this?

if rcvReg = binary-value-of-letter-"a" then RB1 will go high


full source is from PIC16F84 Fundamentals (if you pressed a letter from the keyboard the pic will light a couple of leds equivalent to the binary value):

; FILE: rcv1_1.asm
; AUTH: P.Oh
; DATE: 04/27/02 18:00 1.0 - WORKS
; 04/27/02 18:35 1.1
; DESC: 1.0: PC-to-PIC serial communications. LEDs display binary equivalent
; of key typed on PC
; 1.1: Same as 1.0 but eliminates need for switch
; REFS: rcv4800.asm in PIC'n Techniques p. 219

;--------------------------------------------------------------------------
list p=16f84
radix hex
;--------------------------------------------------------------------------
; CPU EQUATES

tmr0 equ 0x01 ; Timer/counter register
status equ 0x03 ; Status word register. See Easy PIC'n p. 145
portA equ 0x05 ; Port A register
portB equ 0x06 ; Port B register
intCon equ 0x0b ; Interrupt control register
rcvReg equ 0x0c ; General purpose register
count equ 0x0d ; General purpose register
temp equ 0x0e ; General purpose register
optReg equ 0x81 ; File register in Bank 1
trisA equ 0x85 ; File register in Bank 1. See Easy PIC'n p. 145
trisB equ 0x86 ; File register in Bank 1. See Easy PIC'n p. 145
;--------------------------------------------------------------------------
; BIT EQUATES
rp0 equ 5
;--------------------------------------------------------------------------
org 0x000

start bsf status, rp0 ; Switch to Bank 1. See Easy PIC'n p. 145
movlw b'00000101' ; A0, A2 are input and the rest are output
movwf trisA
movlw b'00000000' ; Port B: all output
movwf trisB
bcf status, rp0 ; Switch back to Bank 0
clrf portB
clrf rcvReg
; switch btfsc portA, 2 ; Is A2 equal 0? i.e. is switch closed?
; goto switch ; No, so keep checking
doThis call rcv4800 ; Yes, to serial in subroutine
movf rcvReg, w ; Get byte received
movwf portB ; Display byte on the 8 LEDs
circle goto doThis ; Done
;--------------------------------------------------------------------------
rcv4800 bcf intCon, 5 ; Disable tmr0 interrupts
bcf intCon, 7 ; Disable global interrupts
clrf tmr0 ; Clear timer/counter
clrwdt ; Clear wdt prep prescaler assign
bsf status, rp0 ; to page 1
movlw b'11011000' ; set up timer/counter
movwf optReg
bcf status, rp0 ; Back to page 1
movlw 0x08 ; Init shift counter
movwf count
sbit btfsc portA, 0 ; Look for start bit
goto sbit ; For Mark
movlw 0x98 ;
movwf tmr0 ; Load and start timer/counter
bcf intCon, 2 ; Clear tmr0 overflow flag
time1 btfss intCon, 2 ; Has the timer (bit 2) overflowed? Skip next line if 1
goto time1 ; No
btfsc portA, 0 ; Start bit still low?
goto sbit ; False start, go back
movlw 0x30 ; real, define N for timer
movwf tmr0 ; start timer/counter - bit time
bcf intCon, 2 ; Clear tmr0 overflow flag
time2 btfss intCon, 2 ; Timer overflow?
goto time2 ; No
movlw 0x30 ; Yes, define N for timer
movwf tmr0 ; Start timer/counter
bcf intCon, 2; ; Clear tmr0 overflow flah
movf portA, w ; Read port A
movwf temp ; Store
rrf temp, f ; Rotate bit 0 into carry flag
rrf rcvReg, f ; Rotate carry into rcvReg bit 7
decfsz count, f ; Shifted 8?
goto time2 ; No
time3 btfss intCon, 2 ; Timer overflow?
goto time3 ; No
return ; Yes, byte received
;-----------------------------------------------------------------------
end
;-----------------------------------------------------------------------
; At blast time, select:
; memory unprotected
; watchdog timer disabled
; standard crystal (4 MHz)
; power-up timer on
;=======================================================================
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,
When you post code, if you select the code and then click on the '#' in the menu bar it will keep the formatting.:)

If you look at 16F84 datasheet, you will see the Registers start at address 0x0C and so on. its just a Register address.

Code:
; FILE: rcv1_1.asm  
; AUTH: P.Oh 
; DATE: 04/27/02 18:00 1.0 - WORKS  
; 04/27/02 18:35 1.1  
; DESC: 1.0: PC-to-PIC serial communications. LEDs display binary equivalent  
; of key typed on PC  
; 1.1: Same as 1.0 but eliminates need for switch  
; REFS: rcv4800.asm in PIC'n Techniques p. 219  

;--------------------------------------------------------------------------  
	list	p=16f84
	radix	hex
;--------------------------------------------------------------------------  
; CPU EQUATES 

tmr0	equ	0x01		; Timer/counter register
status	equ	0x03		; Status word register. See Easy PIC'n p. 145
portA	equ	0x05		; Port A register
portB	equ	0x06		; Port B register
intCon	equ	0x0b		; Interrupt control register
rcvReg	equ	0x0c		; General purpose register
count	equ	0x0d		; General purpose register
temp	equ	0x0e		; General purpose register
optReg	equ	0x81		; File register in Bank 1
trisA	equ	0x85		; File register in Bank 1. See Easy PIC'n p. 145
trisB	equ	0x86		; File register in Bank 1. See Easy PIC'n p. 145
;--------------------------------------------------------------------------  
; BIT EQUATES 
rp0	equ	5
;--------------------------------------------------------------------------  
	org	0x000

start	bsf	status,rp0	; Switch to Bank 1. See Easy PIC'n p. 145
	movlw	b'00000101'	; A0, A2 are input and the rest are output
	movwf	trisA
	movlw	b'00000000'	; Port B: all output
	movwf	trisB
	bcf	status,rp0	; Switch back to Bank 0
	clrf	portB
	clrf	rcvReg
; switch btfsc portA, 2 ; Is A2 equal 0? i.e. is switch closed?  
; goto switch ; No, so keep checking  
doThis	call	rcv4800		; Yes, to serial in subroutine
	movf	rcvReg,w	; Get byte received
	movwf	portB		; Display byte on the 8 LEDs
circle	goto	doThis		; Done
;--------------------------------------------------------------------------  
rcv4800	bcf	intCon,5	; Disable tmr0 interrupts
	bcf	intCon,7	; Disable global interrupts
	clrf	tmr0		; Clear timer/counter
	clrwdt			; Clear wdt prep prescaler assign
	bsf	status,rp0	; to page 1
	movlw	b'11011000'	; set up timer/counter
	movwf	optReg
	bcf	status,rp0	; Back to page 1
	movlw	0x08		; Init shift counter
	movwf	count
sbit	btfsc	portA,0		; Look for start bit
	goto	sbit		; For Mark
	movlw	0x98		;
	movwf	tmr0		; Load and start timer/counter
	bcf	intCon,2	; Clear tmr0 overflow flag
time1	btfss	intCon,2	; Has the timer (bit 2) overflowed? Skip next line if 1
	goto	time1		; No
	btfsc	portA,0		; Start bit still low?
	goto	sbit		; False start, go back
	movlw	0x30		; real, define N for timer
	movwf	tmr0		; start timer/counter - bit time
	bcf	intCon,2	; Clear tmr0 overflow flag
time2	btfss	intCon,2	; Timer overflow?
	goto	time2		; No
	movlw	0x30		; Yes, define N for timer
	movwf	tmr0		; Start timer/counter
	bcf	intCon,2	; ; Clear tmr0 overflow flah
	movf	portA,w		; Read port A
	movwf	temp		; Store
	rrf	temp,f		; Rotate bit 0 into carry flag
	rrf	rcvReg,f	; Rotate carry into rcvReg bit 7
	decfsz	count,f		; Shifted 8?
	goto	time2		; No
time3	btfss	intCon,2	; Timer overflow?
	goto	time3		; No
	return			; Yes, byte received
;-----------------------------------------------------------------------  
	end
EDIT which assembler are you using.?
 

Attachments

Last edited:

wejos

Member
Code:
; FILE: rcv1_1.asm
; AUTH: P.Oh
; DATE: 04/27/02 18:00 1.0 - WORKS
;	04/27/02 18:35 1.1
; DESC: 1.0: PC-to-PIC serial communications.  LEDs display binary equivalent
;            of key typed on PC
;       1.1: Same as 1.0 but eliminates need for switch
; REFS: rcv4800.asm in PIC'n Techniques p. 219

;--------------------------------------------------------------------------
	list	p=16f84
	radix	hex
;--------------------------------------------------------------------------
; 	CPU EQUATES

tmr0	equ	0x01	; Timer/counter register
status	equ	0x03	; Status word register. See Easy PIC'n p. 145
portA	equ	0x05	; Port A register
portB	equ	0x06	; Port B register
intCon	equ	0x0b	; Interrupt control register
rcvReg	equ	0x0c	; General purpose register
count	equ	0x0d	; General purpose register
temp	equ	0x0e	; General purpose register
optReg	equ	0x81	; File register in Bank 1
trisA	equ	0x85	; File register in Bank 1. See Easy PIC'n p. 145
trisB	equ	0x86	; File register in Bank 1. See Easy PIC'n p. 145
;--------------------------------------------------------------------------
; 	BIT EQUATES
rp0	equ	5
;--------------------------------------------------------------------------
	org	0x000

start	bsf 	status, rp0	; Switch to Bank 1. See Easy PIC'n p. 145
	movlw	b'00000101'	; A0, A2 are input and the rest are output
	movwf	trisA
	movlw	b'00000000'	; Port B: all output
	movwf	trisB
	bcf	status, rp0	; Switch back to Bank 0
	clrf	portB
	clrf	rcvReg          ; switch	
        btfsc	portA, 2	; Is A2 equal 0? i.e. is switch closed?
 	goto	switch		; No, so keep checking
doThis	call	rcv4800		; Yes, to serial in subroutine
	movf	rcvReg,  w	; Get byte received
	movwf	portB		; Display byte on the 8 LEDs
circle	goto	doThis		; Done
;--------------------------------------------------------------------------
rcv4800	bcf	intCon, 5	; Disable tmr0 interrupts
	bcf	intCon,	7	; Disable global interrupts
	clrf	tmr0		; Clear timer/counter
	clrwdt			; Clear wdt prep prescaler assign
	bsf	status, rp0	; to page 1	
	movlw	b'11011000'	; set up timer/counter
	movwf	optReg
	bcf	status, rp0	; Back to page 1
	movlw	0x08		; Init shift counter
	movwf	count
sbit	btfsc	portA, 0	; Look for start bit
	goto 	sbit		; For Mark
	movlw	0x98		; 
	movwf	tmr0		; Load and start timer/counter
	bcf	intCon, 2	; Clear tmr0 overflow flag
time1	btfss	intCon, 2	; Has the timer (bit 2) overflowed?  Skip next line if 1
	goto	time1		; No
	btfsc	portA, 0	; Start bit still low?
	goto 	sbit		; False start, go back
	movlw	0x30		; real, define N for timer
	movwf	tmr0		; start timer/counter - bit time
	bcf	intCon, 2	; Clear tmr0 overflow flag
time2	btfss	intCon, 2	; Timer overflow?
	goto	time2		; No
	movlw	0x30		; Yes, define N for timer
	movwf	tmr0		; Start timer/counter
	bcf	intCon, 2;	; Clear tmr0 overflow flah
	movf	portA, w	; Read port A
	movwf	temp		; Store
	rrf	temp, f		; Rotate bit 0 into carry flag
	rrf	rcvReg, f	; Rotate carry into rcvReg bit 7
	decfsz	count, f	; Shifted 8?
	goto	time2		; No
time3	btfss	intCon, 2	; Timer overflow?
	goto	time3		; No
	return			; Yes, byte received
;-----------------------------------------------------------------------
	end
;-----------------------------------------------------------------------
; At blast time, select:
; 	memory unprotected
; 	watchdog timer disabled
;	standard crystal (4 MHz)
; 	power-up timer on
;=======================================================================
 

wejos

Member
according to wikipedia: Gprs are General purpose registers (GPRs) can store both data and addresses, i.e., they are combined Data/Address registers.
 

ericgibbs

Well-Known Member
Most Helpful Member
ty eric

so i can use them to assign values also?

what do you mean by assmebler? mplab?
hi,
They are temporary storage registers for the program variables.
The variable can be any 8bit data/addr you need for the program.

If you use MPLAB you dont need to redefine the 16F84 PORTs etc
For example the following NAMES are already recognised by MPLAB,
Code:
tmr0	equ	0x01	; Timer/counter register
status	equ	0x03	; Status word register. See Easy PIC'n p. 145
portA	equ	0x05	; Port A register
portB	equ	0x06	; Port B register
If you add this to the program header [ near the top of the listing]
MPLAB will know the address of PORTA when you say: PORTA in your program

Code:
 list p=16f84
 #include <p16f84.inc>
 radix dec
 errorlevel -302, -207
You MUST define the GPR's yourself. OK:)
Code:
rcvReg	equ	0x0c	; General purpose register
count	equ	0x0d	; General purpose register
temp	equ	0x0e	; General purpose register
 
Last edited:

wejos

Member
ty eric, 4 birds with one stone.

i think that's about it, they answered my second question also, according to what i've read there are logical operators that we can use to compare two values (gprs). hope im on the right track...

again ty you have been a big help eric.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top