mgokce
Üye
- Katılım
- 7 Kas 2009
- Mesajlar
- 88
- Puanları
- 1
- Yaş
- 36
bu programda hatayı bulamadım yardımcı olunursa sevinirim...
list p=16f84, f=inhx8m,
INCLUDE P16f84.INC
;************************************************* *************************
; Defining: variables in RAM memory
;************************************************* *************************
include d:\pic\dim\dimprom.asm
;************************************************* *************************
; Program code
;************************************************* *************************
#define STISAK_KASNJENJE .50
#define VREDNOST_MAX .200
#define VREDNOST_MIN .4
ORG 0000h ; Reset vector.
Init bcf INTCON,GIE ; hardware initialization
clrf STATUS ; turn off interapt
clrf PORTB ;
goto InitNext ;
ORG 0004h ; Interrupt vector.
goto Main_init
;************************************************* *************************
; Main program
;************************************************* *************************
Main_init
movlw 0x03
movwf PORTB
movlw VREDNOST_MAX
movwf Vrednost
movlw 0xff
movwf Smer
;test call Tastaturamain
; goto test
Main_prvi
call Tastaturamain
btfss PORTA,1 ; waiting for histerezis
goto Main_prvi
;initialization of first half-period
bcf PORTB,1
clrf TMR0
Prvapetlja
btfss PORTA,1 ; check + half-periode
goto Main_drugi
movf Vrednost,W
subwf TMR0,W
btfss STATUS,C ; is TMR0-Vrednpost <0 ?
goto Prvapetlja
;turn on - PALI
bsf PORTB,1
call Ukljuci
Prvpetcekaj
btfsc PORTA,1
goto Prvpetcekaj ; + period is still going
bcf PORTB,1
Main_drugi
call Tastaturamain
btfsc PORTA,2
goto Main_drugi
;inicijalization of second half-periode
bcf PORTB,1
clrf TMR0
Drugapetlja
btfsc PORTA,2
goto Main_prvi
movf Vrednost,W
subwf TMR0,W
btfss STATUS,C
goto Drugapetlja
;turn on
bsf PORTB,1
call Ukljuci
Drugapetljacekaj
btfss PORTA,2
goto Drugapetljacekaj
bcf PORTB,1
goto Main_prvi
Ukljuci
;software compensation starts here
movlw .150
subwf Vrednost,W ;compensation of histerezis
btfsc STATUS,C
return
;software compensation ends here, this 4 lines can be removed
movlw b'00001111'
movwf PORTB
movlw b'00000000'
bsf STATUS,RP0
movwf TRISB
bcf STATUS,RP0
nop
nop
nop
nop
nop
nop
nop
movlw b'00000001'
bsf STATUS,RP0
movwf TRISB
bcf STATUS,RP0
return
;************************************************* *************************
;
; sub-program for taster switch
;
;
;************************************************* *************************
Tastaturamain
movf PORTA,W
andlw b'00000001' ;filter for zero bit
movwf Sad ;puts in Sad and after that puts in Pre
andwf Pre,W ;this is for taster switch debounsing
movwf Stanje ;
movf Sad,W
movwf Pre ;if two succesive reading of RA0 are logical 1
btfss Juce,0 ;taster-switch is pushed, then variable Stanje gets
goto Tastkraj ;value 1;
btfss Stanje,0
goto Tastprekinutpritisak ;check push button is released
;The new and previous reading of pushbutton switch are 1, pushbutton is pressed
movlw STISAK_KASNJENJE
subwf Stisak,W ;pushbutton is not released
btfss STATUS,C ;checks how long it was keept pushed
goto Tastparanput ;even and odd, to slow down counting
;light on
decf Stisak,F
movlw 0xff
xorwf Speedcontrol,F
movf Speedcontrol,F
btfss STATUS,Z
goto Tastparanput
;odd pass, only for slow down
btfss Smer,0 ;check the positive direction
goto Tastnegativansmer ;negative direction
;positive direction
movlw VREDNOST_MAX
subwf Vrednost,W
btfss STATUS,Z
goto Tastnijemaxdim
;count off, change direction
clrf Smer
decf Vrednost,F
Tastnijemaxdim
incf Vrednost,F
Tastparanput
incf Stisak,F
Tastkraj
movf Stanje,W
movwf Juce
Tastend
return
Tastnegativansmer
movlw VREDNOST_MIN
subwf Vrednost,W
btfss STATUS,Z
goto Tastnegativansmerkraj
movlw 0xff ;change direction in case of count off
movwf Smer
incf Vrednost,F
;negative direction,
Tastnegativansmerkraj
decf Vrednost,F
goto Tastparanput
Tastprekinutpritisak
movlw STISAK_KASNJENJE ;taster is released, check time to pass
subwf Stisak,W ;keeping taster switch pressed
btfsc STATUS,Z ;
goto Tastprekinutpritisakpreskok
movlw VREDNOST_MIN
movwf Vrednost
btfsc Smer,0
goto Tastprekinutpritisakpreskok
movlw VREDNOST_MAX
movwf Vrednost
Tastprekinutpritisakpreskok
movlw 0xff
xorwf Smer,F
clrf Stisak
goto Tastkraj
;************************************************* *************************
; initialization
;************************************************* *************************
InitNext clrf PORTA ;
bsf STATUS,RP0 ;
movlw b'00000001' ; RB1-RB7,are outputs, RB0 input
movwf TRISB ;
movlw b'00011111' ; RA0-RA4 are inputs.
movwf TRISA
movlw b'10000101' ; Configure OPTION register
movwf OPTION_REG ;
bcf STATUS,RP0 ;
clrf TMR0 ; TMR0 = 0.
movlw b'00000000' ; Configure INTCON register
movwf INTCON ; 7-GIE, 6-EEIE, 5-T0IE, 4-INTE
; 3-RBIE, 2-TOIF, 1-INTF, RBIF
movlw 0ch ;
movwf FSR ; clear RAM
MoreMem clrf INDF ;
incf FSR,F ;
movlw 4fh ;
xorwf FSR,W
btfss STATUS,Z
goto MoreMem
goto Main_init ;
;
END
list p=16f84, f=inhx8m,
INCLUDE P16f84.INC
;************************************************* *************************
; Defining: variables in RAM memory
;************************************************* *************************
include d:\pic\dim\dimprom.asm
;************************************************* *************************
; Program code
;************************************************* *************************
#define STISAK_KASNJENJE .50
#define VREDNOST_MAX .200
#define VREDNOST_MIN .4
ORG 0000h ; Reset vector.
Init bcf INTCON,GIE ; hardware initialization
clrf STATUS ; turn off interapt
clrf PORTB ;
goto InitNext ;
ORG 0004h ; Interrupt vector.
goto Main_init
;************************************************* *************************
; Main program
;************************************************* *************************
Main_init
movlw 0x03
movwf PORTB
movlw VREDNOST_MAX
movwf Vrednost
movlw 0xff
movwf Smer
;test call Tastaturamain
; goto test
Main_prvi
call Tastaturamain
btfss PORTA,1 ; waiting for histerezis
goto Main_prvi
;initialization of first half-period
bcf PORTB,1
clrf TMR0
Prvapetlja
btfss PORTA,1 ; check + half-periode
goto Main_drugi
movf Vrednost,W
subwf TMR0,W
btfss STATUS,C ; is TMR0-Vrednpost <0 ?
goto Prvapetlja
;turn on - PALI
bsf PORTB,1
call Ukljuci
Prvpetcekaj
btfsc PORTA,1
goto Prvpetcekaj ; + period is still going
bcf PORTB,1
Main_drugi
call Tastaturamain
btfsc PORTA,2
goto Main_drugi
;inicijalization of second half-periode
bcf PORTB,1
clrf TMR0
Drugapetlja
btfsc PORTA,2
goto Main_prvi
movf Vrednost,W
subwf TMR0,W
btfss STATUS,C
goto Drugapetlja
;turn on
bsf PORTB,1
call Ukljuci
Drugapetljacekaj
btfss PORTA,2
goto Drugapetljacekaj
bcf PORTB,1
goto Main_prvi
Ukljuci
;software compensation starts here
movlw .150
subwf Vrednost,W ;compensation of histerezis
btfsc STATUS,C
return
;software compensation ends here, this 4 lines can be removed
movlw b'00001111'
movwf PORTB
movlw b'00000000'
bsf STATUS,RP0
movwf TRISB
bcf STATUS,RP0
nop
nop
nop
nop
nop
nop
nop
movlw b'00000001'
bsf STATUS,RP0
movwf TRISB
bcf STATUS,RP0
return
;************************************************* *************************
;
; sub-program for taster switch
;
;
;************************************************* *************************
Tastaturamain
movf PORTA,W
andlw b'00000001' ;filter for zero bit
movwf Sad ;puts in Sad and after that puts in Pre
andwf Pre,W ;this is for taster switch debounsing
movwf Stanje ;
movf Sad,W
movwf Pre ;if two succesive reading of RA0 are logical 1
btfss Juce,0 ;taster-switch is pushed, then variable Stanje gets
goto Tastkraj ;value 1;
btfss Stanje,0
goto Tastprekinutpritisak ;check push button is released
;The new and previous reading of pushbutton switch are 1, pushbutton is pressed
movlw STISAK_KASNJENJE
subwf Stisak,W ;pushbutton is not released
btfss STATUS,C ;checks how long it was keept pushed
goto Tastparanput ;even and odd, to slow down counting
;light on
decf Stisak,F
movlw 0xff
xorwf Speedcontrol,F
movf Speedcontrol,F
btfss STATUS,Z
goto Tastparanput
;odd pass, only for slow down
btfss Smer,0 ;check the positive direction
goto Tastnegativansmer ;negative direction
;positive direction
movlw VREDNOST_MAX
subwf Vrednost,W
btfss STATUS,Z
goto Tastnijemaxdim
;count off, change direction
clrf Smer
decf Vrednost,F
Tastnijemaxdim
incf Vrednost,F
Tastparanput
incf Stisak,F
Tastkraj
movf Stanje,W
movwf Juce
Tastend
return
Tastnegativansmer
movlw VREDNOST_MIN
subwf Vrednost,W
btfss STATUS,Z
goto Tastnegativansmerkraj
movlw 0xff ;change direction in case of count off
movwf Smer
incf Vrednost,F
;negative direction,
Tastnegativansmerkraj
decf Vrednost,F
goto Tastparanput
Tastprekinutpritisak
movlw STISAK_KASNJENJE ;taster is released, check time to pass
subwf Stisak,W ;keeping taster switch pressed
btfsc STATUS,Z ;
goto Tastprekinutpritisakpreskok
movlw VREDNOST_MIN
movwf Vrednost
btfsc Smer,0
goto Tastprekinutpritisakpreskok
movlw VREDNOST_MAX
movwf Vrednost
Tastprekinutpritisakpreskok
movlw 0xff
xorwf Smer,F
clrf Stisak
goto Tastkraj
;************************************************* *************************
; initialization
;************************************************* *************************
InitNext clrf PORTA ;
bsf STATUS,RP0 ;
movlw b'00000001' ; RB1-RB7,are outputs, RB0 input
movwf TRISB ;
movlw b'00011111' ; RA0-RA4 are inputs.
movwf TRISA
movlw b'10000101' ; Configure OPTION register
movwf OPTION_REG ;
bcf STATUS,RP0 ;
clrf TMR0 ; TMR0 = 0.
movlw b'00000000' ; Configure INTCON register
movwf INTCON ; 7-GIE, 6-EEIE, 5-T0IE, 4-INTE
; 3-RBIE, 2-TOIF, 1-INTF, RBIF
movlw 0ch ;
movwf FSR ; clear RAM
MoreMem clrf INDF ;
incf FSR,F ;
movlw 4fh ;
xorwf FSR,W
btfss STATUS,Z
goto MoreMem
goto Main_init ;
;
END