hack1nblack
New Member
i am trying to get a simple AtoD program to work properly on the PICKit1 board; it assembles OK but lights up other LED's as well as the one which is 'supposed' to be lit,as defined by the trisio values from the original sample programs.
it has got me baffled;any ideas?
my code
;A2D SIMPLE FROM HEAD12F675.ASM FOR 12F675 using 4MHz internal RC.
;WITH AMMENDMENTS BY HACKINBLACK 24/9/2008 ****still lights D0 AND D2***??!!!?
TMR0 EQU 1 ;TMR0 is FILE 1.
TRISIO EQU 85H
GPIO EQU 5 ;GPIO is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
CARRY EQU 0 ;A2D RESULT CARRY BIT0
GO EQU 1
ADSEL EQU 9FH
ADCON0 EQU 1FH
ADRESH EQU 1EH
OPTION_R EQU 81H
CMCON EQU 19H
OSCCAL EQU 90H
COUNT EQU 20H ;USER RAM LOCATION.
;**********************************************************
LIST P=12F675 ;We are using the 12F675.
ORG 0 ;0 is the start address.
GOTO START ;goto start!
;***************************************************
; Configuration Bits
__CONFIG H'3F84' ;selects Internal RC oscillator, WDT off,
;Code Protection disabled.
;**********************************************************
; CONFIGURATION SECTION.
#define LED0TRIS b'11001111' ;LED0=PIN3,2 OF PICKIT1
#define LED0ON b'00010000'
#define LED0OFF b'00000000'
;on/off subroutine
OFF MOVLW LED0OFF
MOVWF GPIO
GOTO BEGIN
ON MOVLW LED0ON
MOVWF GPIO
GOTO BEGIN
START
CLRF GPIO ;Clears GPIO
BSF STATUS,5 ;BANK1
MOVLW LED0TRIS ;******changed********
MOVWF TRISIO
MOVLW B'00010001' ;A0 IS ANALOGUE,FOSC/8
MOVWF ADSEL
MOVLW B'00000111' ;Prescaler is /256
MOVWF OPTION_R
CALL 3FFH
MOVWF OSCCAL ;Calibrates 4MHz oscillator
BCF STATUS,5 ;BANK0
MOVLW 7H
MOVWF CMCON ;Turns off comparator
MOVLW b'00000001' ;left justfy A/D,refVDD,AN0 I/P,A/D stopped,A/D enabled
MOVWF ADCON0
BSF ADCON0,0 ;Turns on A/D converter.
;**********************************************************
;Program starts now.
BEGIN
BSF ADCON0,1 ;START CONVERSION
nop
nop
nop
nop
WAIT
BTFSC ADCON0,1
GOTO WAIT
MOVF ADRESH,W ;MOVE A2D RESULT TO W REGISTER
SUBLW .150 ;SUBTRACT 150 FROM A2D VALUE
BTFSC STATUS,CARRY ;CLEAR IF AN0>150
GOTO OFF
GOTO ON
GOTO BEGIN
END
---------------------------
and the LED shematic
it has got me baffled;any ideas?
my code
;A2D SIMPLE FROM HEAD12F675.ASM FOR 12F675 using 4MHz internal RC.
;WITH AMMENDMENTS BY HACKINBLACK 24/9/2008 ****still lights D0 AND D2***??!!!?
TMR0 EQU 1 ;TMR0 is FILE 1.
TRISIO EQU 85H
GPIO EQU 5 ;GPIO is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
CARRY EQU 0 ;A2D RESULT CARRY BIT0
GO EQU 1
ADSEL EQU 9FH
ADCON0 EQU 1FH
ADRESH EQU 1EH
OPTION_R EQU 81H
CMCON EQU 19H
OSCCAL EQU 90H
COUNT EQU 20H ;USER RAM LOCATION.
;**********************************************************
LIST P=12F675 ;We are using the 12F675.
ORG 0 ;0 is the start address.
GOTO START ;goto start!
;***************************************************
; Configuration Bits
__CONFIG H'3F84' ;selects Internal RC oscillator, WDT off,
;Code Protection disabled.
;**********************************************************
; CONFIGURATION SECTION.
#define LED0TRIS b'11001111' ;LED0=PIN3,2 OF PICKIT1
#define LED0ON b'00010000'
#define LED0OFF b'00000000'
;on/off subroutine
OFF MOVLW LED0OFF
MOVWF GPIO
GOTO BEGIN
ON MOVLW LED0ON
MOVWF GPIO
GOTO BEGIN
START
CLRF GPIO ;Clears GPIO
BSF STATUS,5 ;BANK1
MOVLW LED0TRIS ;******changed********
MOVWF TRISIO
MOVLW B'00010001' ;A0 IS ANALOGUE,FOSC/8
MOVWF ADSEL
MOVLW B'00000111' ;Prescaler is /256
MOVWF OPTION_R
CALL 3FFH
MOVWF OSCCAL ;Calibrates 4MHz oscillator
BCF STATUS,5 ;BANK0
MOVLW 7H
MOVWF CMCON ;Turns off comparator
MOVLW b'00000001' ;left justfy A/D,refVDD,AN0 I/P,A/D stopped,A/D enabled
MOVWF ADCON0
BSF ADCON0,0 ;Turns on A/D converter.
;**********************************************************
;Program starts now.
BEGIN
BSF ADCON0,1 ;START CONVERSION
nop
nop
nop
nop
WAIT
BTFSC ADCON0,1
GOTO WAIT
MOVF ADRESH,W ;MOVE A2D RESULT TO W REGISTER
SUBLW .150 ;SUBTRACT 150 FROM A2D VALUE
BTFSC STATUS,CARRY ;CLEAR IF AN0>150
GOTO OFF
GOTO ON
GOTO BEGIN
END
---------------------------
and the LED shematic