Digitalni sat sa M5451

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Za probu bi pokušao sa ovim kodom , jedino trebam razdvojiti destice i jedinice sat kao i minute desetice,jedinice da bi mogao pojedinačne brojeve konvertovati i poslati na displej.Samo još nisam
rješio kako to da uradim.

Code: Select all

Include "modedefs.bas"  ; Include shift modes
D1PIN Var PORTB.7       ; Shift data pin 1
C1PIN Var PORTB.6       ; Shift clock pin 1

Symbol Hrs_button = PORTB.0 ; Hour setting button
Symbol Mins_button = PORTB.1 ; Minute setting button
Ticks VAR byte ; Tick count (61 ticks = 1 sec)
Hour VAR byte ; Hour variable
Minute VAR byte ; Minute variable
Second VAR byte ; Second variable
Disp VAR byte ; Disp = 1 to update display
Delay VAR byte ; Used to Debounce button


TRISB = 3 ; RB0,RB1 are inputs
;
; Clear Hour, Minute, Second and Ticks to zero
;
Hour = 0
Minute = 0
Second = 0
Ticks = 0
;
OPTION_REG = $05 ; Set prescaler = 64
ON INTERRUPT GOTO ISR ; ISR routine
INTCON = $A0 ; Enable TMR0 interrupt and global interrupts
; LCDOUT $FE, 1 ; Clear LCD
;
; Beginning of MAIN program loop
;
LOOP:
;
; Check Hour button and if pressed increment variable Hour
;
IF Hrs_button = 0 THEN
Hour = Hour + 1
IF Hour = 24 THEN Hour = 0
Gosub Debounce
ENDIF
;
; Check Minute button and if pressed increment variable Minute
;
IF Mins_button = 0 THEN
Minute = Minute +1
IF Minute = 60 THEN Minute = 0
Gosub Debounce
ENDIF
;
; Display update section. The display is updated when variable
; Disp is 1. This variable is set to 1 inside the ISR when the
; seconds changes. The cursor is set to home position and the
; time is displayed on the LCD
;
IF Disp = 1 THEN
;LCDOUT $FE, 2
;LCDOUT DEC2 Hour, “:”,DEC2 Minute, “:”,DEC2 Second


Disp = 0
ENDIF
GOTO LOOP
;
; This subroutine Debounces the buttons. Also, a delay is introduced when
; a button is pressed so that the variable attached to the button (Hour or Second)
; can be incremented after a small delay.
;
Debounce:
FOR Delay = 1 To 200
Pause 1 ; Delay 1ms inside a loop. This way,
NEXT Delay ; timer interrupts are not stopped
Disp = 1 ; Set display flag to 1
RETURN
;
;
; Timer TMR0 interrupts are re-enabled just before the program exits this routine.
;
DISABLE
ISR:
Ticks = Ticks + 1
IF Ticks = 61 THEN NoUpdate
;
; 1 second has elapsed, now update seconds and if necessary minutes and hours
;
Ticks = 0
Second = Second + 1 ; Update second
IF Second = 60 THEN
Second = 0
Minute = Minute + 1 ; Update Minute
IF Minute = 60 THEN
Minute = 0
Hour = Hour + 1 ; Update Hour
IF Hour = 24 THEN
Hour = 0
ENDIF
ENDIF
ENDIF
Disp = 1 ; Set to update display
;
; End of time update
;
NoUpdate:
INTCON.2 = 0 ; Re-enable TMR0 interrupts
Resume
ENABLE ; Re-enable interrupts
END
END ; End of program
User avatar
bob4
Stariji član
Stariji član
Posts: 2572
Joined: 31-01-2010, 16:12
Location: Kutina

Re: Digitalni sat sa M5451

Post by bob4 »

Ja rješavam to u bascomu ovako:
Varijable su tipa byte.

Desetica = Broj/10
Pomocna = Desetica*10
Jedinica = Broj-Pomocna
User avatar
niho
Pravi forumaš
Pravi forumaš
Posts: 1895
Joined: 24-09-2009, 17:26
Location: Brcko, Bosnia and Herzegovina

Re: Digitalni sat sa M5451

Post by niho »

Zar nije lakše (ili bar ono školski :) )sa funkcijom MOD.

Code: Select all

desetice =INT(broj/10)
jedinice =broj MOD 10
User avatar
bob4
Stariji član
Stariji član
Posts: 2572
Joined: 31-01-2010, 16:12
Location: Kutina

Re: Digitalni sat sa M5451

Post by bob4 »

Slažem se. Može i tako
Desetica= Broj/10
Jedinica= Broj MOD 10
Hvala; i troši manje memorijskog prostora .
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: Digitalni sat sa M5451

Post by pedja089 »

A zar nije jos lakse:
desetice =broj dig 1
jedinice =broj dig 0
:D
Hteo sam njemu da ostavim to, nek cita sve, nace jos korisnih stvari, pa izmedju ostalog i ovo gore napisano...
User avatar
niho
Pravi forumaš
Pravi forumaš
Posts: 1895
Joined: 24-09-2009, 17:26
Location: Brcko, Bosnia and Herzegovina

Re: Digitalni sat sa M5451

Post by niho »

Naravno, cak ako se kako reče @Bob4 ako se varijable postave kao byte onda ne mora ići ni ovo INT, svejedno su cjelobrojne vrijednosti , može samo:

Code: Select all

desetice = Broj/10 
jedinice = Broj MOD 10
ili nekako ispravnije

Code: Select all

Desetice = Broj\10
Jedinice Broj MOD 10
Evo sad ima dosta za izbor, samo da ne bude po onoj staroj "nije mogao da se odluči.." :)
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Probat ću sve varijante , čim stignem .Uz ovoliki broj primjera mora da radi.
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: Digitalni sat sa M5451

Post by pedja089 »

INT nemas u PBP, mod je drugacija naredba.
User avatar
niho
Pravi forumaš
Pravi forumaš
Posts: 1895
Joined: 24-09-2009, 17:26
Location: Brcko, Bosnia and Herzegovina

Re: Digitalni sat sa M5451

Post by niho »

Pozdrav, Pedja, ko je govorio o PBP-u, :) nadovezao sam se na diskusiju od @BOB4.
Nema potrebe pisati int (iako ga ima u Bascomu) kad se već definiše varijabla kao byte ona automatski poprima cjelobrojne vrijednosti (integer).
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: Digitalni sat sa M5451

Post by pedja089 »

Ja sam govorio, i alpino005 je govorio... Pa je alpino005 rekao da ce probati sve varijante. Prva varijanta koju je Bob napisao, radi i u PBP. Pa ako proba i osale varijante sa INT i MOD u PBP pitace se sto ne radi.
Pa cisto da covek ne mora lupati glavu sto nesto ne radi, a prepisao je kako je napisano na forumu...
Samo sam zato to napomenuo... Nisam miliso nista lose... :)
User avatar
niho
Pravi forumaš
Pravi forumaš
Posts: 1895
Joined: 24-09-2009, 17:26
Location: Brcko, Bosnia and Herzegovina

Re: Digitalni sat sa M5451

Post by niho »

Pozdrav, ma nisam ni pomislio :D
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Evo kako sam to uradio , stim da postoji jedna greška jer minute prikazuje kao sekunde tj. broji do devet minuta u sekundama i prebaci desetice.Sad pokušavam otkriti gdje je problem.

Code: Select all

Include "modedefs.bas"  ; Include shift modes
D1PIN Var PORTB.7       ; Shift data pin 1
C1PIN Var PORTB.6       ; Shift clock pin 1
; clock code
input PORTA.0
input PORTA.1
Symbol Hrs_button = PORTA.0 ; Hour setting button
Symbol Mins_button = PORTA.1 ; Minute setting button
Ticks VAR byte ; Tick count (61 ticks = 1 sec)
Hour VAR byte ; Hour variable
Minute VAR byte ; Minute variable
Second VAR byte ; Second variable
Disp VAR byte ; Disp = 1 to update display
Delay VAR byte ; Used to Debounce button
dessat     VAR byte 
jedsat     VAR byte 
desmin     VAR byte 
jedmin     VAR byte 
poma       VAR byte 
pomb       VAR byte 
f1 VAR byte 
f2 VAR byte 
f3 VAR byte 
f4 VAR byte 
f5 VAR byte 

Hour = 0
Minute = 0
Second = 0
Ticks = 0
; Initialize timer interrupt. The prescaler is set to 64 and the
; TMR0 is left to run from 0 to 255. With a clock frequency of 4MHz,
; The timer interrupt is generated at every 256 * 64 = 16.384ms.
OPTION_REG = $05 ; Set prescaler = 64
ON INTERRUPT GOTO ISR ; ISR routine
INTCON = $A0 ; Enable TMR0 interrupt and global interrupts
; Beginning of MAIN program loop
LOOP:
; Check Hour button and if pressed increment variable Hour
IF Hrs_button = 0 THEN
Hour = Hour + 1
IF Hour = 24 THEN Hour = 0
Gosub Debounce
ENDIF
; Check Minute button and if pressed increment variable Minute
IF Mins_button = 0 THEN
Minute = Minute +1
IF Minute = 60 THEN Minute = 0
Gosub Debounce
ENDIF

dessat = hour/10 
poma=dessat*10
jedsat = hour-poma

desmin = minute/10 
pomb=desmin*10
jedmin = minute-pomb

if dessat=0 then f1 = %1111110 ' Display "0"
if dessat=1 then f1 = %0110000 ' Display "1"
if dessat=2 then f1 = %1101101
if dessat=3 then f1 = %1111001
if dessat=4 then f1 = %0110011
if dessat=5 then f1 = %1011011
if dessat=6 then f1 = %1011111
if dessat=7 then f1 = %1110000
if dessat=8 then f1 = %1111111
if dessat=9 then f1 = %1111011

if jedsat=0 then f3 = %1111110 ' Display "0"
if jedsat=1 then f3 = %0110000 ' Display "1"
if jedsat=2 then f3 = %1101101
if jedsat=3 then f3 = %1111001
if jedsat=4 then f3 = %0110011
if jedsat=5 then f3 = %1011011
if jedsat=6 then f3 = %1011111
if jedsat=7 then f3 = %1110000
if jedsat=8 then f3 = %1111111
if jedsat=9 then f3 = %1111011 

if desmin=0 then f4 = %1111110 ' Display "0"
if desmin=1 then f4 = %0110000 ' Display "1"
if desmin=2 then f4 = %1101101
if desmin=3 then f4 = %1111001
if desmin=4 then f4 = %0110011
if desmin=5 then f4 = %1011011
if desmin=6 then f4 = %1011111
if desmin=7 then f4 = %1110000
if desmin=8 then f4 = %1111111
if desmin=9 then f4 = %1111011 

if jedmin=0 then f5 = %1111110 ' Display "0"
if jedmin=1 then f5 = %0110000 ' Display "1"
if jedmin=2 then f5 = %1101101
if jedmin=3 then f5 = %1111001
if jedmin=4 then f5 = %0110011
if jedmin=5 then f5 = %1011011
if jedmin=6 then f5 = %1011111
if jedmin=7 then f5 = %1110000
if jedmin=8 then f5 = %1111111
if jedmin=9 then f5 = %1111011 

f2=%0000000  ;dodatna cifra
; Shift in 7 bits data za svaku promjenjivu od f1-f5
Shiftout D1PIN, C1PIN,LSBPRE, [$0001,f5\7,f4\7,f3\7,f2\7,f1\7]
GOTO LOOP
;
Debounce:
FOR Delay = 1 To 200
Pause 1 ; Delay 1ms inside a loop. This way,
NEXT Delay ; timer interrupts are not stopped
Disp = 1 ; Set display flag to 1
RETURN

; Timer TMR0 interrupts are re-enabled just before the program exits this routine.
DISABLE
ISR:
Ticks = Ticks + 1
IF Ticks = 61 THEN NoUpdate
;
; 1 second has elapsed, now update seconds and if necessary minutes and hours.
;
Ticks = 0
Second = Second + 1 ; Update second
IF Second = 60 THEN
Second = 0
Minute = Minute + 1 ; Update Minute
IF Minute = 60 THEN
Minute = 0
Hour = Hour + 1 ; Update Hour
IF Hour = 24 THEN
Hour = 0
ENDIF
ENDIF
ENDIF
Disp = 1 ; Set to update display
;
; End of time update
;
NoUpdate:
INTCON.2 = 0 ; Re-enable TMR0 interrupts
Resume
ENABLE ; Re-enable interrupts
END
END ; End of program
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Konačno sve je proradilo a i nepotrebno je malo obrisano.Ovaj zadnji problem je :
IF Ticks = 61 THEN NoUpdate a trebalo je biti IF Ticks < 61 THEN NoUpdate pa nije brojao do 61 ticks- za svaku sekundu .Uz vašu pomoć i nije bilo teško a pokušat ću dodati i automatsku korekciju
sa dcf77 prijemnikom.
ispravan kod

Code: Select all

define osc 4
Include "modedefs.bas"  ; Include shift modes
D1PIN Var PORTB.7       ; Shift data pin 1
C1PIN Var PORTB.6       ; Shift clock pin 1
; clock code
input PORTA.0
input PORTA.1
Symbol Hrs_button = PORTA.0 ; Hour setting button
Symbol Mins_button = PORTA.1 ; Minute setting button
Ticks VAR byte ; Tick count (61 ticks = 1 sec)
Hour VAR byte ; Hour variable
Minute VAR byte ; Minute variable
Second VAR byte ; Second variable
Delay VAR byte ; Used to Debounce button
dessat     VAR byte 
jedsat     VAR byte 

desmin     VAR byte 
jedmin     VAR byte 
poma       VAR byte 
pomb       VAR byte 
f1 VAR byte 
f2 VAR byte 
f3 VAR byte 
f4 VAR byte 
f5 VAR byte 

Hour = 0
Minute = 0
Second = 0
Ticks = 0
; Initialize timer interrupt. The prescaler is set to 64 and the
; TMR0 is left to run from 0 to 255. With a clock frequency of 4MHz,
; The timer interrupt is generated at every 256 * 64 = 16.384ms.
OPTION_REG = $05 ; Set prescaler = 64
ON INTERRUPT GOTO ISR ; ISR routine
INTCON = $A0 ; Enable TMR0 interrupt and global interrupts
; Beginning of MAIN program loop
LOOP:
; Check Hour button and if pressed increment variable Hour
;
IF Hrs_button = 0 THEN
Hour = Hour + 1
IF Hour = 24 THEN Hour = 0
Gosub Debounce
ENDIF
;
; Check Minute button and if pressed increment variable Minute
;
IF Mins_button = 0 THEN
Minute = Minute +1
IF Minute = 60 THEN Minute = 0
Gosub Debounce
ENDIF


dessat = hour/10 
poma=dessat*10
jedsat = hour-poma

desmin = minute/10 
pomb=desmin*10
jedmin = minute-pomb

if dessat=0 then f1 = %1111110 ' Display "0"
if dessat=1 then f1 = %0110000 ' Display "1"
if dessat=2 then f1 = %1101101
if dessat=3 then f1 = %1111001
if dessat=4 then f1 = %0110011
if dessat=5 then f1 = %1011011
if dessat=6 then f1 = %1011111
if dessat=7 then f1 = %1110000
if dessat=8 then f1 = %1111111
if dessat=9 then f1 = %1111011

if jedsat=0 then f3 = %1111110 ' Display "0"
if jedsat=1 then f3 = %0110000 ' Display "1"
if jedsat=2 then f3 = %1101101
if jedsat=3 then f3 = %1111001
if jedsat=4 then f3 = %0110011
if jedsat=5 then f3 = %1011011
if jedsat=6 then f3 = %1011111
if jedsat=7 then f3 = %1110000
if jedsat=8 then f3 = %1111111
if jedsat=9 then f3 = %1111011 

if desmin=0 then f4 = %1111110 ' Display "0"
if desmin=1 then f4 = %0110000 ' Display "1"
if desmin=2 then f4 = %1101101
if desmin=3 then f4 = %1111001
if desmin=4 then f4 = %0110011
if desmin=5 then f4 = %1011011
if desmin=6 then f4 = %1011111
if desmin=7 then f4 = %1110000
if desmin=8 then f4 = %1111111
if desmin=9 then f4 = %1111011 

if jedmin=0 then f5 = %1111110 ' Display "0"
if jedmin=1 then f5 = %0110000 ' Display "1"
if jedmin=2 then f5 = %1101101
if jedmin=3 then f5 = %1111001
if jedmin=4 then f5 = %0110011
if jedmin=5 then f5 = %1011011
if jedmin=6 then f5 = %1011111
if jedmin=7 then f5 = %1110000
if jedmin=8 then f5 = %1111111
if jedmin=9 then f5 = %1111011 

f2=%0000000  ;dodatna cifra
; Shift in 7 bits data za svaku promjenjivu od f1-f5
Shiftout D1PIN, C1PIN,LSBPRE, [$0001,f5\7,f4\7,f3\7,f2\7,f1\7]
GOTO LOOP
;
Debounce:
FOR Delay = 1 To 200
Pause 1 ; Delay 1ms inside a loop. This way,
NEXT Delay ; timer interrupts are not stopped
RETURN

; Timer TMR0 interrupts are re-enabled just before the program exits this routine.
DISABLE
ISR:
Ticks = Ticks + 1
IF Ticks < 61 THEN NoUpdate
; 1 second has elapsed, now update seconds and if necessary minutes and hours.
Ticks = 0
Second = Second + 1 ; Update second
IF Second = 60 THEN
Second = 0
Minute = Minute + 1 ; Update Minute
IF Minute = 60 THEN
Minute = 0
Hour = Hour + 1 ; Update Hour
IF Hour = 24 THEN
Hour = 0
ENDIF
ENDIF
ENDIF
;
; End of time update
;
NoUpdate:
INTCON.2 = 0 ; Re-enable TMR0 interrupts
Resume
ENABLE ; Re-enable interrupts
END
END ; End of program
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Evo i slike na stolu sa trenutnim vremenom , eksperimentalna i willem programer.
Attachments
Sat.rar
(310.8 KiB) Downloaded 357 times
User avatar
bob4
Stariji član
Stariji član
Posts: 2572
Joined: 31-01-2010, 16:12
Location: Kutina

Re: Digitalni sat sa M5451

Post by bob4 »

Pohvale gazdarici; lijepa je mustra ispod sata. A pohvale i za apsolvirani uradak...Kako ćeš riješiti DCF ? Imaš gotov modul?
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Imam više tih modula koje sam probao na pc preko com porta .Rade dobro samo su osjetljivi na smetnje
pa su tačni u večernjim satima a u toku dana malo teže postignu očitanje čitave sekvence .Test softver
traži dva tačna očitanja da bi prihvatio kao tačno vrijeme.
Što se tiče mustre na stolu ručni rad ha-i.
User avatar
bob4
Stariji član
Stariji član
Posts: 2572
Joined: 31-01-2010, 16:12
Location: Kutina

Re: Digitalni sat sa M5451

Post by bob4 »

I ja sam nedavno nabavio original modul; pa će valjda preko zime biti i ugrađeni u one moje velike satove.... :D a ručni radovi su i kod mene aktuelni .
http://fema-hobi.blogspot.com/
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Sad sam u dilemi jer sa DCF77 postavljanje sata uz velike radio(VF) smetnje predstavlja problem .Sam prijemni modul morao bi se istaknuti kao antena što i jeste (feritna) zbog slabijeg signala u mom
podrjučju.U Njemačkoj gdje je lociran predajnik vjerovatno nemaju tih problema.Trenutno ubacujem kod za mjerenje temperature sa DS1820 tako da se smjenjuje sa vremenom svakih nekoliko sekundi.
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Pokušaj da zajedno u jedan kod pokrenem sat i mjerač temperature bez DS1302 nije mi uspio.
Temperaturu čita ok sa DS1820 ali sat ne radi kako treba.

Code: Select all

Include "modedefs.bas"  ; Include shift modes
D1PIN Var PORTB.7       ; Shift data pin 1
C1PIN Var PORTB.6       ; Shift clock pin 1
ADCON1 = 7
; sat  code
input PORTA.0
input PORTA.1
Symbol Hrs_button = PORTA.0 ; Hour setting button
Symbol Mins_button = PORTA.1 ; Minute setting button
Ticks VAR byte ; Tick count (61 ticks = 1 sec)
Hour VAR byte ; Hour variable
Minute VAR byte ; Minute variable
Second VAR byte ; Second variable
Delay VAR byte ; Used to Debounce button
dessat     VAR byte 
jedsat     VAR byte 

desmin     VAR byte 
jedmin     VAR byte 
poma       VAR byte 
pomb       VAR byte 
f1 VAR byte 
f2 VAR byte 
f3 VAR byte 
f4 VAR byte 
f5 VAR byte 

Hour = 0
Minute = 0
Second = 0
Ticks = 0
; Initialize timer interrupt. The prescaler is set to 64 and the
; TMR0 is left to run from 0 to 255. With a clock frequency of 4MHz,
; The timer interrupt is generated at every 256 * 64 = 16.384ms.
OPTION_REG = $05 ; Set prescaler = 64
ON INTERRUPT GOTO ISR ; ISR routine
INTCON = $A0 ; Enable TMR0 interrupt and global interrupts
; Beginning of MAIN program loop
LOOP:
; Check Hour button and if pressed increment variable Hour
;
IF Hrs_button = 1 THEN
Hour = Hour + 1
IF Hour = 24 THEN Hour = 0
Gosub Debounce
ENDIF
;
; Check Minute button and if pressed increment variable Minute
;
IF Mins_button = 1 THEN
Minute = Minute +1
IF Minute = 60 THEN Minute = 0
Gosub Debounce
ENDIF


dessat = hour/10 
poma=dessat*10
jedsat = hour-poma

desmin = minute/10 
pomb=desmin*10
jedmin = minute-pomb

if dessat=0 then f1 = %1111110 ' Display "0"
if dessat=1 then f1 = %0110000 ' Display "1"
if dessat=2 then f1 = %1101101
if dessat=3 then f1 = %1111001
if dessat=4 then f1 = %0110011
if dessat=5 then f1 = %1011011
if dessat=6 then f1 = %1011111
if dessat=7 then f1 = %1110000
if dessat=8 then f1 = %1111111
if dessat=9 then f1 = %1111011

if jedsat=0 then f3 = %1111110 ' Display "0"
if jedsat=1 then f3 = %0110000 ' Display "1"
if jedsat=2 then f3 = %1101101
if jedsat=3 then f3 = %1111001
if jedsat=4 then f3 = %0110011
if jedsat=5 then f3 = %1011011
if jedsat=6 then f3 = %1011111
if jedsat=7 then f3 = %1110000
if jedsat=8 then f3 = %1111111
if jedsat=9 then f3 = %1111011 

if desmin=0 then f4 = %1111110 ' Display "0"
if desmin=1 then f4 = %0110000 ' Display "1"
if desmin=2 then f4 = %1101101
if desmin=3 then f4 = %1111001
if desmin=4 then f4 = %0110011
if desmin=5 then f4 = %1011011
if desmin=6 then f4 = %1011111
if desmin=7 then f4 = %1110000
if desmin=8 then f4 = %1111111
if desmin=9 then f4 = %1111011 

if jedmin=0 then f5 = %1111110 ' Display "0"
if jedmin=1 then f5 = %0110000 ' Display "1"
if jedmin=2 then f5 = %1101101
if jedmin=3 then f5 = %1111001
if jedmin=4 then f5 = %0110011
if jedmin=5 then f5 = %1011011
if jedmin=6 then f5 = %1011111
if jedmin=7 then f5 = %1110000
if jedmin=8 then f5 = %1111111
if jedmin=9 then f5 = %1111011 

f2=%0000000  ;dodatna cifra
; Shift in 7 bits data za svaku promjenjivu od f1-f5
Shiftout D1PIN, C1PIN,LSBPRE, [$0001,f5\7,f4\7,f3\7,f2\7,f1\7]
pause 5000

;temperatura              
        symbol  DQ = PORTA.2             ' Dq linija je povez. na pin RE2
        temp1 var word
        temp2 var word
        destmp var word
        jedtmp var word
        destmpa var word
        jedtmpa var word
        pomatmp var word
        pombtmp var word
        temperatura  Var Word            ' Promen.za cuvanje izmer. temp.
        count_remain Var Byte            ' Ostatak
        count_per_c  Var Byte            ' Ostatak po stepenu C
           ; ADCON1 = 7                           ' PORTA i PORTE su digitalni
        
Pocetaka:
OWOut DQ, 1, [$CC, $44]      ' Start merenja temperature
Cekaj:  OWIn DQ, 4, [count_remain]       ' Provera da li jos traje
If count_remain = 0 Then Cekaj
OWOut DQ, 1, [$CC, $BE]      ' Procitaj izmerenu temperaturu
OWIn DQ, 0, [temperatura.LOWBYTE, temperatura.HIGHBYTE, Skip 4, count_remain, count_per_c]
       
       ' Prikazi temperaturu u DEC obliku
       
temperatura = (((temperatura >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
temp1 = temperatura/100 
temp2= temperatura/1000

destmp =temp1/10 
pomatmp =destmp*10
jedtmp = temp1-pomatmp

destmpa =temp2 /10 
pombtmp=destmp*10
jedtmpa = temp2-pombtmp

if destmp=0 then f1 = %1111110 ' Display "0"
if destmp=1 then f1 = %0110000 ' Display "1"
if destmp=2 then f1 = %1101101
if destmp=3 then f1 = %1111001
if destmp=4 then f1 = %0110011
if destmp=5 then f1 = %1011011
if destmp=6 then f1 = %1011111
if destmp=7 then f1 = %1110000
if destmp=8 then f1 = %1111111
if destmp=9 then f1 = %1111011

if jedtmp=0 then f3 = %1111110 ' Display "0"
if jedtmp=1 then f3 = %0110000 ' Display "1"
if jedtmp=2 then f3 = %1101101
if jedtmp=3 then f3 = %1111001
if jedtmp=4 then f3 = %0110011
if jedtmp=5 then f3 = %1011011
if jedtmp=6 then f3 = %1011111
if jedtmp=7 then f3 = %1110000
if jedtmp=8 then f3 = %1111111
if jedtmp=9 then f3 = %1111011 

if destmpa=0 then f4 = %1111110 ' Display "0"
if destmpa=1 then f4 = %0110000 ' Display "1"
if destmpa=2 then f4 = %1101101
if destmpa=3 then f4 = %1111001
if destmpa=4 then f4 = %0110011
if destmpa=5 then f4 = %1011011
if destmpa=6 then f4 = %1011111
if destmpa=7 then f4 = %1110000
if destmpa=8 then f4 = %1111111
if destmpa=9 then f4 = %1111011 

;if jedtmpa=0 then f5 = %1111110 ' Display "0"
;if jedtmpa=1 then f5 = %0110000 ' Display "1"
;if jedtmpa=2 then f5 = %1101101
;if jedtmpa=3 then f5 = %1111001
;if jedtmpa=4 then f5 = %0110011
;if jedtmpa=5 then f5 = %1011011
;if jedtmpa=6 then f5 = %1011111
;if jedtmpa=7 then f5 = %1110000
;if jedtmpa=8 then f5 = %1111111
;if jedtmpa=9 then f5 = %1111011 
f5=%1100011
f2=%1001110  ;dodatna cifra
          
           Shiftout D1PIN, C1PIN,LSBPRE, [$0001,f5\7,f4\7,f3\7,f2\7,f1\7]
           pause 500
;Lcdout $fe, $C0," ", DEC (temperatura / 100), ".", DEC2        temperatura, "C"
       Pause 5000                            ' Zadrzi pet sekundi
GOTO LOOP
;
Debounce:
FOR Delay = 1 To 200
Pause 1 ; Delay 1ms inside a loop. This way,
NEXT Delay ; timer interrupts are not stopped
RETURN

; Timer TMR0 interrupts are re-enabled just before the program exits this routine.
DISABLE
ISR:
Ticks = Ticks + 1
IF Ticks < 61 THEN NoUpdate
; 1 second has elapsed, now update seconds and if necessary minutes and hours.
Ticks = 0
Second = Second + 1 ; Update second
IF Second = 60 THEN
Second = 0
Minute = Minute + 1 ; Update Minute
IF Minute = 60 THEN
Minute = 0
Hour = Hour + 1 ; Update Hour
IF Hour = 24 THEN
Hour = 0
ENDIF
ENDIF
ENDIF
;
; End of time update
;
NoUpdate:
INTCON.2 = 0 ; Re-enable TMR0 interrupts
Resume
ENABLE ; Re-enable interrupts
END
END ; End of program
User avatar
alpino005
Penjem se :)
Penjem se :)
Posts: 74
Joined: 27-10-2010, 18:29
Location: Sarajevo , BiH

Re: Digitalni sat sa M5451

Post by alpino005 »

Pitanje vezano za PCF8583 real time clock sa kojim već ima primjera na forumu.Ako se definišu
SCL i SDA za čitanje vremena iz PCF8583 , mogu li se definisat drugi pinovi(PIC16F876) za odvojenu I2C za slanje podataka prema M5451 .
Post Reply