Problema con ADC Pic16f526

Buenas noches.

Estoy empezando a programar PICs en ASM. He estado haciendo unas pruebas con este modelo, ya que lo tengo a mano y creo que me puede ser util por tamaño, reloj interno...

El caso es que estoy intentando crear una rutina para que active una salida segun el nivel de continua en la entrada analogica, y no hay manera.

Simulandola esta todo correcto, pero cuando lo implemento en el PIC, se activa la salida con cualquier nivel en la entrada analogica, solamente con 0 queda desactivada.

Alguna idea?

El codigo:

Código:
; PROCESSOR DECLARATION
 ;------------------------------------------------------------------------------
      LIST      p=16F526             ; list directive to define processor
      #INCLUDE <P16F526.INC>         ; processor specific variable definitions
 ;------------------------------------------------------------------------------
 ;
 ; CONFIGURATION WORD SETUP
 ;
 ; The 'CONFIG' directive is used to embed the configuration word within the 
 ; .asm file. The lables following the directive are located in the respective 
 ; .inc file.  See the data sheet for additional information on configuration 
 ; word settings.
 ;
 ;------------------------------------------------------------------------------
	__CONFIG 0XD4
 ;------------------------------------------------------------------------------
 ;
 ; VARIABLE DEFINITIONS
 ;
 ; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
 ; Special Function Registers and General Purpose Registers at the locations 
 ; below:  
 ;
 ;           SFR         SHARED GPR's   GPR's       
 ; Bank 0    0x00-0x0C   0x0D-0x0F      0x10-0x1F 
 ; Bank 1    0x20-0x2C   0x2D-0x2F      0x30-0x3F 
 ; Bank 2    0x40-0x4C   0x4D-0x4F      0x50-0x5F 
 ; Bank 3    0x60-0x6C   0x6D-0x6F      0x70-0x7F 
 ;
 ;------------------------------------------------------------------------------	
		Analog	EQU	0x0D
		AUX1	EQU	0x11
		AUX2	EQU 0x12
		AUX3	EQU 0x13

;Reeseteo:
		ORG		0x0000
		Goto	Start

Start	
;Configuracion:
		Banksel 0
		movlw	0x71
		movwf	CM1CON0
		movlw	0x71
		movwf	CM2CON0
		MOVLW	0XE
		TRIS 	PORTB
		MOVLW	0X00
		TRIS	PORTC
		movlw	0x7E
		MOVWF	OSCCAL     ;CALIBRADO DEL OSCILADOR A MAX FREQ
		MOVLW	0X79
		MOVWF	ADCON0
		MOVLW	0X00
		MOVWF	VRCON
;COMIENZA EL PROGRAMA:
Reinicio	MOVLW	0X00
			MOVWF	PORTC
			MOVWF	PORTB
Inicio		CALL	Comparacion
			movwf	PORTC
			CALL	Delay
			movlw	0x00
			movwf	PORTC
			goto	Inicio

Comparacion
			CALL	Conversion
			movlw	0x80
			addwf	Analog,0
			btfsc	STATUS,C
			retlw	0xFF
			retlw	0x00

Conversion
			BSF 	ADCON0, 1 ;start conversion
loop0 		BTFSC 	ADCON0, 1;wait for ‘DONE’
			GOTO 	loop0
			MOVF 	ADRES, W ;read result
			MOVWF 	Analog ;save result
			retlw 	0x00

Delay

			;3999994 cycles
			movlw	0x23
			movwf	AUX1
			movlw	0xB9
			movwf	AUX2
			movlw	0x09
			movwf	AUX3
Delay_0
			decfsz	AUX1, f
			goto	$+2
			decfsz	AUX2, f
			goto	$+2
			decfsz	AUX3, f
			goto	Delay_0
		
					;2 cycles
			goto	$+1
		
					;4 cycles (including call)
			return
			END

Gracias!

Por cierto, no le busqueis logica al codigo, el delay y demas es porque tenia mas funcionalidades, pero he ido reduciendo por el tema del ADC, que no hay manera, y ha acabado asi, hasta que entienda que sucede con este :D
 
Última edición:
Atrás
Arriba