play with this one
Code:; --------------------------------------------------------------- ; ; Simple program which display ADC results of AN0 ; to 8 LED connected to PORTB<7:0> ; ; Enjoy! ; Steve AKA Mister_e ; ; --------------------------------------------------------------- list p=16f88, W=-302 ; bank switching INCLUDE "p16f88.inc" ; Program Configuration Register 1 CFG1 = _INTRC_IO & _MCLR_OFF & _BODEN_ON & _PWRTE_ON & _WDT_OFF & _LVP_OFF CFG2 = _DEBUG_OFF & _CP_OFF & _CCP1_RB0 & _WRT_PROTECT_OFF & _CPD_OFF __CONFIG _CONFIG1, CFG1 & CFG2 ; Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ORG 0 BANKSEL OSCCON MOVLW B'01100000' MOVWF OSCCON ; 4 MHz INT CLOCK MODE BTFSS OSCCON,IOFS ; wait 'till int osc is stable GOTO $-1 BANKSEL TRISA MOVLW .1 MOVWF TRISA ; porta.0 as input, other to output CLRF TRISB ; all pins set to output MOVLW .7 MOVWF CMCON ; disable analog comparator ; ; ADC setup ; --------- BANKSEL ANSEL MOVLW .1 MOVWF ANSEL ; Disable all ADCs but AN0 CLRF ADCON1 ; Left justified results ; ADCS2 : disabled ; Vref : Vdd, Vss BANKSEL ADCON0 MOVLW B'01000001' MOVWF ADCON0 ; ADCS : Fosc/8 ; select AN0 ; ADON = 1 ; ; Hardware initialisation ; ----------------------- CLRF PORTB ; Clear all CLRF PORTA ; outputs ; ; Program Start ; ------------- Start ; ; ADC Conversion ; -------------- MOVLW .12 ; ~12 uSec acquisition loop DECFSZ W,F ; GOTO $-1 ; BSF ADCON0, GO_DONE ; Start conversion BTFSC ADCON0, GO_DONE ; conversion finished? GOTO $-1 ; NO, wait again ; ; Display result ; -------------- MOVF ADRESH,W ; Move ADC result to Wreg MOVWF PORTB ; display it on PORTB GOTO Start END




Bookmarks