delisakir6
Üye
- Katılım
- 3 Haz 2018
- Mesajlar
- 1
- Puanları
- 1
- Yaş
- 30
Merhaba arkadaşlar ben 7 segment kullanarak 10 dakikalık (9.59.9) kronometre yapmaya çalışıyorum.
PIC16F84A
4mhz kristal
Ortak anode 7segment
kullandım.
Kodu protues isisde simule etmeyi denedim çalısmadı. Resmine bakabilirsiniz.
Kesme devresinde hata olabileceğini düşünüyorum.Bir göz atabilirmisiniz ?
list p=16f84a ;
#include <p16f84a.inc> ;
ERRORLEVEL -302
__CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC
w_copy Equ 0x20 ; w kurtarma
s_copy Equ 0x21 ; status register kurtarma
basamak1 Equ 0x22 ; en kücük basamak
basamak2 Equ 0x23 ;
basamak3 Equ 0x24 ;
basamak4 Equ 0x25 ; en büyük basamak
Digit Equ 0x26 ; basamak sayaci
ar Equ 0x27
Timer2 Equ 0x28 ; prescalar 50hz>10hz
;**************************************************************
;
org 0
goto Init
;**************************************************************
; kesme
org 4
intvec
bcf INTCON, GIE ;kesmeyi kapat
movwf w_copy ; w kurtat
swapf STATUS, w ; STATUS kurtar
movwf s_copy ;
movlw D'131' ; 256-125=131 ((1MHz : 32 ): 125 = 250 Hz)
movwf TMR0
; Intrupt servic routine
Int_serv
bcf PORTA, 0 ; basamak1 kapali
bcf PORTA, 1 ; basamak2 kapali
bcf PORTA, 2 ; basamak3 kapali
bcf PORTA, 3 ; basamak4 kapali
decf Digit,f ; basamak sayacini azalt
;Digit=4: basamak 4 u goster
;Digit=3: basamak 3 u goster
;Digit=2: basamak 2 u goster
;Digit=1: basamak 1 u goster
;Digit=0: islem yok
btfsc STATUS, Z
goto Int_0 ; Z-Flag=1 Digit=0
movfw Digit
movwf ar
decf ar, f
btfsc STATUS, Z
goto Int_1 ; Digit=1
decf ar, f
btfsc STATUS, Z
goto Int_2 ; Digit=2
decf ar, f
btfsc STATUS, Z
goto Int_3 ; Digit=3
goto Int_4 ; Digit=4
Int_0
movlw 5
movwf Digit
btfss PORTA, 4
goto Int_end ; Stop-butonuna basildi
decf Timer2, f ; 5 den 0 a sayma (50 Hz / 5 = 10 Hz)
btfss STATUS, Z
goto Int_end ; Timer2 <> 0
movlw 5
movwf Timer2
incf basamak1, f ; 1/10 saniye artir
movlw D'10'
subwf basamak1, w
btfss STATUS, Z
goto Int_end ; 1/10 saniye <> 10
clrf basamak1
incf basamak2, f ; 1 saniye artir
movlw D'10'
subwf basamak2, w
btfss STATUS, Z
goto Int_end ; 1 Sekunden <> 10
clrf basamak2
incf basamak3, f ; 10 saniye artir
movlw D'6'
subwf basamak3, w
btfss STATUS, Z
goto Int_end ; 10 saniye <> 6
clrf basamak3
incf basamak4, f ; 1 dakika artir
movlw D'10'
subwf basamak4, w
btfss STATUS, Z
goto Int_end ; 1 dakika <> 10
clrf basamak4
goto Int_end
Int_1
movfw basamak1 ; birinci basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 0 ; 1. basamak yansin
goto Int_end
Int_2
movfw basamak2 ; ikinci basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 1 ; 2. basamak yansin
goto Int_end
Int_3
movfw basamak3 ; ucuncu basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 2 ; 3. basamak yansin
goto Int_end
Int_4
movfw basamak4 ; 4. basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 3 ; 4. basamak yansin
goto Int_end
Int_end swapf s_copy, w ;
movwf STATUS
swapf w_copy, f ;
swapf w_copy, w
bcf INTCON, T0IF ;
bsf INTCON, GIE ;
retfie
; 7-Segment-Tablosu
Segment
addwf PCL, f
retlw B'11100111' ; 0
retlw B'00100001' ; 1
retlw B'11001101' ; 2
retlw B'10101101' ; 3
retlw B'00101011' ; 4
retlw B'10101110' ; 5
retlw B'11101110' ; 6
retlw B'00100101' ; 7
retlw B'11101111' ; 8
retlw B'10101111' ; 9
;**************************************************************
; Port A/B giris cikislar
Init
movlw B'00000000'
movwf PORTA
movwf PORTB ;
bsf STATUS, RP0 ;
movlw B'11110000' ; PortA RA0-RA3 cikis
movwf TRISA
movlw B'00000000' ; PortB cikis
movwf TRISB
bcf STATUS, RP0 ;
; zaman 0 dan baslasin
clrf basamak1
clrf basamak2
clrf basamak3
clrf basamak4
movlw 5
movwf Digit ; basamak sayaci
; 250 Hz-Timer-Kesme
bsf STATUS, RP0 ;
movlw B'10000100' ; 32:1
movwf OPTION_REG
movlw D'131' ; 256-125=131 ((1MHz : 32 ): 125 = 250 Hz)
bcf STATUS, RP0 ;
movwf TMR0
movlw 5
movwf Timer2 ;
bsf INTCON, T0IE ;
bsf INTCON, GIE ;
loop
goto loop ;
;**********************************************************
end
PIC16F84A
4mhz kristal
Ortak anode 7segment
kullandım.
Kodu protues isisde simule etmeyi denedim çalısmadı. Resmine bakabilirsiniz.
Kesme devresinde hata olabileceğini düşünüyorum.Bir göz atabilirmisiniz ?
list p=16f84a ;
#include <p16f84a.inc> ;
ERRORLEVEL -302
__CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC
w_copy Equ 0x20 ; w kurtarma
s_copy Equ 0x21 ; status register kurtarma
basamak1 Equ 0x22 ; en kücük basamak
basamak2 Equ 0x23 ;
basamak3 Equ 0x24 ;
basamak4 Equ 0x25 ; en büyük basamak
Digit Equ 0x26 ; basamak sayaci
ar Equ 0x27
Timer2 Equ 0x28 ; prescalar 50hz>10hz
;**************************************************************
;
org 0
goto Init
;**************************************************************
; kesme
org 4
intvec
bcf INTCON, GIE ;kesmeyi kapat
movwf w_copy ; w kurtat
swapf STATUS, w ; STATUS kurtar
movwf s_copy ;
movlw D'131' ; 256-125=131 ((1MHz : 32 ): 125 = 250 Hz)
movwf TMR0
; Intrupt servic routine
Int_serv
bcf PORTA, 0 ; basamak1 kapali
bcf PORTA, 1 ; basamak2 kapali
bcf PORTA, 2 ; basamak3 kapali
bcf PORTA, 3 ; basamak4 kapali
decf Digit,f ; basamak sayacini azalt
;Digit=4: basamak 4 u goster
;Digit=3: basamak 3 u goster
;Digit=2: basamak 2 u goster
;Digit=1: basamak 1 u goster
;Digit=0: islem yok
btfsc STATUS, Z
goto Int_0 ; Z-Flag=1 Digit=0
movfw Digit
movwf ar
decf ar, f
btfsc STATUS, Z
goto Int_1 ; Digit=1
decf ar, f
btfsc STATUS, Z
goto Int_2 ; Digit=2
decf ar, f
btfsc STATUS, Z
goto Int_3 ; Digit=3
goto Int_4 ; Digit=4
Int_0
movlw 5
movwf Digit
btfss PORTA, 4
goto Int_end ; Stop-butonuna basildi
decf Timer2, f ; 5 den 0 a sayma (50 Hz / 5 = 10 Hz)
btfss STATUS, Z
goto Int_end ; Timer2 <> 0
movlw 5
movwf Timer2
incf basamak1, f ; 1/10 saniye artir
movlw D'10'
subwf basamak1, w
btfss STATUS, Z
goto Int_end ; 1/10 saniye <> 10
clrf basamak1
incf basamak2, f ; 1 saniye artir
movlw D'10'
subwf basamak2, w
btfss STATUS, Z
goto Int_end ; 1 Sekunden <> 10
clrf basamak2
incf basamak3, f ; 10 saniye artir
movlw D'6'
subwf basamak3, w
btfss STATUS, Z
goto Int_end ; 10 saniye <> 6
clrf basamak3
incf basamak4, f ; 1 dakika artir
movlw D'10'
subwf basamak4, w
btfss STATUS, Z
goto Int_end ; 1 dakika <> 10
clrf basamak4
goto Int_end
Int_1
movfw basamak1 ; birinci basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 0 ; 1. basamak yansin
goto Int_end
Int_2
movfw basamak2 ; ikinci basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 1 ; 2. basamak yansin
goto Int_end
Int_3
movfw basamak3 ; ucuncu basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 2 ; 3. basamak yansin
goto Int_end
Int_4
movfw basamak4 ; 4. basamak degeri
call Segment
movwf PORTB ;
bsf PORTA, 3 ; 4. basamak yansin
goto Int_end
Int_end swapf s_copy, w ;
movwf STATUS
swapf w_copy, f ;
swapf w_copy, w
bcf INTCON, T0IF ;
bsf INTCON, GIE ;
retfie
; 7-Segment-Tablosu
Segment
addwf PCL, f
retlw B'11100111' ; 0
retlw B'00100001' ; 1
retlw B'11001101' ; 2
retlw B'10101101' ; 3
retlw B'00101011' ; 4
retlw B'10101110' ; 5
retlw B'11101110' ; 6
retlw B'00100101' ; 7
retlw B'11101111' ; 8
retlw B'10101111' ; 9
;**************************************************************
; Port A/B giris cikislar
Init
movlw B'00000000'
movwf PORTA
movwf PORTB ;
bsf STATUS, RP0 ;
movlw B'11110000' ; PortA RA0-RA3 cikis
movwf TRISA
movlw B'00000000' ; PortB cikis
movwf TRISB
bcf STATUS, RP0 ;
; zaman 0 dan baslasin
clrf basamak1
clrf basamak2
clrf basamak3
clrf basamak4
movlw 5
movwf Digit ; basamak sayaci
; 250 Hz-Timer-Kesme
bsf STATUS, RP0 ;
movlw B'10000100' ; 32:1
movwf OPTION_REG
movlw D'131' ; 256-125=131 ((1MHz : 32 ): 125 = 250 Hz)
bcf STATUS, RP0 ;
movwf TMR0
movlw 5
movwf Timer2 ;
bsf INTCON, T0IE ;
bsf INTCON, GIE ;
loop
goto loop ;
;**********************************************************
end