Code:
#include P16f88.INC
;*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
TRISB equ 86h
PORTB equ 06h
OSCCON equ 8Fh
COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops
SPEICHER equ 22h
;****Set up the port****
call Delay
bsf STATUS,RP0 ;Switch to Bank 1
movlw 11h ;Set the Port A pins
movwf TRISA
movlw 01h ;Set the Port B pins
movwf TRISB
movlw 2Eh ;Taktfrequenz setzen
movwf OSCCON
bcf STATUS,RP0 ;Switch back to Bank 0
movlw 00h ;
movwf PORTA
movlw 00h
movwf PORTB
; ADC einschalten
BSF ADCON0, 0 ; ADON=1
; ADC-Eingang AN0 auswählen
BCF ADCON0, 5 ; ADCHS2=0
BCF ADCON0, 4 ; ADCHS1=0
BCF ADCON0, 3 ; ADCHS0=0
; ADC speed für 1 MHz einstellen
BSF ADCON0, 7 ; ADCS1=1
BCF ADCON0, 6 ; ADCS0=0
; Daten rechtsbündig
BSF STATUS,RP0 ; Bank1
BSF ADCON1, 7 ; ADFM=1
BCF STATUS,RP0 ; Bank0
;___________________________________________________________________________
;****Turn the 1st LED on****
Start
call Delay
clrwdt
clrf PORTA
clrf PORTB
bcf STATUS,0 ; Status,0 auf null setzten
;Eingangsspannung wandeln
BSF ADCON0, 2 ; ADC starten
loop
BTFSC ADCON0, 2 ; ist der ADC fertig?
GOTO loop ; nein, weiter warten
; Wert nach W schreiben
BSF STATUS,RP0 ; Bank1
movfw ADRESL ; untere 8 Bit auslesen
BCF STATUS,RP0 ; Bank0
; Erste Überprüfung
SUBWF 15h,0 ;von w 15 abziehen und wieder in w schreiben
movwf SPEICHER ;wieder in den Speicher schreiben
movlw 04h ; LED 1 an
movwf PORTA
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
; Zweite Überprüfung
movlw SPEICHER
SUBWF 17h,0 ;von w 17 abziehen und wieder in w schreiben
movwf SPEICHER
movlw 08h ; LED 2 an
movwf PORTA
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
; Dritte Überprüfung
movlw SPEICHER
SUBWF 16h,0 ;von w 16 abziehen und wieder in w schreiben
movwf SPEICHER
movlw 02h ; LED 3 an
movwf PORTB
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
; Vierte Überprüfung
movlw SPEICHER
SUBWF 16h,0 ;von w 16 abziehen und wieder in w schreiben
movwf SPEICHER
movlw 04h ; LED 4 an
movwf PORTB
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
; Fünfte Überprüfung
movlw SPEICHER
SUBWF 15h,0 ;von w 15 abziehen und wieder in w schreiben
movwf SPEICHER
movlw 10h ; LED5 an
movwf PORTB
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
; Sechste Überprüfung
movlw SPEICHER
SUBWF 16h,0 ;von w 16 abziehen und wieder in w schreiben
movwf SPEICHER
movlw 20h ; LED 5 an
movwf PORTB
BTFSs STATUS,0 ;wenn STATUS,0=1 , dann übersprigen
goto Start
goto Start ;go back to Start and turn LEDs on again
;****Here is our Subroutine
Delay
movlw 230
movwf COUNT1 ;Load count1 with init value
movlw 10
movwf COUNT2 ;Load count2 with init value
Loop1 decfsz COUNT1,f ;This second loop keeps the LEDs
goto Loop1 ;turned off long enough for us to
decfsz COUNT2,f ;see it turned off
goto Loop1 ;
return
;****End of the program****
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
Lesezeichen