Hiç yokmu bu pic i bilen bir arkadaşım. Temel bir ADC programı istiyorum işin ustaları için basit olsa gerek. ben bir tane program buldum ama macro felan kullanmıs biraz anlamadım.
Program gelen voltaj seviyesini anlıyor ve gelen gerilim 2.93V ile 3.42V arasında ise çıkışında ki ledi yakıyor.
;gpi.asm
;Gear position indicator program for PIC12F675
;measures voltage on AN0 (pin 7) with ADC
;if voltage is between 2.93 V and 3.42 V, LED (pin 2) is on
;otherwise it is off
;ADC is 10 bits, and has a max. value of 0x3FF or 1023.
;With a 5 V reference, this gives a resolution of 5/1024
;or 4.88 mV.
list p=12f675 ;list directive to define processor
#include "p12f675.inc" ;processor specific variable definitions
;-----------------------------------------------------------------
;defines
;-----------------------------------------------------------------
#define LED 5
#define ADC 0
#define UPPER_LIMIT .700 ;3.42 V
#define LOWER_LIMIT .600 ;2.93 V
;------------------------------------------------------------------
;macro definitions
;------------------------------------------------------------------
;macro compares the 16 bit value stored in fr,
;fr-1 to a 16 bit literal number. It jumps to
;an address if the value in the registers is higher
;than the literal.
cjalwd macro fr1,L1,L2,addr
movf fr1,W
sublw L1
btfss STATUS,C
goto addr
movlw L1
subwf fr1,W
btfss STATUS,C
goto $+5
movf fr1-1,W
sublw L2
btfss STATUS,C
goto addr
endm
;-----------------------------------------------------------------
;variables
;-----------------------------------------------------------------
cblock 0x20
ADC_value_lo
ADC_value_hi
endc
;------------------------------------------------------------------
;initialisation
;------------------------------------------------------------------
org 0
banksel ANSEL
movlw 11h ;AN0 as analog input,conversion clock Fosc/8
movwf ANSEL
bankseL CMCON
movlw 07h ;comparators off
movwf CMCON
movlw 0x81 ;ADC on, right justified
movwf ADCON0
banksel TRISIO
movlw 0x0F ;LED output GPIO5 (pin 2), AN0 input GPIO0 (pin 7) 00001111
movwf TRISIO
;-----------------------------------------------------------------------
;main program loop
;-----------------------------------------------------------------------
loop:
call read_ADC ;read ADC
banksel GPIO
cjalwd ADC_value_hi,HIGH UPPER_LIMIT,LOW UPPER_LIMIT,LED_off ;compare ADC value with upper limit
cjalwd ADC_value_hi,HIGH LOWER_LIMIT,LOW LOWER_LIMIT,LED_on ;compare ADC value with lower limit
LED_off:
bsf GPIO,LED ;LED off
goto loop
LED_on:
bcf GPIO,LED ;LED on
goto loop
;---------------------------------------------------------------------
;read_ADC
;function to read ADC
;returns high and low bytes (10 bits) in ADC_value_hi
;and ADC_value_lo variables. Value is right-justified.
;---------------------------------------------------------------------
read_ADC:
banksel ADCON0
bsf ADCON0,1 ;start conversion
WaitADC:
btfss PIR1,ADIF
goto WaitADC ;wait for ADC to finish
GetADC1:
movf ADRESH, W ;get high byte
movwf ADC_value_hi
banksel ADRESL
movf ADRESL, W ;get low byte
movwf ADC_value_lo
banksel PIR1
bcf PIR1,ADIF ;clear conversion flag
return
;----------------------------------------------------------------------
end