PIC18F452 ile alive ledi yakmak

Forastero

Üye
Katılım
10 May 2007
Mesajlar
34
Puanları
1
Yaş
39
her iki saniyede bir Alive Ledi yakmak
Led devrede PORTD.0 bağlıdır

programı asm.file mplab ile yazılcak ve test edilcek mikro işlemcide

opsiyonel olarak bekleme zamanını 2snden 2dkkaya çıkabilmek için ne yapılması gerekir



;;;;;;; P1 for QwikFlash board ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 10 MHz Kristal Frekansı.
; Timer 0 10 ms lik taşmalar üretir.; Blink "Alive" LED 2 saniyede bir led i aktif et.

; D0 çıkışını her 10 ms de değille .
;
;;;;;;; Program akışı;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Mainline
; Initial
; BlinkAlive
; LoopTime
;
;;;;;;; Assembler configirasyonu;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

list P=PIC18F452, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, R=DEC, X=ON
#include P18F452.inc
__CONFIG _CONFIG1H, _HS_OSC_1H ;HS oscillator
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_42_2L ;Reset
__CONFIG _CONFIG2H, _WDT_OFF_2H ;Watchdog timer disabled
__CONFIG _CONFIG3H, _CCP2MX_ON_3H ;CCP2 to RC1 (rather than to RB3)
__CONFIG _CONFIG4L, _LVP_OFF_4L ;RB5 enabled for I/O

;;;;;;; Değişkenler;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

cblock 0x000 ; Beginning of Access RAM
TMR0LCOPY ;Copy of sixteen-bit Timer0 used by LoopTime
TMR0HCOPY
INTCONCOPY ;Copy of INTCON for LoopTime subroutine
ALIVECNT ;Counter for blinking "Alive" LED
endc

;;;;;;; Macro tanımı;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MOVLF macro literal,dest
movlw literal
movwf dest
endm

;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org 0x0300 ;Reset Vector
nop
goto Mainline

org 0x0308 ; Yüksek öncelikli interupt
goto $ ;Trap

org 0x0318 ;Low priority interrupt vector
goto $ ;Trap

;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Mainline

rcall Initial ; baslnagıç Değeritanımlarrcall ve callarasındaki fark
Loop ;Sonsuz döngü oluşturur
btg PORTD,0 ;Toggle pin, to support measuring loop time
rcall BlinkAlive ;Blink "Alive" LED aktive eder
rcall LoopTime ;looptime 10ms döngü oluşturur
bra Loop








;;;;;;;Başlangıç altprogram;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; saklayıcıyda değerlere getirilir

Initial

MOVLF B'00001110',TRISD ;Set I/O for PORTD
MOVLF B'10001000',T0CON ;Set up Timer0 for a looptime of 10 ms

return
;;;;;;; LoopTime subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine waits for Timer0 to complete its ten millisecond count
; sequence. It does so by waiting for sixteen-bit Timer0 to roll over. To obtain
; a period of precisely 10000/0.4 = 25000 clock periods, it needs to remove
; 65536-25000 or 40536 counts from the sixteen-bit count sequence. The
; algorithm below first copies Timer0 to RAM, adds "Bignum" to the copy ,and
; then writes the result back to Timer0. It actually needs to add somewhat more
; counts to Timer0 than 40536. The extra number of 12+2 counts added into
; "Bignum" makes the precise correction.

Bignum equ 65536-25000+12+2

LoopTime
btfss INTCON,TMR0IF ; 10 ms dolana kadar bekle
bra LoopTime
movff INTCON,INTCONCOPY ;Disable all interrupts to CPU
bcf INTCON,GIEH
movff TMR0L,TMR0LCOPY ;Read 16-bitlik sayıcıyı oku
movff TMR0H,TMR0HCOPYmovlw low Bignum ;10 ms lik taşma için TMR0 değerlerini yükler


addwf TMR0LCOPY,F
movlw high Bignum
addwfc TMR0HCOPY,F
movff TMR0HCOPY,TMR0H
movff TMR0LCOPY,TMR0L ;Timer 0 a yaz
movf INTCONCOPY,W ;Restore GIEH interrupt enable bit
andlw B'10000000'
iorwf INTCON,F ;taşmayı aktif et
bcf INTCON,TMR0IF ;Timer0 0 layıp işaretler
return



;;;;;;; BlinkAlive Altprogram;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 2sn de bir ledi yakar.



BlinkAlive
bsf PORTD,0 ;Led’i kapar
decf ALIVECNT,F ; Geciktirme oluşturan saklayıcı
bnz Baend ; eğer istenen değer ulaşılmamışsa devam eder.
MOVLF 200,ALIVECNT ;Reinitialize BLNKCNT
bcf PORTD,0 ; Her 2sn bir ledi yakar

biryer
rcall LoopTİme
decf ALIVECNT,F
bnz biryer
Baend
return

end


böyle bir program yazdımda mplab windows 7de atam anlamlı çalışmadığından ve proteus ile iletişim kurarken hata yaşadığından programı test edemiyorum yardımcı olabilcek olan varmıdır
 

Forum istatistikleri

Konular
128,163
Mesajlar
915,578
Kullanıcılar
449,922
Son üye
11akif

Yeni konular

Çevrimiçi üyeler

Geri
Üst