skraceni kurs ucenja picbasica

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

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
User avatar
Kukinjos
Pravi forumaš
Pravi forumaš
Posts: 1724
Joined: 28-03-2012, 18:01
Location: Split

Re: skraceni kurs ucenja picbasica

Post by Kukinjos »

Cezare, star sam i nemoćan, ali poslušaj moj savjet ....
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

Hvala drugar :D

Dva pitanja ?

1. Koja je to verzija, jeli to 3.0.7 /gold ili ?? - da bi znao šta da skinem .

2. U medjuvremenu sam našao 3.0.4 i imam mali problem.
Nisam instalirao MPLAB, već samo MSC,
U MSC pomoću PBP_MPASM_ Connector.exe pokažem putanju do Mpasm na disku (v5.20) i to je OK.
Kada je štiklirano da zatvori MPASM posle asembliranja - prijavi prilikom asembliranja :
error in parametar "/s"
Tek kada ovo isključim sve ide bez greške, ali ne zatvara MPASM ?


Pozdrav
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

Evo da odgovorim sam sebi, jer sam malo nestrpljivo postavio pitanja.

1. Kada se skine 3.0.7 (zadnja verzija sa sajta) i primeni prepisana medicina u Aboutu od MCS lepo piše :
3.0.4.1
2. Kada se u toku instalacije ostavi MPLAB, instaliran je MPASM 5.49 koji ne pravi nikakve probleme.

- Ispravite me ako grešim.


Jedino ne znam može li se isključiti ono ZELENO dugme "Buy PicBasic" - baš bode oči ?

Nego kako stoje stvari sa PROTON kompajlerom, koja je zadnja medicina ?

Pozdrav
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Jedan problem, vezan za poznati termostat sa DS18B20

Code: Select all

Symbol T1=PORTA.1
Merenje1:
If V < TargetTemp - Hyst and T1=0 then Merenje2
Merenje2:
If V > TargetTemp + Hyst and T1=1 then Merenje1
Program mi uredno ide iz merenje,1 kada se ispune uslovi temperatura+porta.1=0, medjutim kad je u merenje2 nece da se vrati u merenje1 kad se ispune uslovi temperatura+porta.1=1.
kad ga ovako formiram:

Code: Select all

Symbol T1=PORTA.1
Merenje1:
If V < TargetTemp - Hyst then Merenje2
Merenje2:
If V > TargetTemp + Hyst and T1=1 then Merenje1
vrati se u merenje1, ali meni treba da kad se ispune uslovi temperature i digitalnog izlaza, ako ima neko neku ideju?
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

Ovako kako si napisao:

Dok je t1 = 0 ti prozivaš konstantno Merenje2 , ali nemaš uslov za izvršavanje u Merenje2 jer ti je T1=0.
Kad je T1 =1 dobija se uslov za izvršavanje u Merenje2, ALI SE NEĆE IZVRŠITI jer se nemože ni prozvati Merenje2. - Sve na svemu pogrešna postavka.

Probaj ubaciti petlju u kojoj če program ostati zaglavljen dok ne dodje do promene stanja T1.

To je ono što sam na brzinu video, - nisam ni ja baš neki ponavalac, slobodno me ispravite ako negde grešim.
Sigurno će iskusniji dati bolju ideju za realizaciju.

Pozdrav
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

A što ne probaš ovako:

Symbol T1=PORTA.1

Main:
gosub Merenje1
gosub Merenje2
goto Main

Merenje1:
If V < TargetTemp - Hyst and T1=0 then
' napiši program
endif
return

Merenje2:
If V > TargetTemp + Hyst and T1=1 then
' napiši program
endif
return


A možeš i koristiti izmedju IF/ENDIF i "ELSE" gde ti je deo koda za slučaj NEispunjavanja uslova u svakom potporgramu.

Pozdrav
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Izgleda je umor, ovako treba:

Code: Select all

    Symbol T1=PORTA.1
    Merenje1:
    If V < TargetTemp - Hyst and T1=0 then Merenje2   'moraju oba uslova da se ispune kako bi pocelo grejanje
    Merenje2:
    If V > TargetTemp + Hyst or T1=1 then Merenje1     'mora jedan (bilo koji) od dva uslova...
User avatar
LegoMan4
Penjem se :)
Penjem se :)
Posts: 92
Joined: 09-05-2012, 21:47
Location: split

Re: skraceni kurs ucenja picbasica

Post by LegoMan4 »

Zna li tko mogu li se pinovi pic mikrokontrolera postaviti da rade u analognom stanju?


Odnosno da mi se led dioda ne uključi odmah, nego da se uključi "eksponencijalno" odnosno malo, pa malo više i tako par stotinki, te da se onda uključi na punu vrijednost napona
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

Pinovi u "Analognom stanju" mogu biti samo ulazni.
Znači, neki ulazni napon ( 0 - 5V) se pretvara putem ADC konvertera u digitalnu vrednost.

To što tebi treba radi se drugačije.
Pin je i dalje "digitalni" a putem PWM odnosno odnosom izmedju signala i pauze menja izlazna struja a samim tim i intenzitet sjaja LED diode.
Puno je lakše ovo izvesti sa mikrokontrolerima koji imaju "hardverski PWM" u sebi.

Proguglaj : LED dimmer + ( i željena familija MCU) i pronaćeš dosta primera.

Pozdrav
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

A evo primera u PBP sa HPWM,

Code: Select all

Duty        var byte
Frekvencija var word
          
                    
          Duty = 0
          Frekvencija = 500         ' Ovde upiši željenu frekvenciju za PWM (Hz)
Main:
    
          if duty < 255 then duty = duty + 1  ' Korak porasta sjaja "po jedan"
          pause 100                           ' Brzina porasta sjaja (100mS)
          hpwm 0,Duty,Frekvencija
          goto Main 
U data sheetu pronadji za željeni kontroler koji je pin za HPWM0 i samo taj pin možeš koristiti za LED diodu.
tron1960
Posts: 1
Joined: 24-04-2015, 16:31

Re: skraceni kurs ucenja picbasica

Post by tron1960 »

Pozdrav

Molim za PBP3 gold medicinu, ako može ...
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Imam neki uredjaj sa 16F628A koji nekako radi, vlasnik mi je dao da ga prepravim... Naime u njemu je oscilator odradjen kao na slici:

Image


Ukupan otpor podešenog trimera i otpornika, mereno je i iznosi 52,6k

Kod je zašticen pa treba da pisem drugi... Kako da podesim u PBP oscilator za 16F628A ako koristim ovakvu šemu bez kristala?
Hteo bi da stavim i probam i sa 16F84A bez kristala, imam neki povlaci mi se?
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Uhhh moja greska...RC oscilator... :idea:
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: skraceni kurs ucenja picbasica

Post by pedja089 »

Sta bi se zajebavao sa tim oscilatorom...
Ukljuci interni od 4MHz i to je to.
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Nisam ni razmisljao, bilo nabrzaka, mada sam vec resio ovako, bilo bi bolje da sam interni
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Kako da u ovaj kod ubacim podesavanje za jos jednu temperaturu SET TEMP2?

Code: Select all

'*****************************************************************************
' Variables
'*****************************************************************************
 I var word
 J var word
 tmp1    var byte
 tmp2    var byte
Temperature    Var   Word      ' Temperature storage
TempC         Var Word
Float         Var Word
TargetTemp      Var   Word      ' Desired Temperature
Hyst         Var   Word      ' Hystereris
V            Var   Word      ' Var. for display

B1              Var Byte            ' Byte for TargetTemp calculation 
B2              Var Byte            ' Byte for TargetTemp calculation
Count_Remain    Var Byte      ' Count remaining
Count_Per_C    Var   Byte      ' Count per degree C
Sign         Var   Byte      ' +/- sign
Mode          Var   Byte      ' 0=Temp. display, 1=Set Temp, 2=Set Hysteresis

Twist         Var Bit

'*****************************************************************************
' Resolution
'*****************************************************************************

DS18B20_9bit     CON %00011111      ' 93.75ms, 0.5°C
DS18B20_10bit    CON %00111111      ' 187.5ms, 0.25°C  <-- My favorite
DS18B20_11bit    CON %01011111      ' 375ms,   0.125°C
DS18B20_12bit    CON %01111111      ' 750ms,   0.0625°C  (default)

DATA 46, 224, 20                        ' Temp MSB, TEMP LSB, Hysteresis DIV 10

Heat=0                               ' Warm Output Low
Cool=0                               ' Cold Output Low
Mode=0                                  ' Temperature display mode
Twist = 0  

PAUSE 500
LCDOUT $FE, 1, $FE, $0C                 ' Clear display, cursor off
PAUSE 250




'-------------------------------------------------------------------------------

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit]    'Skip ROM search and write N_bits
                                               '  resolution to scratch pad
Read 0, B1                              ' Read TargetTemp MSB
Read 1, B2                              ' Read TargetTemp LSB
TargetTemp=B1*256+B2                    ' Calculate TargetTemp value (Default=20.0 C.)
Read 2, B1                              ' Read Hysteresis 
Hyst=10*B1                              ' Calculate Hysteresis value (Default= 2.0 C.)  
'-------------------------------------------------------------------------------
MainLoop: 
If Mode_B=0 then                      ' Mode switch pressed
  Pause 50                              ' Debounce
  LcdOut $FE, $8F, "*"                  ' Show that command is accepted
  If Mode_B=0 then MainLoop            ' Wait until button is released 
  Mode=Mode+1                           ' Increment mode
  If Mode=1 then                        ' Save Target Temperature (Mode1 -> Mode2) 
   Write 0, TargetTemp / 256      ' TargetTemp MSB
   Write 1, TargetTemp MOD 256          ' TargetTemp LSB
  EndIf
  If Mode > 1 Then                      ' Save Hysteresis (Mode 2 -> Mode 0)       
   Mode=0                     ' Only 0, 1, 2 are valid
   Write 2, Hyst / 10                   ' Divide Hyst value to fit in Byte
  EndIf
EndIf


If Mode =0 then                        ' Set Target Temperature                  
  LcdOut $FE, $80, "Set Temp1       "   ' Show function
 
   V=TargetTemp                          ' TargetTemp in V 
  Gosub SelectSign                      ' Select +/blank/-
  Gosub DisplayTemp                     ' Display Target Temperature
  If (UP_B=0) Or (DOWN_B=0) then    ' Up or Down button pushed
   If DOWN_B=0 then                    ' Down button
    If TargetTemp > 7500 then           ' Not lower than -25 C. (10000-MinTemp * 100)
     TargetTemp=TargetTemp-25           ' Decrease temperuture with 0.25 C.
    EndIf
   EndIf
   If UP_B=0 then                    ' Up button
    If TargetTemp < 17500 then          ' Not higher than 75 C. (10000+MaxTemp * 100)
     TargetTemp=TargetTemp+25           ' Increase temperature with 0.25 C.
    EndIf
   EndIf
   GoSub SetTargetTemp                  ' Display TargetTemp and delay 0.25 Sec.
  EndIf
EndIf

If Mode=1 then                         ' Set Hysteresis                          
  LcdOut $FE, $80, "Hysteresys:     "   ' Show function
   Sign= " "                              ' No sign 
  V= 10000+Hyst                         ' Set value for V 
  Gosub DisplayTemp                     ' Display Hysteresis
  If (UP_B=0) Or (DOWN_B=0) then    ' Up or down button pushed 
   Sign= " "                             ' No sign for Hysteresis
   If DOWN_B=0 then                    ' Down button
    If Hyst > 10 then Hyst=Hyst-10      ' Not less than 0.1 C.
   EndIf
   If UP_B=0 then                    ' Up button
    If Hyst < 1000 then Hyst=Hyst+10    ' Not more than 10.0 C.
   EndIf
   V= 10000+Hyst                        ' Set value for V
   Gosub DisplayTemp                    ' Display Hysteresis
   Pause 250                            ' Delay 0.25 Sec.
  EndIf
EndIf

if Mode > 0 then Mainloop              ' Setting TargetTemperature or Hysteresis

 goto mainloop                         ' Check again
'-------------------------------------------------------------------------------



' SUBROUTINES:
'----------------------------------------
SelectSign:
If v = 10000 then                      ' Temperature = 0 C.
  Sign=" "             ' No sign
Else
  If v < 10000 then                 ' <> 0
   Sign="-"            ' Temperature below 0 C.   
  Else
   Sign="+"            ' Temperature above 0 C.
  EndIf
EndIf
Return
'----------------------------------------
DisplayTemp:
 If V >= 10000 then                     ' Above 0 C.      
  Temperature=V-10000                   
 Else                                   
  Temperature=10000-V                   ' Below 0 C. 
 EndIf
 LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",223,"C "
Return
'-----------------------------------------
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DisplayTemp
Pause 250
Return
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: skraceni kurs ucenja picbasica

Post by pedja089 »

Dodaj mode koji je isti kao mode 0, samo ubaci druge promenljive...
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Mode 0 je SET TEMP 2, Mode 1 je Hysteresys, znaci da dodam Mode 2 sa drugim promenjljivim za V i TargetTemp jel treba i ovo da menjam, i dodam?

Code: Select all

Read 0, B1                              ' Read TargetTemp MSB
Read 1, B2                              ' Read TargetTemp LSB
TargetTemp=B1*256+B2                    ' Calculate TargetTemp value (Default=20.0 C.)

Code: Select all

 Write 0, TargetTemp / 256      ' TargetTemp MSB
   Write 1, TargetTemp MOD 256          ' TargetTemp LSB
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7876
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: skraceni kurs ucenja picbasica

Post by pedja089 »

E jbg sad...
Sad mi nije nista jasno. Pitas kako da dodas temp2, a onda kazes da je vec imas u kodu...
A sta mislis dal mozes 2 promenljive cuvati na jednoj lokaciji...
Prouci malo kako radi kod, pa ce ti se samo reci.
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: skraceni kurs ucenja picbasica

Post by electron »

Ma sad sam ubacio al to jos uvek nije to

Code: Select all

 '-------------------------------------------------------------------------------

    OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit]    'Skip ROM search and write N_bits
                                                   '  resolution to scratch pad
    Read 0, B1                              ' Read TargetTemp MSB
    Read 1, B2                              ' Read TargetTemp LSB  
    TargetTemp=B1*256+B2                    ' Calculate TargetTemp value (Default=20.0 C.)
    Read 2, B1                              ' Read Hysteresis
    Hyst=10*B1                              ' Calculate Hysteresis value (Default= 2.0 C.)
    Read 3, B1                              ' Read TargetTemp MSB
    Read 4, B2                              ' Read TargetTemp LSB
    TargetTemp1=B1*256+B2                    ' Calculate TargetTemp value (Default=20.0 C.) 
    '-------------------------------------------------------------------------------
    MainLoop:
    If Mode_B=0 then                      ' Mode switch pressed
      Pause 50                              ' Debounce
      LcdOut $FE, $8F, "*"                  ' Show that command is accepted
      If Mode_B=0 then MainLoop            ' Wait until button is released
      Mode=Mode+1                           ' Increment mode
      If Mode=1 then                        ' Save Target Temperature (Mode1 -> Mode2)
       Write 0, TargetTemp / 256      ' TargetTemp MSB
       Write 1, TargetTemp MOD 256          ' TargetTemp LSB
      EndIf
      If Mode = 2 Then                      ' Save Hysteresis (Mode 2 -> Mode 0)       
      Write 3, TargetTemp / 256      ' TargetTemp MSB
      Write 4, TargetTemp MOD 256          ' TargetTemp LSB 
      
  EndIf
      If Mode > 2 Then                      ' Save Hysteresis (Mode 2 -> Mode 0)       
       Mode=0                     ' Only 0, 1, 2 are valid
       Write 2, Hyst / 10                   ' Divide Hyst value to fit in Byte
      EndIf
    EndIf

    If Mode =0 then                        ' Set Target Temperature                 
      LcdOut $FE, $80, "Set Temp1       "   ' Show function
     
       V=TargetTemp                          ' TargetTemp in V
      Gosub SelectSign                      ' Select +/blank/-
      Gosub DisplayTemp                     ' Display Target Temperature
      If (UP_B=0) Or (DOWN_B=0) then    ' Up or Down button pushed
       If DOWN_B=0 then                    ' Down button
        If TargetTemp > 7500 then           ' Not lower than -25 C. (10000-MinTemp * 100)
         TargetTemp=TargetTemp-25           ' Decrease temperuture with 0.25 C.
        EndIf
       EndIf
       If UP_B=0 then                    ' Up button
        If TargetTemp < 17500 then          ' Not higher than 75 C. (10000+MaxTemp * 100)
         TargetTemp=TargetTemp+25           ' Increase temperature with 0.25 C.
        EndIf
       EndIf
       GoSub SetTargetTemp                  ' Display TargetTemp and delay 0.25 Sec.
      EndIf
    EndIf
    
    If Mode =1 then                        ' Set Target Temperature                 
      LcdOut $FE, $80, "Set Temp2       "   ' Show function
     
       V=TargetTemp                          ' TargetTemp in V
      Gosub SelectSign                      ' Select +/blank/-
      Gosub DisplayTemp                     ' Display Target Temperature
      If (UP_B=0) Or (DOWN_B=0) then    ' Up or Down button pushed
       If DOWN_B=0 then                    ' Down button
        If TargetTemp > 7500 then           ' Not lower than -25 C. (10000-MinTemp * 100)
         TargetTemp=TargetTemp-25           ' Decrease temperuture with 0.25 C.
        EndIf
       EndIf
       If UP_B=0 then                    ' Up button
        If TargetTemp < 17500 then          ' Not higher than 75 C. (10000+MaxTemp * 100)
         TargetTemp=TargetTemp+25           ' Increase temperature with 0.25 C.
        EndIf
       EndIf
       GoSub SetTargetTemp                  ' Display TargetTemp and delay 0.25 Sec.
      EndIf
    EndIf


    If Mode=2 then                         ' Set Hysteresis                         
      LcdOut $FE, $80, "Hysteresys:     "   ' Show function
       Sign= " "                              ' No sign
      V= 10000+Hyst                         ' Set value for V
      Gosub DisplayTemp                     ' Display Hysteresis
      If (UP_B=0) Or (DOWN_B=0) then    ' Up or down button pushed
       Sign= " "                             ' No sign for Hysteresis
       If DOWN_B=0 then                    ' Down button
        If Hyst > 10 then Hyst=Hyst-10      ' Not less than 0.1 C.
       EndIf
       If UP_B=0 then                    ' Up button
        If Hyst < 1000 then Hyst=Hyst+10    ' Not more than 10.0 C.
       EndIf
       V= 10000+Hyst                        ' Set value for V
       Gosub DisplayTemp                    ' Display Hysteresis
       Pause 250                            ' Delay 0.25 Sec.
      EndIf
    EndIf

    if Mode > 0 then Mainloop              ' Setting TargetTemperature or Hysteresis

     goto mainloop                         ' Check again
    '-------------------------------------------------------------------------------



    ' SUBROUTINES:
    '----------------------------------------
    SelectSign:
    If v = 10000 then                      ' Temperature = 0 C.
      Sign=" "             ' No sign
    Else
      If v < 10000 then                 ' <> 0
       Sign="-"            ' Temperature below 0 C.   
      Else
       Sign="+"            ' Temperature above 0 C.
      EndIf
    EndIf
    Return
    '----------------------------------------
    DisplayTemp:
     If V >= 10000 then                     ' Above 0 C.     
      Temperature=V-10000                   
     Else                                   
      Temperature=10000-V                   ' Below 0 C.
     EndIf
     LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",223,"C "
    Return
    '-----------------------------------------
    SetTargetTemp:
    V=TargetTemp
    Gosub SelectSign
    Gosub DisplayTemp
    Pause 250
    Return
Na koje si tacno mislio promenljive?
Post Reply