homemade24
New Member
I'm trying to covert some code I did in Pic Basic to assembly
and before I get to far off base I'm asking for help
which the part I'm working now is a
if it's day do this
if it's night do something different
the #550 is just what centered the calibration pot on my Basic code
I think I have everything right until you get to the ? marks (I think!!!)
then I'm lost thinks
and yes I'm using a external crystal
thanks
and before I get to far off base I'm asking for help
which the part I'm working now is a
if it's day do this
if it's night do something different
the #550 is just what centered the calibration pot on my Basic code
I think I have everything right until you get to the ? marks (I think!!!)
then I'm lost thinks
and yes I'm using a external crystal
thanks
Code:
;*******************************************************************************;
; 16f676 A/D TEST
; !!! USING 4MHz EXTERNAL CLOCK !!!!!!
; HARDWARE 10K PHOTO CELL /10 K POT VOLTAGE DIVIDER POWER FROM PORTA,1 ADIN PORTA,0
; IS IT DAY OR IS IT NIGHT
;********************************************************************************;
#include "p16F676.inc"
errorlevel -302
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _MCLRE_OFF & _CPD_OFF
cblock 0x20
; **********************************************************************************
NIGHT ;HOLDS A/D RESULTS
d1 ;USED BY DELAY
d2
d3
endc
org 0
nop
;**********************************************************************************;
Start:
bcf STATUS,RP0 ; register page 0
bcf STATUS,RP1 ; register page 0
movlw 0X07 ;SET UP W TO TURN COMPARATOR OFF
movwf CMCON ;IS NO BANK 0
MOVLW B'10000100' ; SELECT RIGHT JUSTIFIED,VDD,CHANNEL 00(AN0)
MOVWF ADCON0 ; IS IN BANK 0
bsf STATUS,RP0 ; GOTO BANK 1
movlw b'00001101' ;CONFIG I/O PORTA
movwf TRISA ; IS IN BANK 1
movlw b'00000000' ;CONFIG I/O PORTC
movwf TRISC ; IS IN BANK 1
MOVLW B'00000001' ; SELECT AN0
MOVWF ANSEL ;IS IN BANK 1
MOVLW B'00000101' ; SELECT 16 TOSC
MOVWF ADCON1 ; IS IN BANK 1
bcf STATUS,RP0 ; BACK TO BANK 0
BSF PORTA,1 ;TURN ON POWER TO PHOTO CELL
movlw 0x03 ; Delay = 0.5 seconds ;DELAY FOR PHOTO CELL POWER AND STABLIZE
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;6 cycles
goto $+1
goto $+1
goto $+1
TEST:
clrf NIGHT ; clear the NIGHT VAR
BSF ADCON0, GO ; GO GET ME A SAMPLE
Wait_Loop ; LOOP UNTIL IT GET IT AND IS DONE
BTFSC ADCON0, GO ; WAIT FOR A/D CONVERSION TO FINISH
GOTO Wait_Loop ; ADC will clear bit ADCON0,GO when done
MOVF ADRESH, W ; GET SAMPLED DATA
movwf NIGHT ; PUT DATA IN NIGHT VAR ?????????
; ?????????????????????? SCALE 0-1024 ?????????????????????????
IF NIGHT =<550 THEN GO DO SOMETHING ;IT'S NIGHT
IF NIGHT >550 THEN DO SOMETHING DIFFERENT ;IT'S DAY
;?????????????????????????????????????????????????????????????????
GOTO TEST
END