skraceni kurs ucenja picbasica

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

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

Pozdrav svima dali mi neko moze pomoci u pravljenu ovog uredjaja,treba da radi sledece:
kad se stisne jedan taster da upali osam ledica jednu za drugom
a kad se stisne drugi taster da upali drugih osam ledica jednu za drugom u proteusu radi idealno a na napravljenom uredaju nece
moze li mi neko reci gde gresim:
kad vezem osiloskop na data pin nema nikakvih oscilacija

Code: Select all

 #CONFIG 
     __CONFIG  _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF  & _BOD_OFF & _CP_OFF & _PWRTE_ON
    #ENDCONFIG
    DEFINE OSC 4
  Include "modedefs.bas"  ' Pozivanje moda sift registra

'-------------------------- PDESAVANJA -------------------------------
    
    ANSEL = $30
    WPU = $37
    
    CMCON0 = 7                ' Analog comparators off

    TRISIO = %110000          '5-ULAZ
 
 '---------------------- definicije sift recistra-----------------------  
      
 gore var GPIO.4
 dole var GPIO.5 
 stanje var GPIO.3
 INPUT stanje
   'DEFINICIJA PINOVA ZA SIFT REGISTER
'***************************************************   
DataPin var     GPIO.0         ' Shift data pin 0  *
ClkPin  var     GPIO.1         ' Shift clock pin 1 *
Strobe  var     GPIO.2   'PUSTA BBOJ KROZ REGISTAR *
'***************************************************

Strobe = 0

x var word
y var word
x1  var word
y1 var word

x1=0
y1=0
x = 0  'GORE 
y = 0  'DOLE
I VAR BYTE

PAUSE 500
pocetak:
'**************PODIZE**************************

if stanje=0 then podize
if stanje=1 then spusta

podize:
y=0
DO while gore = 1 
loop



do while gore = 0 
loop

x=1
CALL IZLAZ
for i = 1 to 7
x=x*2
call izlaz 
next i
'*************SPUSTA***************
spusta:

x=0
do while dole = 1 
loop


do while gore = 0
loop
y=1
call izlaz


for i = 1 to 7
y=y*2
call izlaz
next i
goto podize
'*********************************************





izlaz:
x1=x
y1=y

Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
pause 500
'*****************STAVLJA GA NA NULU*******************

X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
pause 500


return        
End
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

video sam gresku biloje:
TRISIO = %110000
prepravio sam na TRISIO = %111000
al opet neradi
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

Sad sam probao samo da palim i gasim dve led diode ni to neradi na uredjaju,svi cipovi imaju napon i sve sto treba moze li mi neko reci gde gresim

Code: Select all

#CONFIG 
     __CONFIG  _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF  & _BOD_OFF & _CP_OFF & _PWRTE_ON
    #ENDCONFIG
    DEFINE OSC 4
  Include "modedefs.bas"  ' Pozivanje moda sift registra
 'DEFINE SHIFT_PAUSEUS 1000
'-------------------------- PDESAVANJA -------------------------------
    
    ANSEL = $30
    WPU = $37
    
    CMCON0 = 7                ' Analog comparators off

    TRISIO = %111000          '5-ULAZ
 
 '---------------------- definicije sift recistra-----------------------  
      
 gore var GPIO.4
 dole var GPIO.5 
 stanje var GPIO.3
 INPUT stanje
   'DEFINICIJA PINOVA ZA SIFT REGISTER
'***************************************************   
DataPin var     GPIO.0         ' Shift data pin 0  *
ClkPin  var     GPIO.1         ' Shift clock pin 1 *
Strobe  var     GPIO.2   'PUSTA BBOJ KROZ REGISTAR *
'***************************************************

Strobe = 0

x var byte
y var byte
x1  var byte
y1 var byte

x1=0
y1=0
x = 0  'GORE 
y = 0  'DOLE
I VAR BYTE

'PAUSE 500

 izlaz:
do
x1=1
y1=1


Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
pause 500
'*****************STAVLJA GA NA NULU*******************

X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
pause 500

  loop


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 »

Za pocetak proveri da li imas sta treba na data i clock pinovima. Probaj samo HIGH LOW pin. Pa odatle kreni dalje... Mozda ti PIC uopste i ne radi... Verovatno si omanuo kod osccal vrednosti. Mozda si omanuo kod programiranja pica. Ima milion i jedan razlog zasto nece da radi.

Drugo proveri chipove, izbaci pic, ubaci tastere sa pull up, pa probaj rucno da ushiftujes nesto.
Da je sve dobro radilo bi bez problema.
Ti pricas da nema oscilacija na data pinu, kakvih ba oscilacija? Kreni redom, od treperenja led, pa nadalje na tom PIC-u. Mozes i staviti da oscilator bude interni sa clockoutom na nekom pinu, pa da vidis da li ti uopste radi i oscilator. Itd itd... A semu nisi ni postavio, a ocekujes neku konkretniju pomoc...
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

napisao mi je drugar test kod u protonu i sa njim radi,dali neko moze da mi kaze gde je greska u mom kodu
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

Zahvaljujem se na pomoci resio sam problem.pozdrav svima
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 »

Jos da si napisao gde je problem, pa da i mi znamo...
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

Problem je bio u definiciji evo ovaj cod radi:

Code: Select all

 #CONFIG 
     __CONFIG  _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF  & _BOD_OFF & _CP_OFF & _PWRTE_ON
 #ENDCONFIG
 DEFINE OSC 8
' Include "modedefs.bas"            ' Pozivanje moda sift registra
' Shiftout Modes
Symbol LSBFIRST = 0     ' LSB first
Symbol MSBFIRST = 1     ' MSB first
DEFINE SHIFT_PAUSEUS 100
'-------------------------- PDESAVANJA --------------
        ANSEL = 0        ' Set all digital
        CMCON0 = 7       ' Analog comparators off
        WPU = 0 '??????????
     TRISIO     = %00111000  ' TRISIO     = %111000     '012-Izlaz 345 Ulaz
        OPTION_REG = %11000000
'        ANSEL      = %00000000     ' select all digital
        OSCCON     = %01110101     ' 8Mhz
'        CMCON0     = %00000111     ' disable comparator
      
 
 
 
 
 
 gore var GPIO.4
 dole var GPIO.5 
 stanje var GPIO.3
 INPUT stanje
   'DEFINICIJA PINOVA ZA SIFT REGISTER
'***************************************************   
DataPin var     GPIO.0         ' Shift data pin 0  *
ClkPin  var     GPIO.1         ' Shift clock pin 1 *
Strobe  var     GPIO.2   'PUSTA BBOJ KROZ REGISTAR *
'***************************************************

Strobe = 0

x var byte
y var byte
x1  var byte
y1 var byte

x1=0
y1=0
x = 0  'GORE 
y = 0  'DOLE
I VAR BYTE

Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10

;PAUSE 500
pocetak:
'**************PODIZE**************************

if stanje=0 then goto podize
if stanje=1 then goto spusta

podize:
y=0
DO while gore = 1 

'*****************STAVLJA GA NA NULU*******************
X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
'************************************************************
loop



do while gore = 0 
'*****************STAVLJA GA NA NULU*******************
X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
'************************************************************

loop

x=1
gosub IZLAZ
for i = 1 to 7
x=x*2
gosub izlaz 
next i
'*************SPUSTA***************
spusta:

x=0
do while dole = 1 
'*****************STAVLJA GA NA NULU*******************
X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
'************************************************************

loop


do while gore = 0
'*****************STAVLJA GA NA NULU*******************
X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
'************************************************************
loop
y=1
gosub izlaz


for i = 1 to 7
y=y*2
gosub izlaz
next i
goto podize
'*********************************************





izlaz:
x1=x
y1=y

Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
pause 500
'*****************STAVLJA GA NA NULU*******************
X1=0
Y1=0 
Shiftout DataPin, ClkPin, MSBFIRST,[Y1,X1]'PRVI BROJ JE ZADNJI SHIFT REGISTAR 
Pulsout Strobe,10
'************************************************************
pause 500


return        
End
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

molim malu pomoc oko GPIO.3 ili mclr nogice treba da bude ulazna a to nikako nemogu dobiti negde u podesavanju je greska moze li mi neko pomoci evo koda koji sam za test iskucao kad se stisne taster treba da upali led a kad se opet stisne treba da ga ugasi

Code: Select all

 #CONFIG 
     __CONFIG  _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF  & _BOD_OFF & _CP_OFF & _PWRTE_ON
    #ENDCONFIG
    DEFINE OSC 4


'-------------------------- PDESAVANJA -------------------------------
         
    ANSEL = $30
    WPU = $37
    
    CMCON0 = 7                ' Analog comparators off
      ANSEL      = %00000000     ' select all digital
        OSCCON     = %01110101     ' 8Mhz  
    TRISIO = %111100      
     '------------------------PROOGRAM------------------------------------        
 
   'DEFINMISANJE PORTOVA
    symbol otvara = GPIO.0      
    LOW otvara
    
    symbol zatvara = GPIO.1
    low zatvara
    
    symbol komanda1 = GPIO.2
    input komanda1
   
    symbol komanda2 = GPIO.3
    input komanda2
    
    
    symbol magnet1 = GPIO.4
   
     input magnet1
     
     
     symbol magnet2 = GPIO.5
     input magnet2
     
     
     
     pocetak:
     
     do while komanda2 = 1   ;ceka stiskanje tastera
     loop
     do while komanda2=0                    ;vrti dok je stisnut taster
     loop
     
     otvara = 1   ;pali led
    pause 500 
     
     
     do while komanda2=1  ' ceka dok je taster stisnut
     loop
     
     otvara = 0   'gasi led
    
    do while komanda2=0    'ceka dok je taster stisnut
    loop                   
    
    
     goto pocetak
     
alarmi ns
Penjem se :)
Penjem se :)
Posts: 54
Joined: 29-06-2013, 20:13

Re: skraceni kurs ucenja picbasica

Post by alarmi ns »

rec je o picu 12f687
User avatar
milan-markovic
Pocetnik na forumu
Pocetnik na forumu
Posts: 34
Joined: 24-05-2014, 10:54
Location: Aleksinac

Re: skraceni kurs ucenja picbasica

Post by milan-markovic »

Zdravo drugari od nedavno sam poceo da ucim programiranje pic-basicom.
Kupio sam i mini ravojni sistem koji je napravio Radanocevic Sinisa sa mikrokontrolerom Pic 16f1827.
E sad je meni problem da mi neko detaljno objasni kako se radi AD konverzija.Evo jednog coda koji sam ja pola prepisao iz nekih primera ono sto mi nije bilo jasno i to nekako radi cod je za citanje napona sa potenciometra i prikaz na displeju 2x16 .

Code: Select all

#CONFIG
 __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
 __config _CONFIG2, _WRT_ALL & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF 
#ENDCONFIG


define OSC 4
define LCD_DREG PORTB  'LCD data port
define LCD_DBIT 4      'LCD pocetni bit podatka o ili 4     

define LCD_RSREG PORTA  'LCD registar select port
define LCD_RSBIT 1      'LCD registar select bit
define LCD_EREG PORTA   'LCD enable port
define LCD_EBIT 3       'LCD enable bit
Define	ADC_BITS	10	' Broj bita
Define	ADC_CLOCK	3	' Klok (1=Oscilator /8)
 inic:
    OSCCON=%01101000 
    OPTION_REG = %00000100 
    fvrcon=%10000011
    ansela=%00000001
    adcon0=%00000001
    adcon1=%10110011
    TRISA=%11110101   ' Port A je ulazni osim RA1 i RA3
    TRISB=%00000000   ' Port B je izlazni
    
    AD_Rez var	word	' Rezultat AD konverzije 
    Napon  var	word	' Promenljiva za dobijanje napona 
    Dummy  var word     ' Promenljiva za 32 bitno delenje i mnozenje
 
        Pause 500           ' Pauza 0.5 sec
        Lcdout $fe, 1		' Izbrisi ceo LCD displej
	    Lcdout $fe, 2		' Pozicioniraj se na prvi red prvi karakter
        Lcdout "      PRIMER   " ' Ispisi "PRIMER" u prvom redu
	    Lcdout $fe, $C0	    ' Podesi kursor na pocetak drugog reda
  	    Lcdout " A/D KONVERTORA" ' Ispisi dati tekst u drugom redu 
        Pause 5000           ' Pauza 5 sec
       
Pocetak:	

            '   Procitaj 1 kanal na RA0 i prikazi
      
        Lcdout $fe, 1		' Izbrisi ceo LCD displej
	    Lcdout $fe, 2		' Pozicioniraj se na prvi red prvi karakter
        Lcdout " A/D kanal br.1" ' Ispisi “A/D kanal br.1 u prvom redu

        ADCIN 0, AD_Rez   	' Izvrsi konverziju na RA0 i 10 bita rezultata smesti u AD_Rez.
	    Lcdout $fe, $C0	    ' Podesi kursor na pocetak drugog reda
        Dummy = AD_Rez * 5 * 100
        Napon = Div32 1024
        Lcdout $fe, $C0	    ' Podesi kursor na pocetak drugog reda
  	    Lcdout "   Napon:",DEC napon,",",dec1 napon,"V" ' Ispisi vrednost na displeju                                      
  	    Pause 500		    ' Pauza 0.5 sec
     

        Goto Pocetak	    ' Kreni ponovo na merenje

	    End		            ' Kraj programa
Sada bih zamolio nekog da mi objasni kako se podesavaju registri :
OSSCON
OPTION_REG
fvrcon
adcon0
adcon1

Predpostavljam da se ovi registi podesavaju iz datasheet ali meni nije jasno da se snadjem u datasheet i kako da podesim referentni napon.
Znam da je ovako referentni napon podesen 5v prilozicu i datasheet pa da mi neko to natenane objasni kako da koristim datasheet.

Pozdrav i hvala unapred
User avatar
milan-markovic
Pocetnik na forumu
Pocetnik na forumu
Posts: 34
Joined: 24-05-2014, 10:54
Location: Aleksinac

Re: skraceni kurs ucenja picbasica

Post by milan-markovic »

Evo prilazem i datasheet za navedeni kontroler i da napomenem da koristim picbasic pro compajler i okrizenje micro code studio.

http://ww1.microchip.com/downloads/en/D ... 41391D.pdf
User avatar
milan-markovic
Pocetnik na forumu
Pocetnik na forumu
Posts: 34
Joined: 24-05-2014, 10:54
Location: Aleksinac

Re: skraceni kurs ucenja picbasica

Post by milan-markovic »

Drugari ima li ko volje da mi objasni ovaj problem koji sam naveo.

Pozdrav
_heX
Napredujem
Napredujem
Posts: 136
Joined: 29-10-2009, 20:09
Location: Republika Zagorje

Re: skraceni kurs ucenja picbasica

Post by _heX »

Kako da koristis datasheet? Lijepo ga uzmes i citas, kao knjigu jebiga...

Inace ovaj tvoj kod za referencu koristi 4.096V (4x 1.024). To vidis iz toga sto je FVRCON dodjeljena vrijednost b'10000011' (prvi bit ukljucuje FVR modul, a zadnja dva odredjuju napon; strana 136 u datasheetu) i sto su zadnja dva bita vrijednosti dodjeljene ADCON1 postavljenja u visoko - pozitivna referenca ADC-a je izlaz iz FVR-a (strana 146 u datasheet-u).
Takt kontroleru daje interni oscilator (CONFIG direktiva _FOSC_INTOSC) i namjesten je na 4MHz-a (OSCON registar - strana 65).
Kako ADC kod PIC-a radi imas objasnjeno na 29 strani ovog podforuma...
User avatar
milan-markovic
Pocetnik na forumu
Pocetnik na forumu
Posts: 34
Joined: 24-05-2014, 10:54
Location: Aleksinac

Re: skraceni kurs ucenja picbasica

Post by milan-markovic »

Hvala vam puno na objasnjenju sada mi je dosta jasno i shvatio sam kako se podesavaju registri iz datasheet.

Citao sam ja datasheet ali nisan znao kako se podesavaju sada sam shvatio sta da se radi nisam imao nikog drugog da pitam da mi sve to objasni a totalni sam pocetnik u ovome tako da nemojte da uzimate za zlo ako pitam neke banalne stvari prvi put se susrecem sa ovim .

Pozdrav
cheko
Posts: 6
Joined: 14-04-2011, 22:04

Re: skraceni kurs ucenja picbasica

Post by cheko »

Pozdrav svima: Na ovom forumu sam naucio dosta o pic mikrokontrolerima i picbasicu i sada imam jedan problem sa i2c i vb6 . Zapravo zeleo bih da u 24cXX na prvu adresu upisem jedan broj od 1-9 preko com porta.Slabo poznajem vb6 i na netu nisam mogao da nadjem takav jednostavan primer u vb6.Ako neko moze da pomogne bio bih zahvalan.Bilo kakva pomoc u vidu primera ili gde mogu da kupim knjigu sa takvim primerima,ili link za tako nesto.Hvala
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 »

Ovaj kod za podesavanje vrednosti temperatura ne radi dobro.
-Kad ukljucim prikaze mi prazan lcd tek kad stisnem mode_B pojavi se set temp
-prelaz izmedju set temp i hysteresys je OK
-a da vratim izmedju hyteresis i set temp opet moram dva puta da stisnem
Sta ne valja?

Code: Select all

clear
DEFINE OSC 8                '8MHz << NOTICE UPPERCASE ON DEFINE

 'END of timer/oscillator defines

 OSCCON = %01110001          'Int CLK 8MHz
 ANSEL = %00000000           'All digital
 ANSELH = %00000000
 OPTION_REG.7 = 1            'Weak pull-ups enabled

DEFINE  LCD_DREG    PORTD  'I/O port na kome se nalazi LCD
DEFINE  LCD_DBIT    4       
DEFINE  LCD_RSREG   PORTD
DEFINE  LCD_RSBIT   1     'Register select pin
DEFINE  LCD_EREG    PORTD
DEFINE  LCD_EBIT    0     'Enable pin
DEFINE  LCD_BITS    4     '4-bitni data bus 
DEFINE  LCD_LINES   2      'LCD ima dva reda karaktera

DEFINE BUTTON_PAUSE 100
    
'*****************************************************************************
'Pinout for EasyPic5

   
  
    
    
    Mode_B         Var PORTB.0    'podesi
    UP_B         Var PORTB.2    'podesi
    DOWN_B         Var PORTB.1     'podesi
    
    
    symbol MO=PORTB.0   'Taster automatski SET/ENTER/MODE  
    symbol DN=PORTB.1   '   UP                 
    symbol UP=PORTB.2   '   DOWN              
    symbol ST=PORTB.3   'Taster start/stop

'*****************************************************************************

TRISB= %00001111                    ' RB0..RB2=Inputs, RB3..RB7=Outputs      

' 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

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

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


Mode=0                                  ' Temperature display mode
Twist = 0  
PAUSE 500
LCDOUT $FE, 1, $FE, $0C                 ' Clear display, cursor off
PAUSE 250



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=2 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) 
   Mode=0                     ' Only 0, 1, 2 are valid
   Write 2, Hyst / 10                   ' Divide Hyst value to fit in Byte
  EndIf
EndIf

If Mode =1 then                        ' Set Target Temperature
  LcdOut $FE, $80, "Set Temp.       "   ' 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, $C6,$06
lcdout $fe, $70, $C,$12,$12,$C,$0,$0,$0,$0

lcdout $fe, $C7,"C"
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature

Return

'-----------------------------------------
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DisplayTemp 
Pause 250
Return

'-----------------------------------------
END
  
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 »

Nedostaje ti u petlji Mode = 0

Code: Select all

clear
DEFINE OSC 8                '8MHz << NOTICE UPPERCASE ON DEFINE

 'END of timer/oscillator defines

 OSCCON = %01110001          'Int CLK 8MHz
 ANSEL = %00000000           'All digital
 ANSELH = %00000000
 OPTION_REG.7 = 1            'Weak pull-ups enabled

DEFINE  LCD_DREG    PORTD  'I/O port na kome se nalazi LCD
DEFINE  LCD_DBIT    4       
DEFINE  LCD_RSREG   PORTD
DEFINE  LCD_RSBIT   1     'Register select pin
DEFINE  LCD_EREG    PORTD
DEFINE  LCD_EBIT    0     'Enable pin
DEFINE  LCD_BITS    4     '4-bitni data bus 
DEFINE  LCD_LINES   2      'LCD ima dva reda karaktera

DEFINE BUTTON_PAUSE 100
    
'*****************************************************************************
'Pinout for EasyPic5

   
  
    
    
    Mode_B         Var PORTB.0    'podesi
    UP_B         Var PORTB.2    'podesi
    DOWN_B         Var PORTB.1     'podesi
    
    
    symbol MO=PORTB.0   'Taster automatski SET/ENTER/MODE  
    symbol DN=PORTB.1   '   UP                 
    symbol UP=PORTB.2   '   DOWN              
    symbol ST=PORTB.3   'Taster start/stop

'*****************************************************************************

TRISB= %00001111                    ' RB0..RB2=Inputs, RB3..RB7=Outputs      

' 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

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

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


Mode=0                                  ' Temperature display mode
Twist = 0  
PAUSE 500
LCDOUT $FE, 1, $FE, $0C                 ' Clear display, cursor off
PAUSE 250



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=2 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) 
   Mode=0                     ' Only 0, 1, 2 are valid
   Write 2, Hyst / 10                   ' Divide Hyst value to fit in Byte
  EndIf
EndIf

'--------------------- NEDOSTAJE TI MODE=0 ZA PRIKAZ TEKUĆE TEMPERATURE --------
if mode=0 then
    LcdOut $FE, $80, "Temperature     "   ' Show function
    V=12000                               ' Temperatura fiksirana na 20 stupnjeva
'    V=Temperature                         ' Za prikaz trenutne temperature
    Gosub SelectSign                      ' Select +/blank/- 
    Gosub DisplayTemp                     ' Display Target Temperature
endif
'-------------------------------------------------------------------------------

If Mode =1 then                        ' Set Target Temperature
  LcdOut $FE, $80, "Set Temp.       "   ' 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, $C6,$06
lcdout $fe, $70, $C,$12,$12,$C,$0,$0,$0,$0

lcdout $fe, $C7,"C"
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature

Return

'-----------------------------------------
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DisplayTemp 
Pause 250
Return

'-----------------------------------------
END
 
Cezare, star sam i nemoćan, ali poslušaj moj savjet ....
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 »

Sad radi...
Boss71
Posts: 16
Joined: 09-03-2015, 18:54

Re: skraceni kurs ucenja picbasica

Post by Boss71 »

Pozdrav svima,

Želeo bih i ja da imam PBP3 gold, - ako može medicina na 24h ...
Post Reply