Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Below is my code, I have lots of research but I don't get it! I have cobined things that look vaguely similar but they won't go together!

;****************************************************************************************************
;					DEFINITIONS						     
;****************************************************************************************************
 
		list    P=PIC16F84A, R=D	;Define PIC type and radix
				;(H=Hex, D=Decimal). Hex numbers must
				;be of the form 0xAA or 0AAh
		include "P16F84A.INC"4	;P16F84A.INC is a file containing
				;definitions of PIC registers
 
;****** REGISTER USAGE ******
 
;For PIC16C84, user RAM starts at 0Ch. The following definitions
;(the names are arbitrary) will be found useful in many programs.
 
count   equ	0Ch		;Counter register
flag    equ    	0Dh		;Counter Flag
msloop	equ    	0Eh		;Microsecond delay loop register
tenloop	equ	0Fh		;Tenth of second delay loop register
secloop	equ	10h		;One Second delay loop register
 
 
;****************************************************************************************************
;					VECTORS							     
;****************************************************************************************************
 
;The PIC16C84 vectors live at the bottom of memory (0000h-0007h)
 
		org	0000h		;Reset vector for PIC16C84 is at 0000h
        	goto    start		;Go to main program start
		org	0004h		;Interrupt vector for PIC16C84 is at 0004h
		goto	inter		;Go to start of interrupt service routine
		org	0008h		;first location available to programs
 
;****************************************************************************************************
;					SUBROUTINES 						     
;****************************************************************************************************
 
;By convention, subroutines are placed after the vectors so that they
;are at the bottom of memory. This avoids memory bank-switching for
;small programs.
 
 
;Gives a 1 microsecond delay

onems	movlw	248		;Moves number 248 into the working register
	movwf	msloop		;Moves number from working register to msloop
loop1	nop			;Used for padding
	decfsz 	msloop,1	;Decrements msloop by 1, skips next instruction if zero
	goto    loop1		;Continues to loop until msloop reaches zero
	nop			;Used for padding
	return
 
;Gives a 0.1 Second Delay

tenth   movlw	100		;Moves number 100 into the working register
	movwf	tenloop		;Moves number from working register to tenloop
loop2	call	onems		;Calls the 1 microsecond delay subroutine
	decfsz	tenloop,1	;Decrements tenloop by 1, skips next instruction if zero
	goto	loop2		;Continues to call microsecond delay until tenloop reaches zero
	return
 
;Gives a 1 Second Delay

sec	movlw	10		;Moves number 10 into the working register
	movwf	secloop		;Moves number from working register to tenloop
loop3	call	tenth		;Calls the tenth of a second delay subroutine
	decfsz	secloop,1	;Decrements secloop by 1, skips next instruction if zero
	goto	loop3		;Continues to call 0.1 second delay until secloop reaches zero
	return

;Preset Flashing Output Sequence

outseq	bsf	PORTB,1		;Sets bit 1 of output port
	call	sec		;Calls the one second delay subroutine
	bcf	PORTB,1		;Clears bit 1 of output port
	call	sec		;Calls the one second delay subroutine
	goto	outseq		;Continues to flash output bit 1 until interrupted
	return
 
 
;****************************************************************************************************
;					MAIN PROGRAM						     
;****************************************************************************************************
 
;****** INITIALISATION ******
 
;Before using the I/O ports, the data direction registers must be set
;up. Bit RP0 in the status register selects either the normal register
;set when 0, or the special register set when 1. The data direction
;registers TRISA and TRISB live in the special register set. A '1' in
;these registers sets the corresponding port line to an Input, and a
;'0' makes the corresponding line an output.
 
start	bsf	STATUS,RP0		;Select special register set
 
		movlw	b'11111'	;Set every pin on PORTA to be an Input
		movwf	TRISA
		movlw	b'00000000'	;Set every pin on PORTA to be an Ouput
		movwf	TRISB
 
		bcf		STATUS,RP0	;Select normal register set
 

;****** MAIN PROGRAM ******
 
;Reset Count and Flag Registers and Clear Outputs
		clrf	count		;Clears value in count register
		movlw	b'00000000'	;Copies binary value 00000000 into working register
 		movwf	PORTB		;Copies value from working register to Output Port 
		clrf	flag		;Clear flag register

;Counting with a flag
wait	btfsc	PORTA,0			;Tests bit 0 of Input Port skips next instruction if zero 
		goto	up		;If bit 0 on then program goes to label up
		bcf	flag,0		;Clears bit 0 of the flag register
		goto	wait		
up		btfsc	flag,0		
		goto 	wait
		bsf	flag,0		;Sets bit 0 of the flag register
		incf	count,1		;Increments value in count by 1
	
;EXOR count register with 100
		movlw	100		;Moves number 100 into working register
		xorwf	count,0		;EXORs count with the number in the working register
		btfss 	STATUS,Z	;Checks Status Bit Z to see if all bits in working register are set
		goto	wait
		bsf	PORTB,0		;Sets bit 0 of Output Port if EXOR is successful

;EXOR count register with 200	
		movlw	200		;Moves number 200 into working register
		xorwf	count,0		;EXORs count with the number in the working register
		btfss 	STATUS,Z	;Checks Status Bit Z to see if all bits in working register are set		
		goto	wait
		call	outseq		;Calls ouput sequence 
What can you do to help me? Thanks
Posted
Updated 8-Mar-14 9:13am
v2
Comments
Sergey Alexandrovich Kryukov 8-Mar-14 13:36pm    
Help with what? This is not a question, just code dump.
—SA

You don't code by "cobined things that look vaguely similar" because they "they won't go together"

Instead you are expected to know things, and learn things, and try to actually do things yourself.

Grabbing random bits of code from the internet, throwing them together and hoping they will work together is not a successful tactic when it comes to development of any form, and definitely not when dealing with assembly code.

Now go back to the beginning, and try to work out how to do it from first principles - personally I would start by turning the LED on and of in a regular sequence, then switching it each time the button way pressed when that worked.
Then finally I'd handle the multiple presses.
 
Share this answer
 
Perhaps your approach is wrong. The best way to start with a new device is to find some working code and try to understand how it does things. Then make small modifications ensuring that the code continues to work. This is how we all do it even experienced guys.

Try for example:

http://www.talkingelectronics.com/projects/PIC_LAB-1/PicLab1_experiments-P2.html[^]

or:

http://www.micro-examples.com/public/microex-navig/doc/100-led-blinking.html[^]

and:

http://www.talkingelectronics.com/projects/Elektor/Gooligum%20PIC%20Tutorials/PIC_Base_A_2.pdf[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900