## Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

• Help others & share knowledge
• Earn cash & points
Solved

Posted on 2009-04-04
379 Views
hi/
can anyone help me for some advice and code example that can be used in PICmicro to allow a system to READ (check) if a number is correct or not. for instance, a staff ID number to be input to the system and compare it with a number if correct or not.
0
Question by:ferman-k
• 9
• 8

LVL 5

Expert Comment

ID: 24069927
From where do You plan to input this number? Keyboard, some port pin, UART, or somewhere else?
0

Author Comment

ID: 24071324
0

LVL 5

Expert Comment

ID: 24074650
Number  from pin ports are read with single command. And how do you plan set this number outside the chip, on it's external pins? Are there some buttons, on these pins, or some external device? And where is number to compare with?
There is too little information in Your question to understand what solution You need exactly.
Please, try to tell, where it would be used, and how.
0

Author Comment

ID: 24076442
i am trying to have a six digit number, represent is in binary, for example 00100110 which is equal to 000038 decimal!
and i want my system to allow input through its port and compare any input, if the input happened to be equal to the number i have on my system, send the last hex to a port as output. in this case i know i need if statement, but i have problem constract it...

please look at the code i have written so for, and pleae provide me with an answer to what i could do next
``````
; list p=16f88
;
;*****************************************************************************
;
;**********************************************************************
status		equ 03h	; Status register address
trisA		equ 05h	; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB		equ 06h	; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A		equ 05h	; address of port A
port_B		equ 06h	; address of port B
b		equ 01h	; turn pulse on

rp0		equ 05h	; bit in status register to select register
; bank 1 where trisA reg is stored
;all_out		equ 00h	; sets all register bits as output
;*******************************************************************
org 0h	; gives instruction to the assembly program to set the program at the first memory location
goto main	; instructs the program to jump to the label "Main"
org 010h	; gives instruction to the assembly program to set this line of the program 				;at memory address 0X10
main		bsf status, rp0	; sets the status register so that the program is
;looking a memory block 1 ( what does 0 mean)
movlw register	; moves the value of all_out to the working register
addwf  b 	; puts the value from the working register to the special register trisA
; unsets the flag to the program is back looking at memory block 0
; now port_c is set up as an out put port
; it has taken four lines of to initialise port_c
signal		movlw b		; Now the program can move the value pf Pulse_on to the working register
movwf port_B		; it now moves the value in the working register to port_c
; so the last two lines of code have out put the hex value of 0xff
nop		; this line just increments the program counter but changes nothing else in the system
goto signal	; this line loops the program so it runs for ever
end		; this is an instruction to the assembler to end the program
``````
0

LVL 5

Expert Comment

ID: 24080834
Like this? There is Port A as input, and Port B as output.
But output will newer change (until reset) if needed value will read at least once.

``````; list p=16f88
;
;*****************************************************************************
status		equ 03h	; Status register address
trisA		equ 05h	; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB		equ 06h	; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A		equ 05h	; address of port A
port_B		equ 06h	; address of port B

OurValue	equ 26h	; Our constant to compare with

;***************************************************************
org 0h	; gives instruction to the assembly program to set the program at the first memory location
goto main	; instructs the program to jump to the label "Main"

org 010h	; gives instruction to the assembly program to set this line of the program 				;at memory address 0X10
main	;init ports and port directions
clrf	port_A	;clear ports
clrf	port_B
bsf	status,rp0	;select bank 1
setf	trisA	;port a is input
clrf	trisB	;port b is output
bcf	status,rp0	;select bank 0

input
movlw OurValue  ;load our constant to compare to W
cpfseq port_A	;read 1 byte from port A and compare
;it with Work register (w is not changed)
goto input		;this brunch will be skipped if read from port A
;matched to looked constant in W (skip if Equal)
;but if we read wrong value, then goto will work,
;and will repeat input again
movwf port_B	;output our constant from W to Port B

goto input		;just do all again

end		; this is an instruction to the assembler to end the program
``````
0

LVL 5

Expert Comment

ID: 24080898
And if You plan to enter 7 digit value then You need many input pins or input it with 7 times, and then You need some clock signal to inform device, that order input digit is ready to read.
Either or not, there must be some protocol of such exchange that will depend on external hardware used.
0

Author Comment

ID: 24087214
i usede your code, it seems to be be good, but i tried to run (implement) it but i some unresolved Errors happened to stop the implementation, i have pasted the error messages bellow, can you please allow a soloution.
thank you....

Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F88 "L9.asm" /l"L9.lst" /e"L9.err" /d__DEBUG=1
Warning[207] F:\MPLAB\SEVSEG L9\L9.ASM 24 : Found label after column 1. (setf)
Error[122]   F:\MPLAB\SEVSEG L9\L9.ASM 24 : Illegal opcode (trisA)
Warning[207] F:\MPLAB\SEVSEG L9\L9.ASM 30 : Found label after column 1. (cpfseq)
Error[122]   F:\MPLAB\SEVSEG L9\L9.ASM 30 : Illegal opcode (port_A)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `F:\mplab\sevseg L9\sevseg.mcp' failed.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Tue Apr 07 14:32:57 2009
----------------------------------------------------------------------
BUILD FAILED
0

LVL 5

Expert Comment

ID: 24087581
It caused the wrong device. I have used the opcode setf that is legal for 18f1320 but not for 16f88.
Here is fixed sample for 18f1320 with lst included.
Tell me, what chip are you using exactly?

``````; list p=18f1320
;
;*****************************************************************************
status          equ 03h ; Status register address
trisA           equ 05h ; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB           equ 06h ; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A          equ 05h ; address of port A
port_B          equ 06h ; address of port B
rp0             equ 05h ; bit in status register to select register
; bank 1 where trisA reg is stored

OurValue        equ 26h ; Our constant to compare with

;***************************************************************
org 0h  ; gives instruction to the assembly program to set the program at the first memory location
goto main       ; instructs the program to jump to the label "Main"

org 010h        ; gives instruction to the assembly program to set this line of the program                             ;at memory address 0X10
main            clrf    port_A  ;init ports and port directions
clrf    port_B
bsf     status,rp0      ;select bank 1
setf    trisA   ;port a is input
clrf    trisB   ;port b is output
bcf     status,rp0      ;select bank 0

input			movlw OurValue  ;load our constant to compare to W
cpfseq port_A   ;read 1 byte from port A and compare
;it with Work register (w is not changed)
goto input              ;this brunch will be skipped if read from port A
;matched to looked constant in W (skip if Equal)
;but if we read wrong value, then goto will work,
;and will repeat input again
movwf port_B    ;output our constant from W to Port B

goto input              ;just do all again

end             ; this is an instruction to the assembler to end the program
``````
0

Author Comment

ID: 24092885
i use PIC18F88 Basic Target Board (16 bits)
0

LVL 5

Expert Comment

ID: 24093125
It's strange, but I cannot find datasheet for this chip. If you have a link, share it.
There is 18F87 and next is 18F96 in the Microchip's Data Sheet Finder. :-(
0

Author Comment

ID: 24096792
please forgive me for wasting your time, i was mistaken, the device is PIC16F88. and the link for its datasheet is;

0

Author Comment

ID: 24096827
here is also the datasheet file i attached...
16f88.pdf
0

LVL 5

Expert Comment

ID: 24108563
Yes! 16F88 it the really existing device! :-) But while trying to find 18F88 I have got the newest MPLAB software. :-) It's a good thing.
Thank You for the datasheet. I have blown my system and temporary can't access to my development tools. If it's still actual, I'll look deeper to this tool in 2..3 days.
0

Author Comment

ID: 24112820
i would be so grateful if you provided me with some code examples on how to take a value from outside the world and compare it with a number i already have in my device;

i have already used these lines of code, but i am not sure if its a right work or not!

thank you
``````
;**********************************************************************

status		equ 03h	; Status register address
trisA		equ 05h	; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB		equ 06h	; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A		equ 05h	; address of port A
port_B		equ 06h	; address of port B
z			equ 02h	; bit in status register to select register
; bank 1 where trisA reg is stored
all_out		equ 00h	; sets all register bits as output
digit_1		equ	020h
digit_2		equ	021h
digit_3		equ	022h
digit_4		equ	023h
digit_5		equ	024h
digit_6		equ	025h
digit_7		equ	026h
digit_8		equ	027h

pulse_on	equ 0ffh	; turn pulse on
pulse_off	equ 00h	; turn pulse off
rp0			equ 05h	; bit in status register to select register
; bank 1 where trisA reg is stored

;****************************************************************************************
org 0h		; gives instruction to the assembly program to set the
;program at the first memory location
goto main	; instructs the program to jump to the label "Main"

org 010h		; gives instruction to the assembly program to set this line of the program 				;at memory address 0X10
main	bcf status, z	; sets the status register so that the program is
;looking a memory block 1 (memory location 0)

movlw all_out			; moves the value of all_out to the working register
movwf trisB		; puts the value from the working register to the special register trisA
bcf status, rp0	; unsets the flag to the program is back looking at memory block 0
; now port_c is set up as an out put port
; it has taken four lines of to initialise port_c

;*********assigning the digits (labels)**************

movlw 3 		;we created a value of 3 and put it into W
movwf digit_1	;we assigned the value in W to lable digit_1

movlw 6 		;we created a value of 3 and put it into W
movwf digit_2	;we assigned the value in W to lable digit_2

movlw 2 		;we created a value of 3 and put it into W
movwf digit_3	;we assigned the value in W to lable digit_3

movlw 0 		;we created a value of 3 and put it into W
movwf digit_4	;we assigned the value in W to lable digit_4

movlw 2 		;we created a value of 3 and put it into W
movwf digit_5	;we assigned the value in W to lable digit_5

movlw 2 		;we created a value of 3 and put it into W
movwf digit_6	;we assigned the value in W to lable digit_6

;*******************************
movlw	3
movwf	port_B
subwf	digit_1
btfss	status, z
goto main
;*******************************

movlw	6
movwf	port_B
subwf	digit_2
btfss	status, z
goto main
;*************************************

movlw	2
movwf	port_B
subwf	digit_3
btfss	status, z
goto main
;****************************************

movlw	0
movwf	port_B
subwf	digit_4
btfss	status, z
goto main
;***************************************

movlw	2
movwf	port_B
subwf	digit_5
btfss	status, z
goto main
;***************************************

movlw	2
movwf	port_B
subwf	digit_6

signal	bcf	trisB,0
movwf port_B	; it now moves the value in the working register to port_c
; so the last two lines of code have out put the hex value of 0xff

btfss	status, z
goto main

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

nop				; this line just increments the program counter but changes nothing else in the system
goto main		; this line loops the program so it runs for ever
end				; this is an instruction to the assembler to end the program
``````
0

Author Comment

ID: 24133083
as you can see i have velue for every digit from 1 to 6, the last digit value is 2. can you please instract me howmove that value of digit_6 to my external divice (pic16f88) ICD2, i mean put it in port B on the device. i have used the following codes but it seems to be wrong...

`````` movlw   2
movwf   port_B
subwf   digit_6

signal  bcf     trisB,0
movwf port_B    ; it now moves the value in the working register to port_c
; so the last two lines of code have out put the hex value of 0xff

``````
0

LVL 5

Accepted Solution

Mechanic_Kharkov earned 500 total points
ID: 24139112
It's like You're trying to output value from W after substracting digit_6. Of course this substraction affects value stored in W.
If You need to output value before subtracting, You must not subtract before output or restore this value before output.
E.g. (restore with XOR):

movf     port_B     ; read port B
xorwf    digit_6     ; compare with digit 6 (Z is set if equal)
btfss          status, z  ; if not equal then go to main
goto main

xorwf    digit_6    ; restore value with double XOR. or we can load it again (movf digit_6)

signal     bcf        trisB,0
movwf  port_B    ; it now moves the value in the working register to port_b

And, it's like to output values vs input them (?). What exactly must do this program?
These lines don't input values from port B but output:
movlw      2
movwf      port_B ; output
subwf      digit_3
btfss      status, z
goto main

0

Author Comment

ID: 24179279
i have used your method for the following code;; and i could successfully send the output to my device, please also not that my device is a chip with four LEDs which are connected to RB0, RB1, RB2, RB3 on it.

however, i tried to use your methode in the same way in the code i sent you on (09/04/09 05:35 PM, ID: 24112820... which you can find it in the previous questions), but i was still unseccessfull to sent the output...

can you please compare my previouse code with this one, and come to a reason why i am un able to sent 2 out to my device...

thank you
``````status		equ 03h		; Status register address
trisA		equ 05h		; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB		equ 06h		; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A		equ 05h		; address of port A
port_B		equ 06h		; address of port B
pulse_on	equ 0ffh	; turn pulse on
pulse_off	equ 00h		; turn pulse off
rp0		equ 05h			; bit in status register to select register
; bank 1 where trisA reg is stored
all_out		equ 00h		; sets all register bits as output
digit_3 	equ 020h
;*******************************************************************
org 0h				; gives instruction to the assembly program to set the program at the first memory location
goto main			; instructs the program to jump to the label "Main"
org 010h			; gives instruction to the assembly program to set this line of the program
main		bsf status, rp0	; sets the status register so that the program is
;looking a memory block 1 ( what does 0 mean)
movlw all_out		; moves the value of all_out to the working register
movwf trisB			; puts the value from the working register to the special register trisA
bcf status, rp0		; unsets the flag to the program is back looking at memory block 0
; now port_c is set up as an out put port
; it has taken four lines of to initialise port_c

movlw      2
movwf      port_B  ; output
subwf      digit_3

goto 		main
end
``````
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The business world is becoming increasingly integrated with tech. Itâ€™s not just for a select few anymore â€” but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and itâ€™s likelyâ€¦
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaacâ€¦