Solved

read number

Posted on 2009-04-04
17
375 Views
Last Modified: 2012-05-06
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
Comment
Question by:ferman-k
  • 9
  • 8
17 Comments
 
LVL 5

Expert Comment

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

Author Comment

by:ferman-k
ID: 24071324
from some port pins...... please
0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
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

by:ferman-k
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

Open in new window

0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
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

Open in new window

0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
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

by:ferman-k
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

by:Mechanic_Kharkov
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

Open in new window

readnumber-LST.txt
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:ferman-k
ID: 24092885
i use PIC18F88 Basic Target Board (16 bits)
0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
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

by:ferman-k
ID: 24096792
please forgive me for wasting your time, i was mistaken, the device is PIC16F88. and the link for its datasheet is;
http://ww1.microchip.com/downloads/en/DeviceDoc/41203D.pdf

0
 

Author Comment

by:ferman-k
ID: 24096827
here is also the datasheet file i attached...
16f88.pdf
0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
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

by:ferman-k
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

Open in new window

0
 

Author Comment

by:ferman-k
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

                

 

Open in new window

0
 
LVL 5

Accepted Solution

by:
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

by:ferman-k
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 				

							;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 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	

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now