Bu asm kodlarını deneyebilirsin:
PROCESSOR 16F84
INCLUDE P16F84.INC
RADIX DEC
__IDLOCS H'0100'
__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
; Diverses
ZERO EQU Z ; ZERO-Flag
CARRY EQU C ; CARRY-Flag
; Variable
S0 = 12 ; located in Bank 0, 1
BEKLE = 13 ; located in Bank 0, 1
BEKLE_HI = 14 ; located in Bank 0, 1
SYS_WSAV = 15 ; located in Bank 0, 1
SYS_SSAV = 16 ; located in Bank 0, 1
LED_ZAMANI = 17 ; located in Bank 0, 1
LED_ZAMANI_HI = 18 ; located in Bank 0, 1
RAM = 19 ; located in Bank 0, 1
ERRORLEVEL -302 ; disable warning (Bankswitching)
ERRORLEVEL -306 ; disable warning (Pageswitching)
;****************************************
;Programmanfang
;****************************************
ORG 0
CLRF STATUS ; switch to RAM-Bank 0
GOTO SYS_INIT
NOP
NOP
;****************************************
;Interrupt-Adress
;****************************************
MOVWF SYS_WSAV ; save register
SWAPF STATUS,W
CLRF STATUS ; bank 0
MOVWF SYS_SSAV
BCF INTCON,T0IF ; Interrupt quitieren
INCFSZ BEKLE,F
GOTO SYS_INT_LABEL_0
INCF BEKLE_HI,F
SYS_INT_LABEL_0
INCFSZ LED_ZAMANI,F
GOTO SYS_INT_LABEL_1
INCF LED_ZAMANI_HI,F
SYS_INT_LABEL_1
EXITINT
SWAPF SYS_SSAV,W ; Register zurück
MOVWF STATUS
SWAPF SYS_WSAV,F
SWAPF SYS_WSAV,W
RETFIE
;****************************************
; Subroutines
;****************************************
;****************************************
;Initialisierung
;****************************************
SYS_INIT
MOVLW B'00100000'
MOVWF INTCON
; Set output before direction
BCF STATUS,RP0 ; Bank 0
MOVLW B'00000000'
MOVWF PORTA
MOVLW B'00000000'
MOVWF PORTB
MOVLW 15
BSF STATUS,RP0 ; Bank 1
MOVWF OPTION_REG
; Richtung setzen
MOVLW B'11111111'
MOVWF TRISA
MOVLW B'11111101'
MOVWF TRISB
; init vars
; Clear RAM
MOVLW 12
MOVWF FSR
CR1
CLRF INDF
INCF FSR,F
MOVFW FSR
SUBLW 80
BTFSS STATUS,ZERO
GOTO CR1
BCF STATUS,RP0 ; Bank 0
CLRF TMR0
BCF INTCON,T0IF
BSF INTCON,GIE ; Interrupt freigeben
;**********************************
;******* Haupt-Programm ***********
;**********************************
MAIN
;***************************************************
; UND - Gatter -> BUTON
;***************************************************
LABEL_BUTON_1
BCF STATUS,RP0 ; Bank 0
BTFSS PORTA,1
GOTO LABEL_BUTON_FALSE
LABEL_BUTON_TRUE
BSF S0,0
GOTO LABEL_BUTON_ENDE
LABEL_BUTON_FALSE
BCF S0,0
LABEL_BUTON_ENDE
;***************************************************
; Anzug-Verzögerung -> BEKLE
;***************************************************
BTFSC S0,0 ; Eingang auf High ?
GOTO LABEL_BEKLE_CHKTIME ; Ja
; RESET
CLRF BEKLE
CLRF BEKLE_HI
BCF S0,2
GOTO LABEL_BEKLE_EXIT ; raus
LABEL_BEKLE_CHKTIME
BTFSC S0,2 ; Ausgang schon auf High ?
GOTO LABEL_BEKLE_EXIT ; Ja
MOVLW 76
SUBWF BEKLE_HI,W
BTFSS STATUS,CARRY
GOTO LABEL_BEKLE_EXIT
MOVLW 75
SUBWF BEKLE,W
BTFSS STATUS,CARRY
GOTO LABEL_BEKLE_EXIT
BSF S0,2
LABEL_BEKLE_EXIT
;***************************************************
; Timer -> LED_ZAMANI
;***************************************************
MOVLW 7 ; Test auf >=
SUBWF LED_ZAMANI_HI,W ;F-W -> W
BTFSS STATUS,ZERO
GOTO LABEL_LED_ZAMANI_CHECK
MOVLW 161
SUBWF LED_ZAMANI,W ;F-W -> W
LABEL_LED_ZAMANI_CHECK
BTFSS STATUS,CARRY
GOTO LABEL_LED_ZAMANI_ENDE
LABEL_LED_ZAMANI_RESET
MOVLW 7 ; Test auf >=
SUBWF LED_ZAMANI_HI,F ;F-W -> F
MOVLW 161
SUBWF LED_ZAMANI,F ;F-W -> F
BTFSS STATUS,CARRY
DECF LED_ZAMANI_HI,F
LABEL_LED_ZAMANI_SET ; toggel output
BTFSC S0,1
GOTO LABEL_LED_ZAMANI_CLR
BSF S0,1
GOTO LABEL_LED_ZAMANI_ENDE
LABEL_LED_ZAMANI_CLR
BCF S0,1
LABEL_LED_ZAMANI_ENDE
;***************************************************
; UND - Gatter -> LED
;***************************************************
LABEL_LED_1
BTFSS S0,2
GOTO LABEL_LED_FALSE
LABEL_LED_2
BTFSS S0,1
GOTO LABEL_LED_FALSE
LABEL_LED_TRUE
BCF STATUS,RP0 ; Bank 0
BSF PORTB,1
GOTO LABEL_LED_ENDE
LABEL_LED_FALSE
BCF STATUS,RP0 ; Bank 0
BCF PORTB,1
LABEL_LED_ENDE
;****************************************
GOTO MAIN
END