Assembly Help

Thread Starter

jakery

Joined Oct 28, 2013
2
Hey guys,

I've been working on an assembly assignment program for some time now and am having a few issues nearing the completion of the program. Basically it reads values from the ADC and checks if they are correct. It needs to check 4 values.

The program is for a PICF690 microcontroller is MPLAB v8.

Here is my code atm:

http://pastebin.com/3CNBfRsg

So my problem is this, I read the value from the potentiometer and parse it to the LED's just fine, this is working as it should (thankfully).

I now need to record the value from the ADC when the switch is high and check if this value is correct and this is where I am having issues. I understand that I want to subtract the value from a number and determine if it is 0 (if it is than the number was correct), but I'm having issues implementing this, you can see my pseduo attempt within.

If this should be posted elsewhere I apologise,

I would appreciate any help at all, I'm desperate.

Regards.
 

ErnieM

Joined Apr 24, 2011
8,377
This is a fine spot for your post. Welcome to the forums!

It would be most helpful (to YOU) if you post your code here instead of linking to it. DO put code tags (see the # icon above the reply text box?) so it keeps formatting.

Especially with just one post it is likely no one will follow your link, and I would advice everyone to do just that.
 

Thread Starter

jakery

Joined Oct 28, 2013
2
Thanks,

Here is is:

Rich (BB code):
#include <p16f690.inc>

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)

; Setup ADC subroutine 
				
				ORG 	0x00
		pause	EQU		0x10
		pause1	EQU		0x20
		val1	EQU		0x21
		val2	EQU		0x22
		val3	EQU		0x23
		val4	EQU		0x24
		checkVal	EQU		0x25
				goto 	main		



	
		checkError
		;		return
	
		checkCorrect
		;		return	
	
	#include <p16f690.inc>

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)

; Setup ADC subroutine 
				
				ORG 	0x00
		pause	EQU		0x10
		pause1	EQU		0x20
		val1	EQU		0x21
		val2	EQU		0x22
		val3	EQU		0x23
		val4	EQU		0x24
		checkVal	EQU		0x25
				goto 	main		



	
		checkError
		;		return
	
		checkCorrect
		;		return	
	
		readVal1

		;		call 		readADC
		;		movlw		W, val1
							
		;		call 		LED1
		;		goto  		loop1		

		readVal2	
		
		;		call 		readADC
		;		movlw		W, val2
							
		;		call 		LED1
		;		goto  		loop1

		readVal3	

		;		call 		readADC
		;		movlw		W, val3
							
		;		call 		LED1
		;		goto  		loop1
				
		readVal4					
		;		call 		readADC
		;		movlw		W, val4
							
		;		call 		LED1
		;		goto  		loop1

;		check	btfsc		subwf val1,1
		;		call 		checkError
				
		;		btfsc		subwf val2,2
		;		call 		checkError
				
		;		btfsc		subwf val3,3
		;		call 		checkError
				
		;		btfsc		subwf val4,4
		;		call 		checkError
				
		;		call 		checkCorrect			

		; Subroutine setSwitch
		
		LED1				 
				movwf		PORTC
			;	bsf			PORTC, W
				call		delay
				bcf			PORTC, W
				return
		
		delay
				decfsz		pause,f
				goto 		delay
				decfsz		pause1,f
				goto		delay
				return
		
		setSwitch 
				BANKSEL		TRISA	;Select BankA
				bsf			TRISA,3	;Set bit3 PORTA as input
				BANKSEL 	PORTA 	;select bank 0		
				return
		
		setLEDs	
				BANKSEL		TRISC
				CLRF		TRISC	
				BANKSEL		PORTC
				RETURN


 			
		initTimer0 
				BANKSEL 	OPTION_REG
 				movlw 		B'10000111' ; Configure Timer0
 				movwf 		OPTION_REG ; Maximum prescalar
 				BANKSEL 	TMR0 
 				clrf 		TMR0 ; Initialise Timer0
 				movlw 		B'10100000' ; Timer0 interrupt active
 				movwf 		INTCON
 				return

		setADC
			 	BANKSEL		TRISA 
				bsf 		TRISA,0
				movlw 		0x10
				movwf 		ADCON1 
				BANKSEL 	ANSEL
				bsf 		ANSEL,0
				BANKSEL 	ADCON0 
				movlw 		B'00000001'
				movwf 		ADCON0 
				goto 		$+1
				goto 		$+1
				goto 		$+1
				return

		readADC 
				BANKSEL 	ADCON0 ; Select bank 0
 				bsf 		ADCON0,GO ; Start ADC conversion
		loop 	btfsc 		ADCON0,GO ; Check if converted
 				goto 		loop ; Poll (loop) until done
 				movf 		ADRESH,W ; Put 8-bit result in W
				return

		main
				call 		setADC ; Setup Channel 0 of ADC
 				call 		readADC ; Read the ADC value
				call 		setSwitch
				call		setLEDs
		loop1	btfsc		PORTA,3
				call 		pressed
				call 		LED1
				goto		loop1	
		
		pressed	call		readADC

				call 		LED1
				
			;	sublw 		val1
			;	btfsc		zflg
			;	goto		$+2
			;	call     	readVal1
				
			;	btfsc		val2
		;		goto		$+2
		;		call     	readVal2
				
		;		btfsc		val3
		;		goto		$+2
		;		call     	readVal3
				
		;		btfsc		val4
		;		goto		$+2
		;		call     	readVal4
				
	
				return

 				goto 		$ 				; Wait here
				end
Would appreciate any help!
 
Last edited:
Top