The Engineer
Waar rook is, is Roel. 5e jaars EE student @TU delft met een uit de hand gelopen buizenhobby!
ik heb van mijn laatste projectje nog een paar PIC18F2550 over.
daar wilde ik een ( zo klein mogelijk) klokje van maken. nu las ik in de datasheet dat er een "onboard RTC" op is te maken mbv Timer1.
http://ww1.microchip.com/downloads/en/DeviceDoc/39632b.pdf
zie pagina 135. dit is echter in MPASM en ik programmeer PICbasic.
hoe bouw ik dit fatsoenlijk om, want ik zie de variabelen er wel in zitten ( in neem aan dat die in PICBASIC ook zo gaan heten) en die kan ik er wel uit destilleren. het stukje code kun je op een manier gewoon in de PICbasic routine zetten, neem ik aan, daar was een functie voor geloof ik.
nu twee vragen: blijven de namen vann de variabelen gelijk, en waar in mijn code plaats ik de ASM lines? bovenaan of in de centrale loop?
Roel
Assembly gewoon op de plaats waar het nodig is, eventueel als subroutine. Of je schrijft het om naar Proton+, dan weet je precies wat het doet.
Registernamen blijven gelijk, die worden gemaakt aan de hand van de files van Mirochip zelf.
Stan1
Read the fuc.... manual and read the fuc.... datasheet! {Proton IDE: V2.0.1.2 / Proton Compiler: V3.5.4.5}
Het is wel te doen, maar lastig.
Volgens mij zit er alleen een fout in het eerste blok van die listing:
MOVLW 80h ; Preload TMR1 register pair
MOVWF TMR1H ; for 1 second overflow
CLRF TMR1L
MOVLW b’00001111’ ; Configure for external clock,
MOVWF T1OSC ; Asynchronous operation, external oscillator
CLRF secs ; Initialize timekeeping registers
CLRF mins ;
MOVLW d’12’
MOVWF hours
BSF PIE1, TMR1IE ; Enable Timer1 interrupt
RETURNVolgens mij moet:
MOVWF T1OSC ; Asynchronous operation, external oscillator
het volgende zijn:
MOVWF T1CON ; Asynchronous operation, external oscillator
Of heb ik het fout?
Wanneer je het eerste blok in picbasic zou doen, zou
dat er zo uit kunnen zien:
; SYMBOLS
Symbol TMR1IE = PIE1.0
Symbol TMR1IF = PIR1.0
;DIMS
Dim secs As Byte
Dim mins As Byte
Dim hours As Byte
RTCinit:
TMR1H = 128
TMR1L = 0
T1CON = %00001111
;T1CON bit 7 RD16 = 0 = Enables register read/write of Timer1 in two 8-bit operations
;T1CON bit 6 T1RUN = 0 = Device clock is derived from another source
;T1CON bit 5-4 = 00 = 1:1 Prescale value
;T1CON bit 3 T1OSCEN = 1 = Timer1 oscillator is enabled
;T1CON bit 2 T1SYNC = 1 = Do not synchronize external clock input
;T1CON bit 1 TMR1CS = 1 = External clock from pin RC0/T1OSO/T13CKI (on the rising edge)
;T1CON bit 0 TMR1ON = 1 = Enables Timer1
secs = 0
mins = 0
hours = 12
TMR1IE = 1 ; Enables the TMR1 overflow interrupt.
Return
Op 25 oktober 2011 22:18:24 schreef Stan1:
Volgens mij moet:MOVWF T1OSC ; Asynchronous operation, external oscillatorhet volgende zijn:
MOVWF T1CON ; Asynchronous operation, external oscillator
lijkt mij ook.
Stan1
Read the fuc.... manual and read the fuc.... datasheet! {Proton IDE: V2.0.1.2 / Proton Compiler: V3.5.4.5}
Nou vooruit, blokje 2 ook maar even dan!
RTCisr:
TMR1H = 7 ; Preload for 1 sec overflow
TMR1IF = 0 ; Clear interrupt flag
Inc Secs ; Increment seconds
If Secs <> 59 Then ; 60 seconds elapsed?
Return ; No, done
Else
Secs = 0 ; Clear seconds
Inc Mins ; Increment minutes
If Mins <> 59 Then ; 60 minutes elapsed?
Return ; No, done
Else
Mins = 0 ; clear minut
Inc Hours ; Increment hours
If Hours <> 23 Then ; 24 hours elapsed?
Return ; No, done
Else
Hours = 1 ; Reset hours to 1
EndIf
EndIf
EndIf
Alleen niet gecontroleerd, alleen van ASM naar Picbasic herschreven!