Pic 16f690

Peltsi

#include

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)


RESULTHI      equ      20
RESULTLO      equ      22


BANKSEL ADCON1 ;
MOVLW B’01110000’ ;ADC Frc clock
MOVWF ADCON1 ;
BANKSEL TRISA ;
BSF TRISA,0 ;Set RA0 to input
BANKSEL ANSEL ;
BSF ANSEL,0 ;Set RA0 to analog
BANKSEL ADCON0 ;
MOVLW B’10000001’ ;Right justify,
MOVWF ADCON0 ; Vdd Vref, AN0, On
CALL SampleTime ;Acquisiton delay
BSF ADCON0,GO ;Start conversion
BTFSC ADCON0,GO ;Is conversion done?
GOTO $-1 ;No, test again
BANKSEL ADRESH ;
MOVF ADRESH,W ;Read upper 2 bits
MOVWF RESULTHI ;store in GPR space
BANKSEL ADRESL ;
MOVF ADRESL,W ;Read lower 8 bits
MOVWF RESULTLO ;Store in GPR space

3

1093

    Vastaukset

    Anonyymi (Kirjaudu / Rekisteröidy)
    5000
    • Peltsi

      Pyytäisin neuvoja joilla saisin analogia tulon toimimaan projektissani. Käsittääkseni alla olevan koodin jälkeen pinnissä RA0 vaikuttava jännite on jossain muodossa rekistereissä RESULTLO ja RESULTHI?

      Miten koodi etenee tästä, jos halutaan esim. yksinkertainen tieto, onko jännite yli vai alle 2.5 volttia?

      Mikäli jollakin on heittää esimerkki koodi, jossa analogiatulon mukaan valitaan seuraava aliohjelma, "olisi se enemmän kuin sata jänistä"






      #include

      __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)


      RESULTHI equ 20
      RESULTLO equ 22


      BANKSEL ADCON1 ;
      MOVLW B’01110000’ ;ADC Frc clock
      MOVWF ADCON1 ;
      BANKSEL TRISA ;
      BSF TRISA,0 ;Set RA0 to input
      BANKSEL ANSEL ;
      BSF ANSEL,0 ;Set RA0 to analog
      BANKSEL ADCON0 ;
      MOVLW B’10000001’ ;Right justify,
      MOVWF ADCON0 ; Vdd Vref, AN0, On
      CALL SampleTime ;Acquisiton delay
      BSF ADCON0,GO ;Start conversion
      BTFSC ADCON0,GO ;Is conversion done?
      GOTO $-1 ;No, test again
      BANKSEL ADRESH ;
      MOVF ADRESH,W ;Read upper 2 bits
      MOVWF RESULTHI ;store in GPR space
      BANKSEL ADRESL ;
      MOVF ADRESL,W ;Read lower 8 bits
      MOVWF RESULTLO ;Store in GPR space

      • Libra73

        Moi. Tuossa esimerkki. Tuo on demo levylle, mutta idea selvinnee.

        ; PICkit 2 Lesson 4 - "A2D"
        ;
        ; This shows how to read the A2D converter and display the
        ; High order parts on the 4 bit LED display.
        ; The pot on the Low Pin Count Demo board varies the voltage
        ; coming in on in A0.
        ;
        ; The A2D is referenced to the same Vdd as the device, which
        ; is provided by the USB cable and nominally is 5V. The A2D
        ; returns the ratio of the voltage on Pin RA0 to 5V. The A2D
        ; has a resolution of 10 bits, with 1023 representing 5V and
        ; 0 representing 0V.

        #include
           __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)

           cblock 0x20
        Delay1      ; Assign an address to label Delay1
        Delay2
        Display      ; define a variable to hold the diplay
           endc
              
           org 0
        Start
           bsf   STATUS,RP0   ; select Register Page 1
           movlw   0xFF
           movwf   TRISA      ; Make PortA all input
           clrf   TRISC      ; Make PortC all output
           movlw   0x10      ; A2D Clock Fosc/8
           movwf   ADCON1
           bcf   STATUS,RP0   ; back to Register Page 0

           bcf   STATUS,RP0   ; address Register Page 2
           bsf   STATUS,RP1   
           movlw   0xFF      ; we want all Port A pins Analoga
           movwf   ANSEL
           bcf   STATUS,RP0   ; address Register Page 0
           bcf   STATUS,RP1
           
           movlw   0x01
           movwf   ADCON0      ; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
        MainLoop
           nop         ; wait 5uS for A2D amp to settle and capacitor to charge.
           nop         ; wait 1uS
           nop         ; wait 1uS
           nop         ; wait 1uS
           nop         ; wait 1uS
           bsf   ADCON0,GO   ; start conversion
           btfss   ADCON0,GO   ; this bit will change to zero when the conversion is complete
           goto   $-1

           swapf   ADRESH,w   ; Copy the display to the LEDs
           movwf   PORTC
           goto   MainLoop
           end
           


      • mbomdwedp
        Libra73 kirjoitti:

        Moi. Tuossa esimerkki. Tuo on demo levylle, mutta idea selvinnee.

        ; PICkit 2 Lesson 4 - "A2D"
        ;
        ; This shows how to read the A2D converter and display the
        ; High order parts on the 4 bit LED display.
        ; The pot on the Low Pin Count Demo board varies the voltage
        ; coming in on in A0.
        ;
        ; The A2D is referenced to the same Vdd as the device, which
        ; is provided by the USB cable and nominally is 5V. The A2D
        ; returns the ratio of the voltage on Pin RA0 to 5V. The A2D
        ; has a resolution of 10 bits, with 1023 representing 5V and
        ; 0 representing 0V.

        #include
           __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)

           cblock 0x20
        Delay1      ; Assign an address to label Delay1
        Delay2
        Display      ; define a variable to hold the diplay
           endc
              
           org 0
        Start
           bsf   STATUS,RP0   ; select Register Page 1
           movlw   0xFF
           movwf   TRISA      ; Make PortA all input
           clrf   TRISC      ; Make PortC all output
           movlw   0x10      ; A2D Clock Fosc/8
           movwf   ADCON1
           bcf   STATUS,RP0   ; back to Register Page 0

           bcf   STATUS,RP0   ; address Register Page 2
           bsf   STATUS,RP1   
           movlw   0xFF      ; we want all Port A pins Analoga
           movwf   ANSEL
           bcf   STATUS,RP0   ; address Register Page 0
           bcf   STATUS,RP1
           
           movlw   0x01
           movwf   ADCON0      ; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
        MainLoop
           nop         ; wait 5uS for A2D amp to settle and capacitor to charge.
           nop         ; wait 1uS
           nop         ; wait 1uS
           nop         ; wait 1uS
           nop         ; wait 1uS
           bsf   ADCON0,GO   ; start conversion
           btfss   ADCON0,GO   ; this bit will change to zero when the conversion is complete
           goto   $-1

           swapf   ADRESH,w   ; Copy the display to the LEDs
           movwf   PORTC
           goto   MainLoop
           end
           

        CaSeZn mcxoflwkwggw, [url=http://odcgbfustbbd.com/]odcgbfustbbd[/url], [link=http://elyqgoaidliz.com/]elyqgoaidliz[/link], http://zpqnmlzakwtw.com/


    Ketjusta on poistettu 1 sääntöjenvastaista viestiä.

    Luetuimmat keskustelut

    1. Björn Wahlroos, maataloustuet lakkautettava

      Sanoo pankkimies. Mitäs persut ja muut tukinulliem perskärpäset tähän? "Wahlroos listaa kansallisen maataloustuen. – I
      Maailman menoa
      153
      3430
    2. Persut päättivät hiilivoiman kieltämisestä Suomessa

      Moni on jo unohanut kuka hyväksyi hiilivoimaloiden kieltämisen Suomessa: persut Sukupuolineutraalit liikennemerkitk
      Maailman menoa
      84
      2976
    3. Vain persut vastustivat hiilivoimaloiden alasajoa

      Persut vastusti jyrkästi hiilen kieltolakia ja on myöhemmin vaatinut hiilivoimaloiden pitämistä käytössä. He perusteliva
      Maailman menoa
      60
      2450
    4. Nalle Wahlroos ei ulise kuten Teemu Selänne sähkölaskuista

      Nalle "hah hah" nauroi saamistaan sähkötuista, kun taas Teemu-poika itkeä tirautti kovasta sähkön hinnasta. Nalle nauro
      Maailman menoa
      41
      2340
    5. Selvästi näyttää siltä, että SDP:n kannattajat hyväksyy kiusaamisen

      ja seksuaalisen ahdistelun, kun puolueen kannatus pysyy korkealla. Mitä tämä kertoo demari-äänestäjien moraalista?
      Maailman menoa
      53
      2260
    6. Muistattekos kuinka kokoomus ja persut vinkuivat sähkön hinnasta?

      Oppositiossa vuonna 2022, kun sähkön hinta uhkasi nousta 20 senttiin kilowattitunnilta? Nyt ovat hiiren hiljaa, kun pitä
      Maailman menoa
      115
      2235
    7. Kyllä nämä nyky autonakut ja autotki on heikloja

      Vuoden vanha akku, eikä inahdakaan.... Pistin vara-akun just lataukseen ja lähen sillä antamaan apuvirtaa Jos ei toimi,
      Ikävä
      17
      2217
    8. Mikä aate kaiken pahan takana?

      Se laiskistuttaa kansat, opettaa vaatimaan etuisuuksia, syleilee maailmoja eikä omaa kansaa.
      Maailman menoa
      151
      2149
    9. Muistan vuosikymmenten takaa

      Toivottavasti voit hyvin ja jaksat työssäsi. Olet upea ja erinomainen ihminen, toivon kaikkea hyvää.
      Ikävä
      12
      1566
    10. Päivi Räsäsen seksipaljastus loksauttaa Katja Ståhlin leuat! Elämäni biisi kohujakso tv:ssä!

      Elämäni biisi -suosikkisarjan uusinnat ovat startanneet ja nyt vuorossa on sarjan 2. jakso v. 2019. Sinisille sohville
      Suomalaiset julkkikset
      29
      1543
    Aihe