radovi forumasa sa ubrzanog kursa pbp

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

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
VFDisplay
Odlično uznapredovao
Odlično uznapredovao
Posts: 515
Joined: 01-08-2009, 20:18

Re: radovi forumasa sa ubrzanog kursa pbp

Post by VFDisplay »

na koji ti misliš programator koji ide na paralelni port?
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

http://www.elektronika.ba/forum/uploadz ... AMATOR.GIF" onclick="window.open(this.href);return false;
Na taj sam mislio.
Bas me zanima hoce li i kod tebe biti uzaludan pokusaj ili ne...
Nemoj samo posle da me :azdaja:
VFDisplay
Odlično uznapredovao
Odlično uznapredovao
Posts: 515
Joined: 01-08-2009, 20:18

Re: radovi forumasa sa ubrzanog kursa pbp

Post by VFDisplay »

koje si diode koristio (jel 1n4007 ili 1n4148) te koji ti je ono npn tranzistor?
kako se spaja d0,d1,d2,d3,d4, te onaj vpp1,vpp2
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Uh, kako nikom to nije jasno.
Samo gledas pinove kako se zovu. Iste oznake imas na DB25 konektoru, i na ostalom delu seme.
To je samo da se ne vuku zice preko cele seme.
Diode mogu bilo koje, ja sam koristio 1N4148.
Tranzistore sam koristio BC547/557.
Ovi brojevi desno npr ACK-10, to znaci da spajas na pin 10 na DB25.
Ovo levo je ime pina. A iznad funkcija pina na programatoru.
Koliko vidim samo bespotrebni podatci...
Mislio sam da ce nekog mozda zanimati princip pa sam ih zato pisao...
VFDisplay
Odlično uznapredovao
Odlično uznapredovao
Posts: 515
Joined: 01-08-2009, 20:18

Re: radovi forumasa sa ubrzanog kursa pbp

Post by VFDisplay »

ništa od toga....
sram me i reći ali u cijeloj kući nemogu naći ama baš niti jedan PNP tranzistor!
sami NPN-ovci
svejedno hvala na trudu!!!
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Ok. Al kad ga nabavis probaj...
User avatar
niho
Pravi forumaš
Pravi forumaš
Posts: 1895
Joined: 24-09-2009, 17:26
Location: Brcko, Bosnia and Herzegovina

Re: radovi forumasa sa ubrzanog kursa pbp

Post by niho »

Projekat semafor je u zavrsnoj fazi bolje reci 99% zavrsen, sve radi - sve funkcionise kako je zamisljeno a ostala su jos neka sitna dotjerivanja estetske prirode. U dilemi sam da li da ga objavim ovdje posto imam namjeru da s tim projektom nastupimo na takmicenju. Sva dokumentacija je spremna, shema, plocica, kod a ono sto je najvaznije uredjaj radi perfektno. Popodne cu postaviti fotke ili video .
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Ja bih postavio slike, video, semu, a program posle zavrsenog takmicenja.
Srecno :wink: I pazi da ga neko ne odnese :roll:
User avatar
sindja1204
Odlično uznapredovao
Odlično uznapredovao
Posts: 792
Joined: 03-05-2009, 11:57
Location: Beograd

Re: radovi forumasa sa ubrzanog kursa pbp

Post by sindja1204 »

Counter sa mogucnoscu podesavanja od 0-65535. Tasterom reset podesi se zeljeno vreme. Tasterom start aktivira se brojac , pali se led dioda (relej), i nakon isteka vremena led se gasi uz zvucnu signalizaciju.

Code: Select all

Define  LCD_DREG        PORTD
Define  LCD_DBIT        4
Define  LCD_RSREG       PORTD
Define  LCD_RSBIT       2
Define  LCD_EREG        PORTD
Define  LCD_EBIT        3
DEFINE  LCE_BITS        4
DEFINE  LCD_LINES       2
symbol taster=porta.0
symbol tastera=porta.1
symbol led=portb.0
symbol buzer=portc.2


trisb=%00000000
ADCON1=$7
I Var word
j var word
i=0
j=0

 pocetak:
 portb=0
 if taster=0 then i=i+1
 if i>65535 then i=0
 if tastera=0 then   broj
 pause 20
 Lcdout $fe, 1, "reset:   "    ,DEC5 I    
 Pause 100           
 Goto   pocetak      
 broj:
 portb=0
 high led
 for j=0 to i
 if j=i then  i=0:low led: sound buzer,[110,55]
 lcdout $fe,$c0, "start:   "    ,dec5 j
 pause 1000
 next j
 goto pocetak
 End
http://www.youtube.com/watch?v=xhNE-0CsmyA" onclick="window.open(this.href);return false;


Doterivanjem ovog koda dobija se tajmer u rasponu od 00:00-59:59. Funkcionise na isti nacin kao i counter. Tasterom setings se podesi zeljeno vreme na prvoj liniji displeja. Pritiskom na taster counter, aktivira se brojac na drugoj liniji displeja i u isto vreme pali led ili relej. Nakon isteka podesenog vremena gasi se led (relej) uz zvucnu signalizaciju. Brise se drugi red displeja i tajmer je ponovo spreman za upotrebu. Poslednje vreme se pamti. Tasterom Reset/mclr po potrebi se resetuje na 00:00

Code: Select all

:10000000B6011D290408A7008811081108118316DC
:100010008811081108110F30880583122708B618B7
:100020002F283A30A1009830C7203330A600432053
:100030001330A1008830C72043206430C6204320FD
:100040006430C6202230A600432028302E200C30F9
:100050002E2006302E20B61427082F283614A6008E
:10006000361C3D280811033C031C4228422007305F
:10007000A100D030C720031408003614FE3C031939
:1000800018290815361C361088150F3088052608E3
:10009000F03988048811A60E361843283230C6205D
:1000A00003140800B71329080319B7170530A8006F
:1000B0002730A300103068200330A300E830682008
:1000C000A30164306820A3010A30682024086F2847
:1000D000A2002508A1002408A000F7202008A00005
:1000E000A8030319B713290803197928280203184C
:1000F00008002008031DB713B71B0800303E132962
:10010000A3003A0884003809A7208413A308031920
:100110001829F030A50022088038A400F030A5038B
:100120000319A5000319A303031918299728AA2066
:10013000030120183808A21F3808A2080319030178
:10014000A40FA42880068B28A52800008E288417D9
:1001500080051829210820040319A00A8030201ADC
:10016000A1062019A106A018A106210DA00DA10D20
:100170001829A301A200FF30A207031CA307031C38
:1001800018290330A100DF30C720BB28A101E83EB9
:10019000A000A109FC30031CD028A0070318CD281B
:1001A000A0076400A10FCD282018D628A01CDA28AB
:1001B0000000DA280800A101A301A2000230E02813
:1001C000A80023082102031DE7282208200204308A
:1001D00003180130031902302805031DFF301829C8
:1001E0000038031DFF300405031DFF301829A50149
:1001F000A4011030A600210DA40DA50D2208A40213
:100200002308031C230FA50203180D292208A407A5
:1002100023080318230FA5070310A00DA10DA60B9B
:10022000FB2820081829840031088A003008820041
:1002300083130313831264000800831686010730BA
:100240009F008312BF01BE01BD01BC018601640095
:100250008A110A1205182D29BF0A64003C303F029A
:100260008A110A12031C3629BF01BE0A64003C3001
:100270003E028A110A12031C3E29BE0164008A1143
:100280000A12851C7D2932308A01B920FE308A018C
:10029000032001308A01032073308A010320653076
:1002A0008A01032074308A01032069308A01032007
:1002B0006E308A01032067308A01032073308A017F
:1002C000032020308A0103200230A9003E08A40048
:1002D000A5010230B000B1018A0152203A308A01F2
:1002E00003200230A9003F08A400A5010230B0009D
:1002F000B1018A0152208A01262932308A01B920AF
:1003000086010614831606108312BC0164003D307A
:100310003C028A110A120318272ABD0164003D30ED
:100320003D028A110A120318222A64003D083C3C4F
:100330008A110A12031D9E29BD01BC0A64003C08F3
:100340003C3C8A110A12031DA729BC01BD013C08CF
:10035000A0003E088A01DB20B2003D08A0003F0853
:100360008A01DB20B4003208840034088A01F020BE
:10037000B400B5006400340835048A110A12031968
:10038000CE2906108316061007308312BA000430F7
:10039000B8006E30A20032308A018020FE308A011F
:1003A0000320C0308A01032063308A0103206F30AC
:1003B0008A01032075308A0103206E308A010320F0
:1003C00074308A01032065308A01032072308A016B
:1003D000032020308A0103200230A9003C08A40039
:1003E000A5010230B000B1018A0152203A308A01E1
:1003F00003200230A9003D08A400A5010230B0008E
:10040000B1018A0152200330A300E8308A01BA20EA
:100410003C08A0003E088A01DB20B2003D08A00095
:100420003F088A01DB20B4003208840034088A01C6
:10043000F0208A110A12031D2629BD0A8A110A1208
:10044000031D8E29BC0A8A110A12031D86298A01FE
:08045000262963008A01292A14
:02400E00753FFC
:00000001FF
http://www.youtube.com/watch?v=ETpxdKaNrQk" onclick="window.open(this.href);return false;

Kod je pisan za pic 16F877A. Moze se upotrebiti i 16F87A /16F 628A...El shemu nisam postavio posto se lako moze sklopiti na osnovu angazovanih pinova u prvom delu koda. S tim da se za neki drugi pic izvrse izmene u kodu...
User avatar
RazoR
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 255
Joined: 01-08-2008, 15:14
Location: Hrvatska

Re: radovi forumasa sa ubrzanog kursa pbp

Post by RazoR »

Ima li netko primjer koda sličan onome koji se koristi u Ir ON-OFF prekidaču? Htio bi napraviti prijemnik s nekim malo većim PIC-om od 12F629 kako bi mogao koristiti više izlaza (tranzistora i/ili releja). Zgodan je onaj sindjin način, ali ja bi to volio napraviti s jednim PIC-om.
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Ovo je neki primer za RC5 kod, ali ne znam dali radi...

Code: Select all

SYMBOL BrojB       = 52  'Maksimalno 255
SYMBOL LED_Blink   = 500 'mSec: Vreme trajanja iskljucenja LED diode greske
SYMBOL Ok          = 50  'Maksimalno 255

SYMBOL LED_Greska  = PORTA.0 'Led greske u prijemu RC5
SYMBOL IR_Bit      = PORTA.4 'Prijem IR signala

TRISA = %11111000
TRISB = %00000000   'PORTB je izlazni 

Komanda VAR BYTE
Adresa VAR BYTE

BD1 VAR BYTE        'Brojacka promenljiva

ToggBit    VAR BIT  'Toggle bit
BitFF      VAR BIT  'Tekuca vrednost Toggle bita
PrimBit    VAR BIT  'Broj primljenih bita
ID1        VAR BIT  'bIt Dummy


PORTB =%11111111    'PORTB je izlazni 

GoTo Pocetak        'Idi na pocetak

'-------Podprogram prijema bita -------------                                                                                                           
PrijemBita:
 PrimBit = IR_Bit       
 BD1     = 0

 While IR_Bit = PrimBit AND BD1 < Ok 
   BD1 = BD1 + 1
 Wend

 IF Ok = BD1 Then Greska_Prijem1   
 PauseUs 1100                     
 
Return

'--------Ceka na prijem IR signala-----------                                                                                                         
Pocetak:
 
 BD1 = 0

 While IR_Bit = 1
 Wend                        
 
 While IR_Bit = 0 AND BD1 < BrojB
   BD1 = BD1 + 1
 Wend

 PauseUs 500                 '200 - 825; Prijem start bita

 GoSub PrijemBita
 Adresa.6 = PrimBit ^ 1      'bit prosirenja

 GoSub PrijemBita
 ToggBit = PrimBit

 GoSub PrijemBita
 Adresa.4 = PrimBit

 GoSub PrijemBita
 Adresa.3 = PrimBit

 GoSub PrijemBita
 Adresa.2 = PrimBit

 GoSub PrijemBita
 Adresa.1 = PrimBit

 GoSub PrijemBita
 Adresa.0 = PrimBit
 

 GoSub PrijemBita
 Komanda.5 = PrimBit

 GoSub PrijemBita
 Komanda.4 = PrimBit

 GoSub PrijemBita
 Komanda.3 = PrimBit

 GoSub PrijemBita
 Komanda.2 = PrimBit

 GoSub PrijemBita
 Komanda.1 = PrimBit

 GoSub PrijemBita
 Komanda.0 = PrimBit
 
 IF ToggBit = BitFF Then  ' Ako se togle bit nije promenio ignorisi komandu
              GoTo AB
 EndIF            

 
   BitFF = ToggBit        ' Zapamti togle bit

' Promeni stanja na izlazima PORTA-B zavisno od primljene komande

   IF Komanda = 1 Then
   Toggle PORTB.0
   GoTo AB
   EndIF
   
   IF Komanda = 2 Then
   Toggle PORTB.1
   GoTo AB
   EndIF
   
   IF Komanda = 3 Then
   Toggle PORTB.2
   GoTo AB
   EndIF
   
   IF Komanda = 4 Then
   Toggle PORTB.3
   GoTo AB
   EndIF
   
   IF Komanda = 5 Then
   Toggle PORTB.4
   GoTo AB
   EndIF
   
   IF Komanda = 6 Then
   Toggle PORTB.5
   GoTo AB
   EndIF
   
   IF Komanda = 7 Then
   Toggle PORTB.6
   GoTo AB
   EndIF

   IF Komanda = 8 Then
   Toggle PORTB.7
   GoTo AB
   EndIF
                      
AB:                      

 GoTo Pocetak
'---------Obrada greske u prijemu---------
Greska_Prijem1:
 LED_Greska  = 1              
 Pause LED_Blink
 LED_Greska  = 0              
 Pause LED_Blink
 LED_Greska  = 1              
 Pause LED_Blink
 LED_Greska  = 0              
 Pause LED_Blink
 GoTo Pocetak
User avatar
sindja1204
Odlično uznapredovao
Odlično uznapredovao
Posts: 792
Joined: 03-05-2009, 11:57
Location: Beograd

Re: radovi forumasa sa ubrzanog kursa pbp

Post by sindja1204 »

Ovo je kod Voje Milanovica za 4-Kanalni IR Prijemnik. Na istoj strani je i RC5 IR Predajnik kojim moze da se kontrolise ovaj prijemnik. Ja sam napravio i jedan i drugi sklop ali to nije radilo. Covek je zaboravio da stavi hex za ovaj predajnik. Kod postoji na disku koji se prodaje uz knjigu, ali prilikom kompajliranja pokaze se mali milion gresaka. Znaci u ovoj kombinaciji kod ne radi. Trebalo bi sklop i kod proveriti nekim univerzalnim daljinskim koji ima RC5 standard.
Medjutim, mislim da je RazoR mislio na nesto drugo. Na kod koji je npr. Trax primenio u dimmeru kojim se memorise tipka na daljinskom ili nesto poput IR prekidaca Ivice Novakovica IR on/of ili IR2xon/of.
http://www.ivica-novakovic.from.hr/Projekti.htm" onclick="window.open(this.href);return false;
Znaci poenta bi bila da se u jednom picu vecem od 12F629 objedini Memorisanje tipke/tipki daljinskog sa drugim delom koda.
U ovom projektu posebno je odradjen deo za prijem koda , mada bi bilo mnogo bolje da je sve to objedinjeno i odradjeno sa jednim Pic-om
http://www.elektronika.ba/forum/viewtop ... f=9&t=7603" onclick="window.open(this.href);return false;
E sad bi Trax mogao da zasuce rukave i otkrije nam svoj tajni kod koji je koristio za dimmer. :)
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Ja nisam naisao ni na jedan RC5 daljinac. Sve sto imam su sa NEC protokolom...
A ja sam uporno pokusavao naterati ih da rade sa RC5, i tu sam odustao...
Inace ovaj gore kod nema ni jednu gresku, ako je imao moguce da sam ispravio...
Mislim da nije nikakav problem napisati kod za odgovarajuci protokol, samo prvo treba naci koji je protokol na daljincu. A objediniti sve protokole u jednom kodu nije bas tako jednostavno...
User avatar
sindja1204
Odlično uznapredovao
Odlično uznapredovao
Posts: 792
Joined: 03-05-2009, 11:57
Location: Beograd

Re: radovi forumasa sa ubrzanog kursa pbp

Post by sindja1204 »

pedja089 wrote: Inace ovaj gore kod nema ni jednu gresku,
Kod je mozda dobar, ali IR prijemnik (u kome se nalazi Pic sa ovim kodom), nisam jos uvek uspeo nijednim daljincem da aktiviram :)
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

E to nisam ni ja...
User avatar
RazoR
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 255
Joined: 01-08-2008, 15:14
Location: Hrvatska

Re: radovi forumasa sa ubrzanog kursa pbp

Post by RazoR »

Evo nasao sam neki kod za prijemnik i predajnik u pic basicu: http://www.rentron.com/PicBasic/IR_Chips.htm" onclick="window.open(this.href);return false;

Na pic je spojen TSOP1740, ako bi stavio TSOP1738 je li jedina razlika u onome vremenu u kodu (40kHZ - 25us, onda je za 38kHZ približno 26us)?

'// RA.1 to RA.5 = Hardware address inputs (set same on encoder as decoder)
Mogu li ja ove portove iskoristiti za spojiti neku tipku i ledicu umjesto da s njih očitava adrese, a adrese koje bi slao encoder i primao decoder upisati u kodu?

Još bi trebalo napraviti da može naučiti kodove kao Traxov dimmer i onaj Ir ON-OFF switch. To mi se ne čini kao veliki problem kada bi znao spremati varijable u eeprom pica (naučiti ću :))
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: radovi forumasa sa ubrzanog kursa pbp

Post by pedja089 »

Evo jedan primer sta treba izbegavati:

Code: Select all

serin2 pc_rx,396,3000,init,[wait("DATA:"), dan, mesec, god, sat, minut, sek, dat, str sb1\9, str sb2\9, str sb3\9, str sb4\9, br12.byte1,br12.byte0,br11.byte1,br11.byte0,br10.byte1,br10.byte0,br22.byte1,br22.byte0,br21.byte1,br21.byte0,br20.byte1,br20.byte0,br32.byte1,br32.byte0,br31.byte1,br31.byte0,br30.byte1,br30.byte0,br42.byte1,br42.byte0,br41.byte1,br41.byte0,br40.byte1,br40.byte0,str mpl1\2,str mpl2\2,str mpl3\2,str mpl4\2,Dsms1,Dsms2,str SMS1\dsms1,str SMS2\dsms2]
To je samo 1 red programa :lol:
Mada nije samo da se hvalim duzinom 8) Nego ima i nesto pametno.
A to je ovo:

Code: Select all

Dsms1,Dsms2,str SMS1\dsms1,str SMS2\dsms2
Sto znaci da sa racunara mozemo poslati duzinu stringa koji kupimo i string odjednom.
U kursu takva komunikacija nije radjena iz prostog razloga sto treba i znati pisati aplikacije da bi bilo koristi od komunikacije. Stoga evo ovo samo kao napomena onima koji su probali komunikaciju...
User avatar
Kizo
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 387
Joined: 01-11-2009, 22:40
Location: Hrvatska

Re: radovi forumasa sa ubrzanog kursa pbp

Post by Kizo »

Da pridonesem nešto ovoj temi, te se pohvalim sa programom koji sam napravio ovih dana za PIC16F628.

Dobio sam na popravak uređaj za automatsko mljevenje kukuruze koji svakih 24h uključuje motor na 1-15sec. Uglavnom, unutra su tko zna zbog čega poizgarali skoro pa svi poluvodiči. PIC je preživio (osim 4 pina :D), pinovi za programiranje su ok, no na moju veliku žalost, nisam mogao iz njega izvući hex jer je bio zaštićen, tako da sam morao napisati program ispočetka.

Nije PBP, ali je Basic:

Code: Select all

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+ -------------------------------------------------------------------------- +
'+    Description : Ruđilica za kukuruzu                                      +
'+    Revision    : 1.0                                                       +
'+    Controller  : PIC16F628                                                 +
'+    Compiler    : Basic Compiler                                            +
'+    Author      : Zoran Halic, Croatia, Dec.2010.                           +
'+ -------------------------------------------------------------------------- +
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'define port pin
Symbol led = RA1  'LED is connected on RA1
Symbol cap = RA2  'capacitor is connected to RA2
Symbol pot = RA3  'one end of potentiometer is connected to RA3
Symbol start_key = RB1  'START key is on RB1
Symbol test_key = RB2  'TEST key is on RB2
Symbol accu = RB3  'indication of low accumulator voltage
Symbol relay = RB4  'relay is on RB4

'config ports
Config led = Output  'RA1 is output
Config cap = Output  'RA2 is output at begining
Config pot = Output  'RA3 is output
Config start_key = Input  'RB1 is input
Config test_key = Input  'RB2 is input
Config accu = Input  'RB3 is input
Config relay = Output  'RB4 is output

'initilize hardware
T2CON.T2CKPS0 = 1  'Timer2 prescale=4

CMCON.CM1 = 1  'four inputs multiplexed to two comparators
CMCON.CIS = 1  'select RA2:RA3 as inputs to comparator

VRCON = %00101100  'configure internal voltage reference to 2.5V

'define variables
Dim relay_working_miliseconds As Word  'this variable will contain miliseconds relay is ON
Dim relay_on_time As Word  'contains miliseconds relay needs to be ON
Dim miliseconds As Word  'keep track of passed miliseconds
Dim seconds As Byte  'keep track of passed seconds
Dim minutes As Byte  'keep track of passed minutes
Dim hours As Byte  'keep track of passed hours

'define flags
Dim timer2_int_flag As Bit  'used to indicate that Timer2 Interrupt occured
Dim check_charge_time_flag As Bit  'indication that charge time need to be checked
Dim relay_is_on_flag As Bit  'indicate that relay needs to be on

'enable interrupts
PIE1.TMR2IE = 1  'enable Timer2 interrupts
INTCON.PEIE = 1  'enable peripheral interrupts
INTCON.GIE = 1  'global Interrupt Enable

'initilize start conditions
WaitMs 250  'wait some time for capacitors to fully charge
PR2 = 249  'with prescale=4 and xtal=4MHz, timer2 will reload every 1ms
T2CON.TMR2ON = 1  'start Timer2
timer2_int_flag = 0  'clear flags
check_charge_time_flag = 0  'clear flags




'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'------------------------------------------------------------------------------
'Main program
'------------------------------------------------------------------------------
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
main:  'forever loop
If timer2_int_flag = 1 Then Gosub update_time  'Timer2 overflow occured? -> update time
If check_charge_time_flag = 1 Then Gosub check_charge_time  'pot position needs to be checked? -> jump to corresponding subroutine

If test_key = 0 Then check_charge_time_flag = 1  'test key is pressed? -> check pot position

If start_key = 0 Then  'start key is pressed?
	check_charge_time_flag = 1  'check pot position
	'---reset time---
	miliseconds = 0
	seconds = 0
	minutes = 0
	hours = 0
Endif

If accu = 0 Then led = 0 Else led = 1  'voltage is too low? -> turn ON LED

Goto main
End                                               




'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'------------------------------------------------------------------------------
'Subroutine that keeps track of time
'will be accessed every 1ms
'------------------------------------------------------------------------------
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
update_time:

'---keep track of time---

miliseconds = miliseconds + 1  'increase miliseconds
If miliseconds >= 1000 Then  '1 second passed?
	seconds = seconds + 1  'increase seconds
	miliseconds = 0  'reset miliseconds

	If seconds >= 60 Then  '1 minute passed?
		minutes = minutes + 1  'increase minutes
		seconds = 0  'reset seconds

		If minutes >= 60 Then  '1 hour passed?
			hours = hours + 1  'increase hours
			minutes = 0  'reset minutes
			
			If hours >= 24 Then  '1 day passed?
				hours = 0  'reset hours
				relay = 1  'turn ON relay
				relay_is_on_flag = 1  'set flag to monitor relay ON time
				relay_working_miliseconds = 0  'reset ON time
			Endif
		Endif
	Endif
Endif


'---measure for how long relay is on and turns it off if it reach max value---

If relay_is_on_flag = 1 Then  'relay needs to be on?
	relay_working_miliseconds = relay_working_miliseconds + 1  'increase miliseconds relay is ON

	If relay_working_miliseconds >= relay_on_time Then  'ON time expired?
		relay = 0  'turn OFF relay
		relay_is_on_flag = 0  'reset flag that relay is ON
		relay_working_miliseconds = 0  'reset ON time for next cycle
	Endif
Endif


'---reset flag and exit this subroutine---

timer2_int_flag = 0  'reset flag of this subroutine

Return                                            




'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'------------------------------------------------------------------------------
'Subroutine that checks required time for capacitor to charge and from that
'calculates selected seconds (1-15s) for relay to be on
'------------------------------------------------------------------------------
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
check_charge_time:

'---init needed hardware/variables for measurement---

VRCON.VREN = 1  'turn ON voltage reference
TMR1H = 0  'reset Timer1
TMR1L = 0


'---fully discharge capacitor---

Config cap = Output  'make pin on which is connected cap as output
cap = 0  'start discharging
WaitUs 100  'wait at least 100us for capacitor do discharge


'---start charging cap through pot---

Config cap = Input  'now voltage on capacitor is input to analog comparator
INTCON.GIE = 0  'disable global interrupts so it doesn't interfere with measurments
pot = 1  'put one end of Pot to 5V


'---measure time needed for voltage on Cap to reach Reference Voltage---

T1CON.TMR1ON = 1  'start Timer1
While CMCON.C2OUT = 1  'wait till voltage on cap reach reference voltage
Wend
T1CON.TMR1ON = 0  'stop Timer1
INTCON.GIE = 1  'enable global Interrupts


'---calculate selected seconds relay will be on---

relay_on_time.LB = TMR1L  'save Timer1 value
relay_on_time.HB = TMR1H
relay_on_time = relay_on_time * 3  'scale that value


'---turn ON relay and set flag to monitor for how long its ON---

relay = 1  'turn ON relay
relay_is_on_flag = 1  'set flag to monitor relay ON time
relay_working_miliseconds = 0  'relay has just turned ON


'---prepare next measurment---

VRCON.VREN = 0  'turn OFF voltage reference - consumes power
pot = 0  'slowly discharge cap through pot
check_charge_time_flag = 0  'reset flag of this subroutine

Return                                            




'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'------------------------------------------------------------------------------
'Interrupt handler
'This routine will be activated by Timer2 overflow which occurs every 1ms
'------------------------------------------------------------------------------
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
On Interrupt
timer2_int_flag = 1  'set flag so we know that interrupt occured
PIR1.TMR2IF = 0  'enable new Timer2 interrupt by clearing its flag
Resume                                            
Sklop radi po ovim uvjetima:
http://img233.imageshack.us/img233/4503/dsc01709x.jpg
VFDisplay
Odlično uznapredovao
Odlično uznapredovao
Posts: 515
Joined: 01-08-2009, 20:18

Re: radovi forumasa sa ubrzanog kursa pbp

Post by VFDisplay »

malo kasnim s temom no šta je tu je.
@Pedja, probao sam tvoj kod za RC-5 i nešta nevalja.Svaki put kad pritisnem tipku izbacuje mi grešku (tj ona ledica za grešku trepće). U daljincu koji sam koristio nalazi se SAA3010 integrirani krug (infrared remote control transmitter RC-5), IR senzor je od tog daljinca tako da tu nebi trebalo biti problema.
Da li netko zna u čemu bi mogao biti problem?
Branez
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 457
Joined: 22-04-2008, 16:27
Location: Maribor(SLO) Koprivnica(HR)
Contact:

Re: radovi forumasa sa ubrzanog kursa pbp

Post by Branez »

Daljinac nema senzora nego IR diode!
Real Radios Glow in the Dark!
Post Reply