Hallo ich bin alex und brauche Hilfe
vorerst schon mal danke für Beiträge
Ich hab ein Programmm geschrieben wo ich den Analogeingang AN0 einlese
und die 10 Bit Zahl einfach an PORTD und POTE rechtlbündig ausgab.
Es hat super funktionier und nun möcht ich auswählen zwischen AD0 und
AD1.
Mit einem Schalter an PORTB am LSB (BIT 0) möcht ich entscheiden
welchen der Beiden Analogeingänge ich auswähle und dann an PORTD und E
ausgeben (sind LED's angeschlossen)
Das hier ist mein Programm (in ASM geschriebn)
es lässt sich builden und auch raufschreiben aber es macht nichts :(.
an AN0 und AN1 hab ich zwei POTIS. Das Poti ist an VDD angeschlossen.
Ich verwende den PIC18F452 und MPLAP mit PICkit 3 und meine Probeplatine
(Hardware Probelme gibt es sicher keine und der PIC funzt auch)
LIST P=18F452 ; directive to define processor
#include <P18F452.INC> ; processor specific variable definitions
CONFIG OSC = HS ; HS oscillator
CONFIG CP0 = OFF ; code protect disabled
CONFIG WDT = OFF ; Watch Dog Timer disabled
CONFIG LVP = OFF ; Single-Supply ICSP disabled
wait_reg EQU 0x20 ; holds starting value for waiting counter
ORG 0x0000 ; reset vector
GOTO init
init CLRF PORTD, 0
CLRF TRISD, 0 ; PORTD all outputs
CLRF PORTE, 0
SETF TRISE, 0
BCF TRISE, 0, 0
BCF TRISE, 1, 0 ; only RE0 and RE1 are outputs
CLRF PORTB, 0
BSF TRISB,0,0 ; only RB0 is input
CLRF ADCON1
MOVLW 0x84 ; VSS and VDD are reference voltages for ADC and...
MOVWF ADCON1,0 ; only AN0 (RA0) is analog
start BTFSC PORTB,0,0
GOTO init_AN1
GOTO init_AN0
init_AN0
CLRF ADCON0 ; select AN0 (RA0), ADC off (for now)
MOVLW 0x41
MOVWF ADCON0,0
BSF ADCON0,2,0 ; start operation
retry0 BTFSC ADCON0,2,0 ; poll for GO/DONE bit to be cleared
GOTO retry0 ; if not cleared, poll again
GOTO output
init_AN1
CLRF ADCON0 ; select AN0 (RA0), ADC off (for now)
MOVLW 0x49
MOVWF ADCON0,0
BSF ADCON0,2,0 ; start operation
retry1 BTFSC ADCON0,2,0 ; poll for GO/DONE bit to be cleared
GOTO retry1 ; if not cleared, poll again
GOTO output
output MOVFF ADRESH, PORTE ; Bits 9 and 8 of result to PORTE<1:0>
MOVFF ADRESL, PORTD ; Bits 7 to 0 of result to PORTD<7:0>
wait SETF wait_reg,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ wait_reg,0
GOTO wait
GOTO start
END
Für jene die sich den Code auf MPLAP ansehen würden hab ich dei
ASM-Datei als anhang hinzugefügt
Danke für Beiträge und Ideen
mgf
alex