Citiram: |
Vezje z eno tipko ki bi ob vsakem pritisku naredila nekaj. |
Citiram: |
Kje bi dobil seznam ukazov?v kakšni tabeli z kakšno majhno razlago zravn? |
Citiram: |
Še eno vprašanje.A se s tem čipom da naredit da led dioda recimo postopoma prizge?da bi izhod višal napetost? |
Citiram: |
If tipka = 0
Goto nekaj End If |
RGorazd je napisal/a: |
seznam ukazov v Bascomu dobiš s pritiskom na eno tipko:
do If F1 = 1 then Print HELP End if loop ... LP G |
Koda: |
AREF:
AREF is the analog reference pin for the A/D Converter. Operation: The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB. Optionally, AVCC or an internal 2.56V reference voltage may be connected to the AREF pin by writing to the REFSn bits in the ADMUX Register. The internal voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve noise immunity. |
Koda: |
'Config Adc = Single , Prescaler = Auto, Reference = Internal 'The reference param may be : 'OFF : AREF, internal reference turned off 'AVCC : AVCC, with external capacitor at AREF pin 'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin |
program_er je napisal/a: |
Aja, pa na feri so mi pravli, da je v enem primeru rezultat ADC-ja izražen v mili voltih. Je to res? |
Koda: |
– 8-channel, 10-bit ADC 8 Single-ended Channels 7 Differential Channels in TQFP Package Only 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x |
Koda: |
– 8-channel, 10-bit ADC 8 Single-ended Channels |
Koda: |
ADC Running mode. May be SINGLE or FREE. PRESCALER A numeric constant for the clock divider. Use AUTO to let the compiler generate the best value depending on the XTAL REFERENCE The options depend on the used micro. Some chips like the M163 have additional reference options. In the definition files you will find : ADC_REFMODEL = x This specifies which reference options are available. The possible values are listed in the table below. ----------------------------------------------------------------------------------------------- 'The newer has options for the reference voltage 'For those chips you can use the additional param : 'Config Adc = Single , Prescaler = Auto, Reference = Internal 'The reference param may be : 'OFF : AREF, internal reference turned off 'AVCC : AVCC, with external capacitor at AREF pin 'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin |
Koda: |
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function 'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128 'Because the ADC needs a clock from 50-200 KHz 'The AUTO feature, will select the highest clockrate possible Config Adc = Single , Prescaler = Auto 'Now give power to the chip Start Adc 'With STOP ADC, you can remove the power from the chip 'Stop Adc Dim W As Word , Channel As Byte Channel = 0 'now read A/D value from channel 0 Do W = Getadc(channel) Print "Channel " ; Channel ; " value " ; W Loop |
Koda: |
Dim W2 as word
w2 = w * 50 w2 = w2 / 1024 print W2 |
Koda: |
dim volti as word
dim desetinke as word volti = W2 / 10 desetinke = W2 mod 10 print "Napetost je ";volti;".";desetinke;"V " |
vilko je napisal/a: |
A, ti nas tako, hipotetično .. |
Citiram: |
Data Types
Every variable in BASCOM has a data type that determines what can be stored in the variable. The next section summarizes the elementary data types. Elementary Data Types Bit (1/8 byte). A bit can hold only the value 0 or 1. A group of 8 bits is called a byte. Byte (1 byte). Bytes are stores as unsigned 8-bit binary numbers ranging in value from 0 to 255. Integer (two bytes). Integers are stored as signed sixteen-bit binary numbers ranging in value from -32,768 to +32,767. Word (two bytes). Words are stored as unsigned sixteen-bit binary numbers ranging in value from 0 to 65535. Long (four bytes). Longs are stored as signed 32-bit binary numbers ranging in value from -2147483648 to 2147483647. Single. Singles are stored as signed 32 bit binary numbers. Ranging in value from 1.5 x 10^–45 to 3.4 x 10^38 Double. Doubles are stored as signed 64 bit binary numbers. Ranging in value from 5.0 x 10^–324 to 1.7 x 10^308 String (up to 254 bytes). Strings are stored as bytes and are terminated with a 0-byte. A string dimensioned with a length of 10 bytes will occupy 11 bytes. |
vilko je napisal/a: |
Odgovor na zadnje vprašanje je 1024 |
rene_9 je napisal/a: |
Error:7 Line:67 IF THEN expectet[67]
Error:269 Line:67 END SELECT expectet Program ja je sledeč: $regfile = "m8515.dat" $crystal = 12000000 Config Debounce = 40 Dim Stevec As Byte Config Porta = Input Config Portb = Output Tipka1 Alias Pina.0 Led1 Alias Portb.0 Led2 Alias Portb.1 Zacetek: Do Debounce Tipka1 , 0 , Vklop Loop Vklop: Incr Stevec If Stevec = 3 Then Stevec = 0 End If Goto Izbira ' tega ni treba Izbira: Select Case Stevec Case 0 : Goto Prog1 Case 1 : Goto Prog2 Case 2 : Goto Prog3 Prog1: Set Led1 Goto Zacetek Prog2: Reset Led1 Wait 1 Set Led1 Wait 1 Set Led2 Goto Zacetek Prog3: Set Led2 Wait 1 Set Led1 Wait 1 Goto Zacetek |
Koda: |
Each device has a unique 64-bit serial code stored in an onboard ROM |
vilko je napisal/a: |
če pa imaš na viru, ki ga želiš meriti višjo napetost, potem jo enostavno z uporovnim delilnikom, ki ga narediš sam, in potemtakem njegovo delitev napetosti poznaš, deliš tako, da bo izhod iz uporovnega delilnika nižja od referenčne. |
program_er je napisal/a: |
Ima kdo kakšen načrt za uporovni delilnik in kako ploh deluje? Ali ni to enako kot en enostaven upor? |
Koda: |
$regfile = "m16def.dat"
$crystal = 1000000 Config Portc.6 = Output Config Lcd = 16 * 2 Config Lcdbus = 4 Config Lcdpin = Pin , Db7 = Portc.0 , Db6 = Portc.1 , Db5 = Portc.2 , Db4 = Portc.3 , E = Portc.4 , Rs = Portc.5 Cursor Off Osvetlitev Alias Portc.6 Do Cls Osvetlitev = 1 Waitms 200 Lcd "Podravljen!" Lowerline Waitms 500 Lcd "LCD deluje!" Wait 1 Osvetlitev = 0 Waitms 500 Osvetlitev = 1 Waitms 500 Osvetlitev = 0 Loop End |
int47 je napisal/a: |
LCD ni (pravilno) inicializiran. Problem je lahko v SW, ali HW.
-Mogoče je v Basic-u potrebno uporaiti ukaz za inicializacijo LCD-ja? -Poglej, če je vse prav zvezano. Kam je priklopljen R/W LCD-ja? -Poglej, če si pravilno definiral signale. -Preveri, če je nastavljena hitrost uC-ja pravilna. -Preveri, če je napajalna napetost v (za LCD) ustreznih tolerancah. |
vilko je napisal/a: |
Lahko je tudi vrag v mikroprocesorjivih krmilnih bitih fuse bitih in jtag bitih.
Le ti lahko nekatere portpine odvzamejo in dajo portpinom čisto druge funkcije. Oglej si datasheet. Izvleček! Port Pin Alternate Function PC7 TOSC2 (Timer Oscillator Pin 2) PC6 TOSC1 (Timer Oscillator Pin 1) PC5 TDI (JTAG Test Data In) PC4 TDO (JTAG Test Data Out) PC3 TMS (JTAG Test Mode Select) PC2 TCK ( J TAG Te s t Cl ock ) PC1 SDA (Two-wire Serial Bus Data Input/Output Line) PC0 SCL (Two-wire Serial Bus Clock Line) vse te 'alternativne' funkcije je potrebno onemogočiti, (disablirati po slovensko) |
Pobesneli je napisal/a: |
Nevem če je krivo...samo meni se zdi da ima ukaz waitms največjo vrednost 255 ? |
program_er je napisal/a: |
LCD sem vezal na port A in deluje odlično!
Glede waitms: včasih sem imel wait ukaze nastavljene tudi do Waitms 1250 pa je vse normalno delovalo. Še dokaj točno je blo! |
Koda: |
Config Lcd = 16 * 2 |
vilko je napisal/a: |
Sicer nimam Viste, a prepričan sem, da ima tak pogled tudi Vistin kalkulator, le na 'pulldown' meniju Pogled moraš izbrati šestnajtiški pogled. |
program_er je napisal/a: |
Dobil sem LCD-je od Nokie 3310. Pa sem se znašem pred nekaj težavami, kajti jaz sem mislil, da se bo to podobno priključilo kot 16*2 LCD.
Gledal sem tole spletno stran in videl, da sta na mikrokontroler povezana samo 2 ali 3 pini. |
int47 je napisal/a: |
šestnajstiško = HEX
dvojiško = BIN Edit: Izbrisna slika. Vidim, da si že našel. |
int47 je napisal/a: |
Na sliki nista dva 4,7uF elektrolitska kondenzatorja. |
Pobesneli je napisal/a: |
malo poglej po datashetih ne? |
Koda: |
config portb.0=output ddrb=255 do portb.0 = 1 waitms 1 'spreminjaš dolžino intervala portb.0=0 loop |
Citiram: |
Nastavil sem fuse bits: High: EA -- Low: 99 |
Citiram: |
Če pa še to ne bo zaleglo,potem pa te res reši samo še pararelni programator. |
Koda: |
$regfile = "m16def.dat" $crystal = 1000000 Config Portd.6 = Output Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portd.0 , Db6 = Portd.1 , Db5 = Portd.2 , Db4 = Portd.3 , E = Portd.4 , Rs = Portd.5 Cursor Off Osvetlitev Alias Portd.6 Config Adc = Single , Prescaler = Auto , Reference = Internal Start Adc Dim W As Word , Channel As Byte Channel = 0 'now read A/D value from channel 0 Do W = Getadc(channel) Cls Home U Lcd "ADC:" ; Channel ; " = " ; W Wait 1 Incr Channel If Channel > 4 Then Channel = 0 Loop End 'The new M163 has options for the reference voltage 'For this chip you can use the additional param : 'Config Adc = Single , Prescaler = Auto, Reference = Internal 'The reference param may be : 'OFF : AREF, internal reference turned off 'AVCC : AVCC, with external capacitor at AREF pin 'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin 'Using the additional param on chip that do not have the internal reference will have no effect. End |
Koda: |
$regfile = "m16def.dat" $crystal = 1000000 Enable Adc Config Portd.6 = Output Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portd.0 , Db6 = Portd.1 , Db5 = Portd.2 , Db4 = Portd.3 , E = Portd.4 , Rs = Portd.5 Cursor Off Osvetlitev Alias Portd.6 Osvetlitev = 1 Config Adc = Single , Prescaler = Auto , Reference = Off Start Adc Dim W As Word , Rz As Word , Kp As Word , Rezultat As Single , Channel As Byte Channel = 0 'now read A/D value from channel 0 'Aha, se pravi da je pri 10-bitnem ADC-ju račun takšen: '&H80 = W <--neka cifra (če mi to vrže v programu) 'W x referenčna napetost = Rz 'Rz x 1000 (ne 10) = Kp 'Kp : 1024 = Mv Do W = Getadc(channel) Rz = W * 5.05 Kp = Rz * 1000 Rezultat = Kp / 1024 Gosub Prikaz Incr Channel If Channel > 3 Then Channel = 0 Loop Prikaz: Cls Home U Lcd "ADC:" ; Channel ; " = " ; Rezultat Wait 1 Return End 'The new M163 has options for the reference voltage 'For this chip you can use the additional param : 'Config Adc = Single , Prescaler = Auto, Reference = Internal 'The reference param may be : 'OFF : AREF, internal reference turned off 'AVCC : AVCC, with external capacitor at AREF pin 'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin 'Using the additional param on chip that do not have the internal reference will have no effect. |
vilko je napisal/a: | ||
...
In če hočeš napisati rezultat kot 5.0V potem moraš še ločiti desetinke od celih voltov v dve ločeni spremenljivki
Najbolje je, da probaš. |
Koda: |
Config Adc = Single , Prescaler = Auto , Reference = Internal Start Adc Dim W As Word , Rz As Word , Kp As Word , Rezultat As Word , Channel As Byte , Volti As Word , Desetinke As Word Channel = 0 Do W = Getadc(0) Rz = W * 5.45 Kp = Rz * 10 Rezultat = Kp / 1023 Volti = Rezultat / 10 Desetinke = Rezultat Mod 10 Gosub Prikaz Loop Prikaz: Cls Home U Lcd "ADC = " ; Volti ; "." ; Desetinke ; " V" Lowerline Lcd "ADC izvir:" ; W Waitms 500 Return End |
Koda: |
dim volti as word
dim desetinke as word volti = W2 / 10 desetinke = W2 mod 10 print "Napetost je ";volti;".";desetinke;"V " |
Koda: |
dim volti as word
dim stotinke as word volti = W2 / 100 stotinke = W2 mod 100 print "Napetost je ";volti;".";stotinke;"V " |
Koda: |
Do W = Getadc(0) Rz = W * 5.45 Kp = Rz * 10 Rezultat = Kp / 1023 ' Rezultat = Rezultat * 10 Volti = Rezultat / 10 ' Rezultat / 100 Desetinke = Rezultat Mod 10 'Mod 100 If W > 600 Then Portc.7 = 0 If W < 600 Then Portc.7 = 1 Gosub Prikaz If W > 600 Then Portc.7 = 0 If W < 600 Then Portc.7 = 1 Loop Prikaz: Home U Lcd "ADC = " ; Volti ; "." ; Desetinke ; " V" Lowerline Lcd "ADC izvir:" ; W Waitms 300 Return End |
poule je napisal/a: |
v dokumentaciji za razvojno plato pa imam napisano:
konektor K6: RST pin3 MOSI pin 8 MISO pin9 SCKpin10 GND pin2 Kako je pravilno? |
poule je napisal/a: |
A je kdo iz Ljubljane, ki uporablja minipin in sample programator in bi mi naklonil nekaj minut ob kavi, da prečekirava moje nastavitve in programator. |
program_er je napisal/a: |
A se da v Bascomu kaj podobnega naret z timerji? Me lahko kdo nauči? Ker timerjev še nikoli nisem uporabljal! Hvala! |
Pobesneli je napisal/a: |
Kje bi dobil jaz fajl attiny2313.dat? |
program_er je napisal/a: |
Obstajajo kaki gonilniki za računalnik, da bi sprejel podatke preko USB? |
Koda: |
' BOJAN POTOČNIK '******************************************************************************* '--------------- MERITEV TEMPERATURE Z DS18B20+ IN IZPIS NA LCD ---------------- '******************************************************************************* '******************************* Mikrokontroler ******************************** $regfile = "m8def.dat" $crystal = 1000000 '************************************* LCD ************************************* Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.7 , Db5 = Portd.5 , Db4 = Portd.6 , E = Portd.7 , Rs = Portb.0 Cursor Off Config Portb.0 = Output Config Portb.1 = Output Osvetlitev Alias Portb.1 Deflcdchar 0 , 226 , 229 , 226 , 224 , 224 , 224 , 224 , 224 ' replace ? with number (0-7) Cls '******************************************************************************* Dim T1 As Byte , T2 As Byte , T3 As Byte , Temp As Integer , Temp2 As Single , , Temp3 As String * 10 '******************************************************************************* Config 1wire = Portb.2 '******************************************************************************* '//////////////////// UVOD: Osvetlitev = 1 Cls '/////////////////////////////// GLAVNI PROGRAM //////////////////////////////// Do T1 = 0 T2 = 0 T3 = 0 Temp = 0 1wreset 1wwrite &HCC 1wwrite &H44 Wait 1 1wwrite &HCC 1wwrite &HBE T1 = 1wread() T2 = 1wread() 1wreset If Err > 0 Then Locate 1 , 1 Lcd "NAPAKA" End If Temp = Makeint(t1 , T2) Gosub Prikaz Loop Prikaz: Locate 1 , 1 Lcd "Temperatura je:" Locate 2 , 1 Lcd Temp ; Chr(0) ; "C" Return End |
Highlag je napisal/a: |
Pa dejansko imaš Ds1820, ki podpira tako visoko resolucijo? |
aly je napisal/a: |
Pri 1-wire je zelo pomemben timing. Če imaš časovne vrednosti narobe nastavljene, ne bo delalo nič. |
aly je napisal/a: |
In še vizualen komentar glede USB in RS232 direktne povezave: |
Koda: |
'///////////////////////////////////////////////////////////////////////////////
$regfile = "m8def.dat" $crystal = 4000000 '$crystal = 11000000 $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 'default use 10 for the SW stack $framesize = 40 'default use 40 for the frame space Config 1wire = Portc.5 Dim Ar(8) As Byte , A As Byte , I As Byte Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portb.5 , Rs = Portb.3 Config Lcd = 16 * 2 '$sim Cursor Off Noblink Cls Do Reset Portc.6 Wait 1 1wreset 'reset the device 1wwrite &H33 'read ROM command For I = 1 To 8 Ar(i) = 1wread() 'place into array Next For I = 1 To 8 Lowerline Lcd I Lowerline Locate 2 , 2 Lcd ":" Lcd Ar(i); Wait 5 Cls Next Loop End |
Koda: |
'///////////////////////////////////////////////////////////////////////////////
'DS1820 Thermo - merjenje temperature z dvema senzorjema ' Za Šolo Programiranja pri OZS . ' '/////////////////////////////////////////////////////////////////////////////// $regfile = "m8def.dat" $crystal = 4000000 '$crystal = 4000000 'Dim Ar(8) As Byte , A As Byte , 'I As Byte Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portb.5 , Rs = Portb.3 Config Lcd = 16 * 2 '$sim Declare Sub Read1820 Declare Sub Temperature Declare Sub Temp1 Declare Sub Temp2 Dim T2 As Integer , T4 As Integer Dim Bd(9) As Byte Dim I As Byte , Tmp As Byte Dim T As Integer , T1 As Integer , Tn As Byte Dim Tz As Byte Dim Ar(8) As Byte T = 0 Config 1wire = Portc.5 Cursor Off Noblink Cls Reset Portc Locate 1 , 1 : Lcd "DS1820 " Locate 2 , 1 : Lcd " Temp" Wait 2 Do Temp1 Temperature Locate 1 , 1 : Lcd "N" Tn = T4 Lcd T 'vpis celega dela Lcd Chr(46) 'vpis pike Lcd T1 'vpis decimalnega Lcd Chr(223) 'vpis stopinj Lcd "C" If Err = 1 Then 'ce ni senzorja Locate 1 , 3 : Lcd "-- " 'je na LCDju "-- " End If 'izpis praznega prostora Temp2 Temperature Locate 2 , 1 : Lcd "Z" Tz = T4 Lcd T Lcd Chr(46) Lcd T1 Lcd Chr(223) Lcd "C" If Err = 1 Then 'ce ni senzorja Locate 2 , 3 : Lcd "-- " 'je na LCDju "-- " End If 'Prizgi diodo If T <= 2 Then 'Ob vrednosti prizgi LED Reset Portd.5 Wait 1 Elseif T > 2 Then Set Portd.5 Wait 1 End If Loop End Rem /////// ' read address 1 Sub Temp1 'branje adrese 1 For I = 0 To 8 Ar(i + 1) = Lookup(i , Dta1) Next End Sub Rem ///////////////////////// ' read address 2 Sub Temp2 'branje adrese 2 For I = 0 To 7 Ar(i + 1 ) = Lookup(i , Dta2) Next End Sub Dta1: Data 16 , 80 , 46 , 140 , 0 , 8 , 0 , 50 'naslov 1 Dallasa Dta2: Data 16 , 168 , 26 , 140 , 0 , 8 , 0 , 122 'naslov 2 Dallasa '/////////////////////////////////////////////////////////////////////////////// Sub Temperature 'merjenje temperature 1wreset 1wwrite &H55 1wwrite Ar(1) , 8 '1Wire ukaz 1wwrite &H44 Wait 1 Read1820 'read 9 bytes End Sub Sub Read1820 'bere senzor 'T za 0.1 C 1wreset 'reset 1wwrite &H55 '1Wire ukaz 1wwrite Ar(1) , 8 1wwrite &HBE Bd(1) = 1wread(9) 1wreset Tmp = Bd(1) And 1 '0.1C natancnost If Tmp = 1 Then Decr Bd(1) End If T = Makeint(bd(1) , Bd(2)) T4 = T / 2 'T4 lahko uporabimo, ce zelimo temp. kot celo stevilo T = T * 50 : T = T - 25 : T1 = Bd(8) - Bd(7) : T1 = T1 * 100 'za to matematiko je potrebno pogledati datashet T1 = T1 / Bd(8) : T = T + T1 : T = T / 10 'tam je formula in opis vseh podatkov ki jih beremo T1 = T T = T / 10 ' bom kasneje še razložil vsako vrstico posebej T2 = T * 10 T1 = T1 - T2 T1 = Abs(t1) End Sub ' to je primer branja temperature iz več DS-ov , s tem , da moramo prvo prebrati njihove naslove ' gornji program. |
Koda: |
Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.7 , Db5 = Portd.5 , Db4 = Portd.6 , E = Portd.7 , Rs = Portb.0
|
Koda: |
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portb.5 , Rs = Portb.3
Config Lcd = 16 * 2 |
program_er je napisal/a: |
Bom poizkusil tvojo kodo.
Moram pa opozoriti, da uporabljam čip DS 18 B 20 ki ima tovarniško nastavljeno 12-bitno resolucijo in čas merjenja 750ms! Pomembni podatki o tem v zgornjem datasheetu na strani 8 in na strani 3 pod poglavjem OPERATION—MEASURING TEMPERATURE. |
program_er je napisal/a: |
Pa pri vsakem sem probal z nogico na Vcc, pa v zraku (parazitno napajanje). |
program_er je napisal/a: |
Pozdravljeni!
Kakšno vlogo za vraga ima pin AREF pri AD pretvorniku? |
iskra je napisal/a: |
Ja boš moral še malo dodelati program : http://www.mcselec.com/index.php?option=com_content&task=view&id=75&Itemid=57 |
robika je napisal/a: | ||
Če ga napajaš parazitno potem Vcc veži na maso. Jaz imam na dvožični liniji dolžine >40 metrov (zvezda vezava) vezanih 7 senzorjev pa vse teče po pravilih. |
Koda: |
'/////////////////////////////////////////////////////////////////////////////// 'DS1820 Thermo - merjenje temperature z dvema senzorjema ' Za Šolo Programiranja pri OZS . ' '/////////////////////////////////////////////////////////////////////////////// $regfile = "m8def.dat" $crystal = 1000000 '$crystal = 4000000 'Dim Ar(8) As Byte , A As Byte , 'I As Byte Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.7 , Db5 = Portd.5 , Db4 = Portd.6 , E = Portd.7 , Rs = Portb.0 Config Portb.1 = Output Osvetlitev Alias Portb.1 Deflcdchar 0 , 2 , 5 , 2 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7) Osvetlitev = 1 '$sim Declare Sub Read1820 Declare Sub Temperature Declare Sub Temp1 Declare Sub Temp2 Dim T2 As Integer , T4 As Integer Dim Bd(9) As Byte Dim I As Byte , Tmp As Byte Dim T As Integer , T1 As Integer , Tn As Byte Dim Tz As Byte , Tp As Integer , Tb As Integer Dim Ar(8) As Byte T = 0 Config 1wire = Portb.2 Cursor Off Noblink Cls Reset Portb Locate 1 , 1 : Lcd "DS1820 " Locate 2 , 1 : Lcd " Temperatura" Wait 2 Do Temp1 Temperature Locate 1 , 1 : Lcd "1.temp: " Tn = T4 Tp = T / 10 Tb = T Mod 10 Lcd Tp 'vpis celega dela Lcd Chr(46) 'vpis pike Lcd Tb 'vpis decimalnega Lcd Chr(0) 'vpis stopinj Lcd "C" If Err = 1 Then 'ce ni senzorja Locate 1 , 3 : Lcd "-- " 'je na LCDju "-- " End If 'izpis praznega prostora Temp2 Temperature Locate 2 , 1 : Lcd "2.temp: " Tz = T4 Tp = T / 10 Tb = T Mod 10 Lcd Tp Lcd Chr(46) Lcd Tb Lcd Chr(0) Lcd "C" If Err = 1 Then 'ce ni senzorja Locate 2 , 3 : Lcd "-- " 'je na LCDju "-- " End If 'Prizgi diodo If T <= 2 Then 'Ob vrednosti prizgi LED Reset Portd.5 Wait 1 Elseif T > 2 Then Set Portd.5 Wait 1 End If Loop End Rem /////// ' read address 1 Sub Temp1 'branje adrese 1 For I = 0 To 8 Ar(i + 1) = Lookup(i , Dta1) Next End Sub Rem ///////////////////////// ' read address 2 Sub Temp2 'branje adrese 2 For I = 0 To 7 Ar(i + 1 ) = Lookup(i , Dta2) Next End Sub Dta1: Data 40 , 68 , 244 , 183 , 1 , 0 , 0 , 178 'naslov 1 Dallasa Dta2: Data 40 , 72 , 14 , 184 , 1 , 0 , 0 , 78 'naslov 2 Dallasa '/////////////////////////////////////////////////////////////////////////////// Sub Temperature 'merjenje temperature 1wreset 1wwrite &H55 1wwrite Ar(1) , 8 '1Wire ukaz 1wwrite &H44 Wait 1 Read1820 'read 9 bytes End Sub Sub Read1820 'bere senzor 'T za 0.1 C 1wreset 'reset 1wwrite &H55 '1Wire ukaz 1wwrite Ar(1) , 8 1wwrite &HBE Bd(1) = 1wread(9) 1wreset Tmp = Bd(1) And 1 '0.1C natancnost If Tmp = 1 Then Decr Bd(1) End If T = Makeint(bd(1) , Bd(2)) T4 = T / 20 'T4 lahko uporabimo, ce zelimo temp. kot celo stevilo T = T * 50 : T = T - 25 : T1 = Bd(8) - Bd(7) : T1 = T1 * 100 'za to matematiko je potrebno pogledati datashet T1 = T1 / Bd(8) : T = T + T1 : T = T / 10 'tam je formula in opis vseh podatkov ki jih beremo T1 = T T = T / 10 ' bom kasneje še razložil vsako vrstico posebej T2 = T * 10 T1 = T1 - T2 T1 = Abs(t1) End Sub ' to je primer branja temperature iz več DS-ov , s tem , da moramo prvo prebrati njihove naslove |
program_er je napisal/a: |
Imam težavo. Rad bi nastavil mojo mego8 na zunanji kvarčni kristal, pa mi ne uspe. Ko sem to hotel narediti na megi16, sem jo s tem zaklenil oz. uničil.
Uporabljam AVRUSB programator (v Bascomu-AVR STK500 extended) Ko odprem okno za programiranje, mi se poleg ostalega prikaže tudi to: Ko priključim ATmega8 in pri vsem kliknem Read, mi potem kaže to: V datasheetu od mege pa piše med drugim to: Kot se vidi pri 1. sliki, sta pri Fuse bits dva prostorčka oz. kvadratka. Zanima me, kateri kvadratek so CKSEL 3...0 biti. Prvi ali drugi? Če je eden CKSEL, iz česa je potem sestavljen drugi? |
Citiram: |
Juhu!!!
Program od @iskra mi deluje! Moral sem samo parazitno priklopiti napajanje in deluje. Moral sem še malo popraviti rezultat, ker ko je bilo npr. 21,5°C mi je kazalo 215,8°C ali pa podobno. |
Koda: |
Config Lcdpin = Pin , Db7 = Portb.3 , Db6 = Portb.2 , Db5 = Portb.1 , Db4 = Portb.0 , E = Portb.4 , Rs = Portb.5 Config Lcd = 16 * 1 Cursor Off Dim W As Word , W2 As Word , Stotinke As Word , Desetinke As Word Config Adc = Single , Prescaler = Auto Start Adc Cls Do W = Getadc(0) W2 = W * 50 W2 = W2 / 1023 Stotinke = W2 / 10 Desetinke = W2 Mod 10 Locate 1 , 1 Lcd Stotinke ; "," ; Desetinke; "V"; Loop |
Koda: |
Lcdat 3 , 5 , "[slovenščina je zame španska vas]" , 0 |
LEDuser je napisal/a: |
Ker sem pred kratkim obupal nad assemblerjem sem preklopil na Bascom. Naučil sem se prižigati LED ... zataknilo pa se mi je pri ADCju. Če napišem program ki mi bere z enega ADCja v spremenljivko W (P = W / 10) in z nekaj IF stavki preverjam ali je P > 5 (10,15,20) mi prižiga izhode 0,1,2,3 se mi ob spreminjanju napetosti na ADC (0-100%) v prvi četrtini prižgejo v zaporedju vse ledice, v drugi četrtini se ugasnejo in se spet prižgejo v zaporedju...
Po moji logiki bi bilo tako: ADC prebere stanje in ob 100% bi vrgel ven 1023. če to deliš z 10 bi moralo biti potemtakem stanje od 0-102. Če bi to razdelil na 4 enake dele (npr 25) in imam na vhodu ADC 1/4 napetosti (AVCC) bi morala LEDica zasvetiti pri takem stavku: If P > 25 Then Portd.0 = 1 Else Portd.0 = 0 End If Ne vem kaj delam narobe ampak zdi se mi da me tale Atmega8 malo |
Koda: |
Config Lcdpin = Pin , Db7 = Portb.3 , Db6 = Portb.2 , Db5 = Portb.1 , Db4 = Portb.0 , E = Portb.4 , Rs = Portb.5 Config Lcd = 16 * 1 Cursor Off Dim W As Word , W2 As Word , Stotinke As Word , Desetinke As Word Config Adc = Single , Prescaler = Auto Start Adc Cls Do W = Getadc(0) LCD W Loop |
Koda: |
Napis:
Cls Locate 1 , 1 Lcd "****************" Locate 2 , 1 Lcd "****************" Wait 1 Goto Napis |
Koda: |
Locate 1,8
Lcd"********" |
Koda: |
$regfile = "m8def.dat"
Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc Dim W As Word Cls Cursor Off W = Getadc(1) Lcd W |
Koda: |
$regfile = "m8def.dat"
Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc Dim W As Word Cls Cursor Off do W = Getadc(1) locate 1,1 Lcd W loop |
LEDuser je napisal/a: |
Ker sem pred kratkim obupal nad assemblerjem sem preklopil na Bascom. Naučil sem se prižigati LED ... zataknilo pa se mi je pri ADCju. Če napišem program ki mi bere z enega ADCja v spremenljivko W (P = W / 10) in z nekaj IF stavki preverjam ali je P > 5 (10,15,20) mi prižiga izhode 0,1,2,3 se mi ob spreminjanju napetosti na ADC (0-100%) v prvi četrtini prižgejo v zaporedju vse ledice, v drugi četrtini se ugasnejo in se spet prižgejo v zaporedju...
Po moji logiki bi bilo tako: ADC prebere stanje in ob 100% bi vrgel ven 1023. če to deliš z 10 bi moralo biti potemtakem stanje od 0-102. Če bi to razdelil na 4 enake dele (npr 25) in imam na vhodu ADC 1/4 napetosti (AVCC) bi morala LEDica zasvetiti pri takem stavku: If P > 25 Then Portd.0 = 1 Else Portd.0 = 0 End If Ne vem kaj delam narobe ampak zdi se mi da me tale Atmega8 malo |
Koda: |
Locate 1,6
LCD "TEST" |
Koda: |
LCD "TESTIRANJE" |
Koda: |
Locate 1 , 4
Lcd "TEST" Wait 2 Locate 2 , 4 Lcd "TEST" Wait 2 |
Koda: |
Config LDC = 16 * 1a |
Koda: |
Locate 1 , 6 Lcd "TESTIRANJE" Wait 2 Cls Locate 1 , 6 Lcd "TEST" |
red_mamba je napisal/a: |
[cenzurirano] te to da imaš ADC kot 10 bitov nastavljen bereš pa samo spodnjih 8 bitov v byte spremeljivko namesto word |
Koda: |
Config Lcd = 16 * 1a |
Koda: |
Dim A As Byte
Config Pinb.0 = Input Config Pind.7 = Input Cls Cursor Off Locate 1 , 1 : Lcd "Stetje s tipko" A = 0 Do If Pinb.0 = 0 Then Waitms 20 If Pinb.0 = 0 Then Gosub Naprej End If End If If Pind.7 = 0 Then Waitms 20 If Pind.7 = 0 Then Gosub Nazaj End If End If Naprej: Incr A Locate 2 , 5 : Lcd A Return Nazaj: Decr A Locate 2 , 5 : Lcd A Return End |
mucek je napisal/a: |
Tista nula ti ostane še od prej (ko si imel izpisano 10), saj pišeš vedno na isto mesto.
Enostavno zadevo rešiš, da pišeš Lcd a ; Lcd " " (par presledkov) Tako ti presledki pobrišejo morebitni ostanek. Druga varianta je ukaz Cls po vsaki spremembi, a to za seboj potegne utripanje zaslona. Še tretja možnost je if stavek, ki v primeru spremembe mest poskrbi za brisanje dotičnega mesta. Lp, Grega |
program_er je napisal/a: |
Ja, poglej:
LCD a : LCD "nekaj" : LCD b : LCD "bla" LCD a ; "nekaj" ; b ; "bla" |
dkone je napisal/a: |
kaj pa takole:
ddrb=255 set portb.x |
Koda: |
...
C = 0 Do If Pinc.5 = 0 Then Waitms 20 If Pinc.5 = 0 Then Gosub Vec End If End If If Pinc.3 = 0 Then Waitms 20 If Pinc.3 = 0 Then Gosub Manj End If End If If Pinc.4 = 0 Then Waitms 20 If Pinc.4 = 0 Then Exit Do End If End If Loop Do 'Ta zanka bi se naj izvedla C krat. Loop Vec: Incr C Locate 3 , 5 : Lcd C : Lcd " " Return Manj: Decr C Locate 3 , 5 : Lcd C : Lcd " " Return |
Koda: |
$regfile = "m8def.dat" $crystal = 11059200 Config Portc = Input Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0 Config Lcd = 20 * 4 Dim C As Byte Dim C_flag As Bit Declare Sub Vec Declare Sub Manj Reset C_flag Cls '**************************************** Do If Pinc.5 = 0 Then ' Waitms 20 If Pinc.5 = 0 Then Call Vec End If End If If Pinc.3 = 0 Then ' Waitms 20 If Pinc.3 = 0 Then Call Manj End If End If If Pinc.4 = 0 Then ' Waitms 20 If Pinc.4 = 0 Then Set C_flag End If ' If C_flag = 1 Then Lcd "*" If C_flag = 1 And C > 0 Then If C = 1 Then Reset C_flag ' dodaj svojo kodo Lcd "#" End If Decr C Lcd C End If Loop '******************************************** Sub Vec: Incr C Locate 1 , 1 : Lcd C : Lcd " " End Sub '******************************************** Sub Manj: Decr C Locate 1 , 1 : Lcd C : Lcd " " End Sub '******************************************** |
Koda: |
Dim Number As Word Number = 1000 ... Waitus Number ... |
Koda: |
Servo = 1
Waitus Count Servo = 0 Waitms 20 |
Koda: |
$crystal = 4000000
Ddrb.0 = 1 Dim A As Word Do For A = 2000 To 1000 Step -10 Pulseout Portb , 0 , A Waitms 20 Next For A = 1000 To 2000 Step 10 Pulseout Portb , 0 , A Waitms 20 Next Loop |
Koda: |
do prikaži LCD itd if pogoj_npr_tipka = pritisnjena then nastavljen čas = željen čas if zastavica= 1 then reset zastavica izvrši kar hočeš endif loop timer0_isr: if nastavljeni čas>0 then decr nastavljeni čas if nastavljen_čas=0 then set zastavica endif return |
RGorazd je napisal/a: |
Drugič Waitus deluje samo do 255 se pravi 255us. Če hočeš čakati v mikrosekundah
moraš čakati 4xpo250us. LP G |
Citiram: |
The number of microseconds to wait. (1-65535)
This must be a constant. Not a variable! |
klpzm je napisal/a: |
Lp.
Mislim da Rx ter Tx nimata notranjega pullup upora. Dodaj 4.7k upor na Ucc. Lp |
tozir je napisal/a: | ||
Ga že imam, vendar je vrednost 10k . Prevelik? |
Koda: |
Config 1wire = Portd.2
Dim A As Word , I As Word Do A = 1wread(1) If A < 11 Then Print "A=" ; A End If Loop End |
Koda: |
Config 1wire = Portd.2
Dim A As Word , I As Word I = 1 Do 1wreset 1wwrite I Waitms 250 Waitms 250 Loop End |
klpzm je napisal/a: |
Lp
Če bi sam pokazal malo interesa in pokazal kaj si do sedaj naredil za to nalogo ( razen 3-je posti na elektronik.si ) bi ti z veseljem pomago. Vendar, če ti jaz napišem program se iz njega neboš nič naučil. Učitelj vam nebi dal kar tako naloge in da vam v šoli nebi pokazal kako se bere tipke, kako se nastavijo vhodi/izhodi, pisanje po LCD-ju ali pač? |
Koda: |
$crystal = 12000000 $baud = 9600 Dim A1 As word A1 = 1023 Do Print A1 Loop |
Koda: |
'$sim $crystal = 12000000 $baud = 9600 Dim A1 As Word Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.1 , Rs = Portb.0 Config Lcd = 16 * 2 Cls Do Waitms 10 A1 = Inkey() Locate 1 , 1 Lcd A1 ; " " Loop |
eddie je napisal/a: |
Takole na pamet:
Malo pavze med oddajanji nebi škodilo, Funkcija Inkey pa ti vrne en znak iz uarta! Funkcija inputbin bi znala biti boljša! Lp |
Koda: |
'$sim $crystal = 8000000 $baud = 300 Dim A1 As Word A1 = 500 Do Printbin A1 Waitms 10 Loop |
Koda: |
'$sim $crystal = 8000000 $baud = 300 Dim A1 As Word Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.1 , Rs = Portb.0 Config Lcd = 16 * 2 Cls Do Waitms 100 Inputbin A1 Locate 1 , 1 Lcd A1 ; " " Loop |
eddie je napisal/a: |
Sprejemno zanko "vrtiš" 10x bolj počasi kot oddajno!
Morda je že tule problem! Lp |
galex4 je napisal/a: |
kako je pri bascomu tipka če je pritisnena gre proti masi pomeni, da je stanje 0 ali 1? |
galex4 je napisal/a: |
kako je pri bascomu tipka če je pritisnena gre proti masi pomeni, da je stanje 0 ali 1? |
Koda: |
$regfile = "2313def.dat"
$crystal = 4000000 'Config Pind.6 = Output Config Timer1 = Timer , Prescale = 64 , Capture Edge = Rising Dim Wtime As Byte Dim Timercounter As Word On Capture1 Captmr Wtime = 100 Timercounter = 0 Enable Interrupts Enable Capture1 Do 'Set Portd.6 Waitms Wtime 'Reset Portd.6 Waitms Wtime Cls Lcd "pwidth: " ; " " ; Capture1 Loop Captmr: Timercounter = Capture1 Timer1 = 0 Return End |
Citiram: |
Timer1 Capture
Timer1 can be configured in the 'Capture' mode. This means that Timer1 counts the controller clock through a prescaler, and when on the ICP input (PortD.6, pin 11) a pulse arrives, the contents of the Timer1 register is copied to the input capture register. In this way it is possible to measure the time between two pulse edges exactly: Config Timer1 - Timer, Prescale = 1|8|64|256|1024, Capture Edge = Rising|Falling interrupt-timer1-capture.bas $regfile = "2313def.dat" $crystal = 4000000 'Config Pind.6 = Output Config Timer1 = Timer , Prescale = 64 , Capture Edge = Rising Dim Wtime As Byte Dim Timercounter As Word On Capture1 Captmr Wtime = 100 Timercounter = 0 Enable Interrupts Enable Capture1 Do 'Set Portd.6 Waitms Wtime 'Reset Portd.6 Waitms Wtime Cls Lcd "pwidth: " ; " " ; Capture1 Loop Captmr: Timercounter = Capture1 Timer1 = 0 Return End In the interrupt routine the value of Timer1 (Capture1 is just another name for this register) is copied to Timercounter. Timer1 is then reset. The next time that a pulse on the ICP input arrives the same happens. So, Timercounter is a measure of the time between pulses on ICP. |
joze je napisal/a: |
LP!
Mucek, zanima me kam oziroma kako ta Avr Timer.exe generira kodo?? |
Koda: |
$regfile = "at26def.dat" $crystal = 8000000 Deflcdchar 1 , 10 , 4 , 14 , 17 , 16 , 17 , 14 , 32 Deflcdchar 0 , 10 , 4 , 15 , 16 , 14 , 1 , 30 , 32 Dim Vrednost As Integer , Desetinke As Byte Dim Sekunde As Byte , Stotinke As Byte , I As Byte , Flag As Bit Dim Sekold As Byte , Stotold As Byte , Desold As Byte Dim X As Byte , S As String * 1 Config Lcd = 16 * 2 Config Timer0 = Timer , Prescale = 8 Config Int0 = Falling Enable Int0 Enable Timer0 On Int0 Int0isr On Ovf0 Ovf0isr Load Timer0 , 250 Stop Timer0 Header: Cls Restore Dta1: For X = 1 To 10 Locate 1 , X Read S Lcd " " : Lcd S Waitms 150 Next X Cls Restore Dta2: For X = 1 To 10 Locate 2 , X Read S Lcd " " : Lcd S Waitms 150 Next X Cls Enable Interrupts While Flag = 0 Lcd "Cakam na prvi " Lowerline Lcd "impulz... " Wend Main: Do Locate 1 , 1 If Flag = 1 Then Cls Flag = 0 End If Lcd "Trenutni:" : Lcd Sekunde : Lcd ":" : Lcd Stotinke : Lcd Desetinke Locate 2 , 1 Lcd "Prej" : Lcd Chr(0) : Lcd "nji:" : Lcd Sekold : Lcd ":" : Lcd Stotold : Lcd Desold Loop Int0isr: Disable Int0 Stop Timer0 If Flag = 0 Then Sekold = Sekunde Stotold = Stotinke Desold = Desetinke End If Sekunde = 0 Stotinke = 0 Desetinke = 0 Vrednost = 0 Timer0 = 0 Flag = 1 Enable Int0 Start Timer0 Return Ovf0isr: Load Timer0 , 250 Incr Vrednost If Vrednost = 40 Then Incr Desetinke Vrednost = 0 End If If Desetinke > 9 Then Incr Stotinke Desetinke = 0 End If If Stotinke > 9 Then Incr Sekunde Stotinke = 0 End If Return Dta1: Data "(" , "c" , ")" , "R" , "o" , "s" , "b" , "a" , "c" , "h" Dta2: Data "M" , "a" , "r" , "e" , "c" , " " , "2" , "0" , "0" , "6" |
dkone je napisal/a: |
Pozdravljeni!
Zanima me kako v Bascomu uporabiti decimalna števila? Imam eno konstanto Faktor(vrednost naprimer 0,8333),ki bi jo rad pomnožil z spremenljivko Števec in to prikažem na LCD-ju. Gledal sem help,vendar nisem zasledil. Prosim za izkušene bascomaše za pomoč. |
LEDuser je napisal/a: |
Jaz pa se trudim in iščem kako bi vklopil "fast PWM" na megi8 v Bascomu. Največ kot sem lahko dobil z uporabo int. 8MHz frekvence je 16kHz to pa je kar malo premalo... |
LEDuser je napisal/a: |
Ja škoda jaz bi potreboval čim višjo frekvenco od 50kHz naprej. Kristal bom uporabil 20MHz. Nekaj sem slišal za spreminjanje registrov TCCR samo tukaj pa ne vem več kateri biti morajo biti postavljeni za hitri PWM. |
program_er je napisal/a: | ||
Denis, tukaj imaš. Upam, da sem ti pomagal, če pa bo še kaj narobe, pa mi lahko tudi na Skypu pišeš. |
Koda: |
dim Spremenljivka(4) as byte |
Koda: |
Declare Sub podrutina(byval Spremenljivka As Byte) |
stursc je napisal/a: |
Pozdravljeni baskom-aši.
Nimam razlage zakaj ta primer ne deluje. Vsak komentar je dobrodošel, seveda v smeri rešitve problema Priloga je preimenovana v txt Hvala za namige. |
Koda: |
$regfile = "8515def.dat" $baud = 19200 $crystal = 11059200 $hwstack = 64 $swstack = 64 $framesize = 64 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portb.7 , Db6 = Portb.6 , Db5 = Portb.5 , Db4 = Portb.4 , E = Portb.2 , Rs = Portb.1 Cursor Off Cls Lcd "Test PORT in PIN" 'Wait 1 '------------------------------------------------------------------------------ 'deklaracija subrutin Declare Sub Prikazi Declare Sub Xx(byval Ix As Byte) Declare Sub Gor Declare Sub Dol '------------------------------------------------------------------------------ Config Porta = Output Config Portc = Output Config Portd = Input Dim I As Byte Dim Pa As Byte Dim Pc As Byte '*** deklaracija tipk Tipka1 Alias Pind.0 Tipka2 Alias Pind.1 '*** deklaracija pinov Rele1 Alias Porta.0 Rele2 Alias Porta.1 Rele3 Alias Porta.2 Rele4 Alias Porta.3 Rele5 Alias Porta.4 Rele6 Alias Porta.5 Rele7 Alias Porta.6 Rele8 Alias Porta.7 Rele9 Alias Portc.7 Rele10 Alias Portc.6 Rele11 Alias Portc.5 Rele12 Alias Portc.4 Rele13 Alias Portc.3 Rele14 Alias Portc.2 Rele15 Alias Portc.1 Rele16 Alias Portc.0 Porta = 0 'Izklopiš vse releje na portu A Portc = 0 'Izklopiš vse releje na portu C I = 0 Do 'Zaradi simulacije sem zakomentiral spodnje vrstice ' Debounce Tipka1 , 0 , Gor , Sub Gor ' Debounce Tipka2 , 0 , Dol , Sub ' Dol Call Xx(i) Call Prikazi Loop '------------------------------------------------------------------------------- Sub Gor: Incr I If I > 16 Then I = 1 End Sub '------------------------------------------------------------------------------- Sub Dol: Decr I If I < 1 Then I = 16 End Sub '------------------------------------------------------------------------------- Sub Xx(ix As Byte) Decr Ix If Ix > 8 Then Ix = Ix - 8 Porta = 0 If Pc.ix = 0 Then Set Pc.ix Else Reset Pc.ix Portc = Pc Else Portc = 0 If Pa.ix = 0 Then Set Pa.ix Else Reset Pa.ix Porta = Pa End If End Sub '------------------------------------------------------------------------------- Sub Prikazi: Cls Lcd Bin(pa) Locate 2 , 1 Lcd Bin(pc) End Sub '------------------------------------------------------------------------------- end |
protoncek je napisal/a: |
če to ne znaš, potem močno dvomim da ti bo uspelo napisati program...10 bitov je 2 na 10, kar znese 1024 različnih vrednosti. Torej bo 0 stopinj 0 in 180 stopinj 1024. Če bo na ADC torej 512, to pomeni temperaturo 90 stopinj...čista osnovnošolska matematika... |
Koda: |
Adc_vrednost2 = Adc_vrednost Adc_vrednost2 = Adc_vrednost * 100 |
linel je napisal/a: |
koda je zdaj taka, in stvar dela, hvala za opombo:)
|
protoncek je napisal/a: |
Je, je...
en primer: If K = 4 Or K = 5 Or K = 6 Then Locate 4 , 1 itd... |
linel je napisal/a: |
zanima me,kako se naredi, da se dogodek izvrši če npr gledamo dva pogoja
if pina.0 and pina.1 = 1 then portc = 1 vendar v bascomu nisem zasledil ukaza and, kako vi naredite v tem primeru? |
Koda: |
... Reset Spi_cs XX(1) = Spimove(&H02) XX(2) = Spimove(&H00) Set Spi_cs Locate 1 , 1 Lcd XX(2) ... |
Koda: |
A = 123 Locate 1 , 1 Lcd A Lowerline Lcd Bin(A) |
vilko je napisal/a: |
Bascom simulator slabo dela, čim imaš kakršnekoli wait-e, bascom jih sicer simulira, a ne s frekvenco 4M, kot je v kristalu.
Oglej si v helpu, kaj naredi $sim. Pozdrav vs |
kotnikd3 je napisal/a: |
evo...tole me zanima, če mi lahko pomagate. Attiny26 oz. Attiny261 ima na portu PB7 reset funkcijo, tako da mi v simulatorju Proteus ledica na tem portu ne zasveti. Kaj moram narediti, da mi bo port PB7 zaznal kot izhod, ne pa kot reset?
Hvala http://wiki.noone.at/_media/hardware:attiny26.png?w=&h=&cache=cache |
kotnikd3 je napisal/a: |
tudi s $sim sem sprobal. čemu potem sploh služi tist lcd/simulator v bascomu, če pa ne moreš preveriti kaj si sprogramiral? |
Koda: |
Reset Startmotor
I = 255 J = 0 K = 255 While I > 1 Pulseout Portb , 1 , J Toggle Startmotor Pulseout Portb , 1 , K Toggle Startmotor I = I - 1 J = J + 1 K = K - 1 Wend |
kotnikd3 je napisal/a: |
tudi s $sim sem sprobal. čemu potem sploh služi tist lcd/simulator v bascomu, če pa ne moreš preveriti kaj si sprogramiral? |
TECHNIC je napisal/a: | ||
Skušam naredit soft-start elektromotorja brez uporabe pwm-ja in prekinitev (prekomplicirano zame). Ne rabi biti nič eksotično, samo kakšnih 10 ms spreminjanja širine pulza od nekje 20 do 100%.
Takšna koda bi po pričakovanju morala delovati, vendar je rezultat prav obraten:
|
Koda: |
Startmor Alias Portx.y ' kamor je priklopljen rele za start motorja
Config Startmotor = Output Startmotor = 1 ' prepodstavljam, da je motor pod napetostjo, ko je ta pin na 0 For I = 0 To 255 J = 255 - I Reset Startmotor Pulseout Port , Pin , J Set Startmotor Pulseout Port , Pin , I Next |
protoncek je napisal/a: |
Ravno testiram EEPROM 24C64 na tiny2313...zanima me če kdo lahko razloži zakaj zadeva ne deluje če izberem SCL/SDA na porta D0 in D1 - na portih D2 in D3 pa deluje...je to kaj v povezavi z dejstvom da sta podta D0 in D1 RXD in TXD? |
Koda: |
$regfile = "attiny2313.dat" ' specify the used micro
$crystal = 1000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Pinb.2 , Db5 = Pinb.3 , Db6 = Pinb.4 , Db7 = Pinb.5 , E = Pinb.1 , Rs = Pinb.0 Config Scl = Portd.2 Config Sda = Portd.3 Dim Value As Byte Cls 'writing I2cstart 'start condition I2cwbyte &B10101000 'slave address I2cwbyte 0 'asdress of EEPROM I2cwbyte 12 I2cwbyte 48 'value to write I2cstop 'stop condition Wait 1 'reading I2cstart I2cwbyte &B10101000 'slave address I2cwbyte 0 'asdress of EEPROM I2cwbyte 12 I2cstart 'start condition I2cwbyte &B1010_0011 'slave address I2crbyte Value , Nack 'value to write I2cstop 'read it back Lcd "prebrano:" ; Value End |
Koda: |
$regfile "attiny2313.dat"
Config Portd = Output Config Portb = Output Dim A As Byte Dim B As Byte Dim C As Byte Dim D As Byte Dim E As Byte Dim F As Byte Dim T1 As Byte Dim T2 As Byte Dim T3 As Byte Dim T As Integer T = 0 Config 1wire = Portb.0 A = 0 Do For B = 0 To 9 Pinb.1 = 0 Portd = Lookup(a , Prikaz) Waitms 20 Pinb.1 = 1 Pinb.2 = 0 Portd = Lookup(a , Prikaz) Waitms 20 Pinb.2 = 1 Pinb.3 = 0 Portd = Lookup(a , Prikaz) Waitms 20 Pinb.3 = 1 A = A + 1 If A > 9 Then A = 0 End If Next Pinb.1 = 1 Portd = 0 Waitms 500 Portd = 255 Pinb.1 = 0 Do 1wreset 1wwrite &HCC 1wwrite &H44 Waitms 750 1wreset 1wwrite &HCC 1wwrite &HBE T = 1wread(2) 1wreset T = T / 2 T1 = T / 10 For E = 0 To 5 For D = 0 To 170 Pinb.1 = 0 Portd = Lookup(t1 , Prikaz) Waitus 850 Pinb.1 = 1 Pinb.2 = 0 Portd = Lookup(c , Prikaz) Waitus 850 Pinb.2 = 1 Pinb.3 = 0 Portd = Lookup( , Prikaz) Waitus 850 Pinb.3 = 1 Portd = 255 Next Next Loop |
rok je napisal/a: |
Pozdrav!
Kak mesec nazaj sem začel s programiranjem v Bascom-u |
Koda: |
$regfile "attiny2313.dat"
Config Portd = Output Config Portb = Output Dim T1 As String * 4 Dim T2 As Byte Dim T3 As Byte Dim T As Integer Dim A1 As Byte Dim A2 As Byte Dim A3 As Byte Dim D1 As Byte Dim D2 As Byte Dim D3 As Byte A1 = 1 A2 = 2 A3 = 3 T = 23.4 Config 1wire = Portb.0 A = 0 Do T1 = "T" T1 = Str(t) 1wreset 1wwrite &HCC 1wwrite &H44 Wait 1 1wreset 1wwrite &HCC 1wwrite &HBE T = 1wread(2) 1wreset D1 = Instr(t1 , A1) D2 = Instr(t1 , A2) D3 = Instr(t1 , A3) For E = 0 To 5 For D = 0 To 170 Pinb.1 = 0 Portd = Lookup(d1 , Prikaz) Waitus 850 Pinb.1 = 1 Pinb.2 = 0 Portd = Lookup(d2 , Prikaz) Waitus 850 Pinb.2 = 1 Pinb.3 = 0 Portd = Lookup(d3 , Prikaz) Waitus 850 Pinb.3 = 1 Portd = 255 Next Next Loop |
Vlado je napisal/a: |
Rok,
Drugo "T1" imaš deklarirano kot string*4, to ne bo v redu, če je tvoj string dolg 4 znake, potem moraš T1 deklarirati kot string*5. String se vedno konča z H00, tako da je dolžina stringa vedno večja za en bajt. Svoje spremenljivke A1, A2, A3 dimenzioniraj kot overlay čez string T1. Na ta način boš dobil vrednost karakterja, da bi dobil številčno vrednost od tega odštej 48 in boš imel pravo vrednost, ali pa uporabi ukaz "Val". |
Koda: |
Do
1wreset 1wwrite &HCC 1wwrite &H44 Wait 1 1wreset 1wwrite &HCC 1wwrite &HBE T = 1wread(2) T2 = Str(t) D3 = Right(t2 , A1) D2 = Mid(t2 , A2 , A1) D1 = Left(t2 , A1) B1 = Val(d1) B2 = Val(d2) B3 = Val(d3) B4 = Val(d4) If B3 > 9 Then B3 = B4 End If If B3 > 9 Then D4 = Right(t2 , A1) End If For E = 0 To 5 For D = 0 To 170 Portb.1 = 1 Portd = Lookup(b1 , Prikaz) Waitus 850 Portb.1 = 0 Portb.2 = 1 Portd = Lookup(b2 , Prikaz) Waitus 850 Portb.2 = 0 Portb.3 = 1 Portd = Lookup(b3 , Prikaz) Waitus 850 Portb.3 = 0 Next Next Loop |
Koda: |
$regfile = "m644pdef.dat"
$crystal = 12000000 $baud = 9600 $baud1 = 9600 $framesize = 16 $hwstack = 32 $swstack = 16 Dim S As String * 5 , D1 As Byte At S Overlay , D2 As Byte At S + 1 Overlay Dim D3 As Byte At S + 2 Overlay , D4 As Byte At S + 3 Overlay S = "24,5" Print D1 Print D2 Print D3 Print D4 End |
Koda: |
$regfile "attiny2313.dat"
$crystal = 7372000 Config Portd = Output Config Portb = Output Dim B As Byte Dim A1 As Byte Dim A2 As Byte Dim A3 As Byte Dim T As Byte Dim D1 As Byte Dim D2 As Byte Dim D3 As Byte Dim T1 As Integer Dim T2 As Integer Dim T3 As Byte Config 1wire = Pinb.0 Do Disable Interrupts 1wreset 1wwrite &HCC 1wwrite &H44 Waitms 750 1wreset 1wwrite &HCC 1wwrite &HBE T = 1wread(2) 1wreset 1wwrite &HCC 1wwrite &HBE Wait 1 T = 1wread(2) T = T / 2 T1 = T / 10 T2 = T Mod 10 T2 = T2 * 100 T2 = T2 / 100 T1 = A1 T2 = A2 A3 = 0 For B = 0 To 255 Portb.1 = 1 Portd = Lookup(a1 , Prikaz) Waitms 5 Portb.1 = 0 Portb.2 = 1 Portd = Lookup(a2 , Prikaz) Waitms 5 Portb.2 = 0 Portb.3 = 1 Portd = Lookup(a3 , Prikaz) Waitms 5 Portb.3 = 0 Next Loop Prikaz: Data 192 , 249 , 36 , 48 , 25 , 18 , 2 , 248 , 0 , 16 |
rok je napisal/a: |
Poskušal sem pretvoriti integer v string a mi ni uspelo. |
Koda: |
Dim ii as integer
Dim Ss as string * 10 ' pretvorba integer v string: Ss = str(i) |
rok je napisal/a: |
Vlado, tvoja pripeta koda ne deluje. Bascom mi javi cel kup napak. |
Citiram: |
in nismo definirali Config lcd, ker smo to prepustili avtorju, ki edini ve, kako je vezan LCD, bo seveda Bascom prevajalnik zajamral. |
Koda: |
Sub Read_ad(byval Adress As Byte , Value As Byte) I2cstart 'start I2cwbyte Write_ad I2cwbyte Adress I2cstart I2cwbyte Read_ad I2crbyte Value , Ack I2cstop End Sub |
Koda: |
dim beseda as word |
Koda: |
dim spodnja as byte at beseda overlay
dim zgornja as byte at beseda + 1 overlay |
Koda: |
$regfile = "m32def.dat"
$crystal = 400000 Config Pinc.1 = Input Config Pinc.6 = Input Config Pind.2 = Output Do If Pinc.1 = 0 and Pinc.6 = 0 Then Pind.7 = 0 Else Pind.7 = 1 End If Loop End |
Koda: |
$regfile = "m32def.dat"
$crystal = 4000000 Config Porta = Output Config Portd.0 = Input Porta = 255 Config Debounce = 80 Dim Led As Byte Dim Tipka As Byte Main: Do If Pind.0 = 0 Then Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 If Pind.0 = 0 Then Porta = Led Led = Not Led Else End If End If Loop |
Citiram: |
Do
If Pinc.1 = 0 and Pinc.6 = 0 Then Pind.7 = 0 Else Pind.7 = 1 End If Loop End |
Koda: |
Do If Pinc.1 = 0 and Pinc.6 = 0 Then Pind.7 = 0 Else Pind.7 = 1 End If Loop |
Koda: |
Do If Pinc.1 = 0 and Pinc.6 = 0 Then Pind.7 = 0 Else Pind.7 = 1 End If Loop |
xzibitx je napisal/a: |
Da ne podpirate lenobe je čis prov sam res nimam pojma kako bi lahko to naredu. To z OR nism prepričan če je prov ker mi je ob zamenjavi AND funkcije z funkcijo OR led dioda skos gorela. Pravilnostne tabele sem pogledal in vem kaj morem naredit nimam pa pojma kako bi to naredil. Ko sem zamenjal funkcijo OR in vstavil XOR mi pa niti ledica ni več gorela ampak sem dobil ogromno napak napak [slovenščina je zame švedska vas] da res nimam pojma kako bi se to nardil. |
Koda: |
$regfile = "m32def.dat"
$crystal = 4000000 'poišči primer za ta m32 in tu dodaj še steke 'Predvidevam, da imaš na PORTD tipke na PORTA pa ledice Config Porta = Output Led_0 Alias Porta.0 Led_1 Alias Porta.1 'itd Config Portd = Input Tipka_0 Alias Pind.0 Tipka_1 Alias Pind.1 'itd Porta = 255 ' 'Config Debounce = 80 ' sedaj še ne rabiš te vrstice 'Dim Led As Byte '// LED JE POSAMIČNA ENORA 'Dim Tipka As Byte '// TIPKA JE POSAMIČNA Do If Pind.0 = 0 Then Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 Porta = &B00000000 Wait 2 Porta = &B11111111 Wait 2 If Tipka_0 = 0 Then Set Led_0 Else Reset Led_0 'If Pind.0 = 0 Then ' Porta = Led ' Led = Not Led ' NISI ZAKLJUČIL IF STAVKA ' Else 'OZIROMA TA ELSE TU NE PAŠE ' End If End If Loop End |
Citiram: |
Debounce Pinb.7 , 0 , Program , Sub Xor |
Koda: |
$regfile = "m32def.dat" " $crystal = 4000000 Config Porta = Output Config Portb = Input Main: do Debounce Pinb.7 , 0 , Program , Sub ' tale Xor nima kaj tle iskati Debounce PINB.6 , 0 , Program1 , Sub 'če imaš posamezen pin definiran kot vhod, potem daj pinb.x loop Program: Porta = &B10000000 Return Program1: Porta = &B00000000 Return |
Koda: |
Dim Var3 As Word , Var2 As Byte , Var1 As Byte Var3 = 12345 Print Bin(var3) Shift Var3 , Right , 4 Var1 = Var3 Print Bin(var1) Shift Var3 , Left , 4 ' alternativa :var2= var3<<4 ? Var2 = Var3 Print Bin(var2) Var3 = Makeint(var2 , Var1) Print Var3 ' preverim če je pravilni rezultat |
Koda: |
Dim Var3 As Word , Var2 As Byte , Var1 As Byte Var3 = 12345 Print Bin(var3) Var2 = Var3 Print Bin(var2) Shift Var3 , Right , 8 Print Bin(var3) Var1 = Var3 Print Bin(var1) Var3 = Makeint(var2 , Var1) Print Var3 |
Koda: |
Dim Var3 As Word , Var2 As Byte , Var1 As Byte Var3 = 12345 : Var2 = Var3 Shift Var3 , Right , 8 : Var1 = Var3 Var3 = Makeint(var2 , Var1) Print Var3 |
Koda: |
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI Config Scl = Portc.5 ' we need to provide the SCL pin name Config Sda = Portc.4 ' we need to provide the SDA pin name I2cinit ' we need to set the pins in the proper state Config Twi = 100000 'clock speed Do Pulsein Motor1 , Pinb , 1 , 1 ' Na portb prejema PWM vrednosti Pulsein Motor2 , Pinb , 2 , 1 Pulsein Motor3 , Pinb , 3 , 1 Pulsein Motor4 , Pinb , 4 , 1 'in jih nato pošlje po I2c I2cstart I2cwbyte &H70 ' Slave address I2cwbyte Motor1 I2cwbyte Motor2 I2cwbyte Motor3 I2cwbyte Motor4 I2cstop Loop |
Koda: |
Config Sda = Portc.4 Config Scl = Portc.5 Config Twislave = &H70 , Btr = 1 , Bitrate = 100000 'Slave Address, clock speed Const Timer2reload = 156 'Timer, ki vsakih 20ms Generira pulz za PWM servo signal Config Timer2 = Timer , Prescale = 1024 Load Timer2 , Timer2reload On Ovf2 Timer2_isr Enable Ovf2 Start Timer2 Enable Interrupts Do Loop Timer2_isr: 'Generira PWM servo signal Load Timer2 , Timer2reload Portb.1 = 1 For I = 0 To Motor1 Waitus 10 Next Portb.1 = 0 '''''''''''''''''''''''''''''''''''''''' Portb.2 = 1 For I = 0 To Motor2 Waitus 10 Next Portb.2 = 0 '''''''''''''''''''''''''''''''''''''''' Portb.3 = 1 For I = 0 To Motor3 Waitus 10 Next Portb.3 = 0 '''''''''''''''''''''''''''''''''''''''' Portb.4 = 1 For I = 0 To Motor4 Waitus 10 Next Portb.4 = 0 Return '''''''''''''''''''''''''''''''''''''''''''' Twi_stop_rstart_received: Return '''''''''''''''''''''''''''''''''''''''''''''' Twi_addressed_goread: Return '''''''''''''''''''''''''''''''''''''''''' Twi_addressed_gowrite: Return '''''''''''''''''''''''''''''''''''''''''' Twi_gotdata: Select Case Twi_btw Case 1 : Motor1 = Twi - 40 ' Spremenljivke napolni z vrednosti, ki jih prejme po i2c Case 2 : Motor2 = Twi - 40 Case 3 : Motor3 = Twi - 40 Case 4 : Motor4 = Twi - 40 End Select Print Motor1 'In jih pošlje po uart Print Motor2 Print Motor3 Print Motor4 Return '''''''''''''''''''''''''''''''''''''''' Twi_master_needs_byte: Return '''''''''''''''''''''''''''''''''''''''' Twi_master_need_nomore_byte: Return |
Koda: |
$regfile = "m8def.dat"
$prog &HFF , &HE1 , &HD9 , &H00 Config Servos = 2 , Servo1 = Portc.1 , Servo2 = Portc.2 , Reload = 10 'konfiguriras servota Config Portc.1 = Output Config Portc.2 = Output Enable Interrupts Servo(1) = 10 '10 times 10 = 100 uS on Servo(2) = 10 dim podatek1 as word 'za primer sem dolocil dve spremenljivki dim podatek2 as word podatek1 = 25 'spremenljivkama sem dolocil dve vrednosti (samo za primer, da ve kam postaviti servota ob inicializaciji) podatek2= 135 do 'malo bomo ponavljali 'tu vmes pride vsa logika - skaliranje, mix komand, itd 'za prvi preizkus pa sem zaenkrat napisal samo naslednji sestavek: incr podatek1 'premakni servo za en delcek incr podatek2 if podatek1=210 then 'ce servo pride do skrajne tocke (vsaj pri mojih servotih je 210 ena skrajna tocka) podatek1 = 25 'ga postavi v drugo skrajno tocko endif if podatek2=210 then podatek2 = 25 endif Servo(1) = podatek1 'vrednost posljes na servo, in ti ni potrebno uporabljati waitus komand - tako program tece naprej, PWM pa se izvaja v ozadju Servo(2) = podatek2 Loop |
Koda: |
'Servo's need a pulse in order to operate
'with the config statement CONFIG SERVOS we can specify how many servo's we 'will use and which port pins are used 'A maximum of 16 servos might be used 'The SERVO statements use one byte for an interrupt counter and the TIMER0 'This means that you can not use TIMER0 anymore 'The reload value specifies the interval of the timer in uS Config Servos = 2 , Servo1 = Portc.1 , Servo2 = Portc.2 , Reload = 10 'we use 2 servos with 10 uS resolution(steps) |
Koda: |
On Pcint2 Isr_pcint0
Pcmsk2.6 = 1 'določim na katerem pinu bo prvič PCINT Enable Pcint2 Config Timer0 = Timer , Prescale = 64 Enable Interrupts ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Do Waitms 100 Print In3 Loop '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Isr_pcint0: If Pind.t = 1 Then 'preveri če je interrupt sprožen na prednjem ali zadnjem robu pulza Goto Naprej 'če je na prdnjem, potem samo resetira timer0 in se vrne End If 'Če je na zadnjem robu, potem gre naprej v program za branje vrednosti timerja Select Case T Case 4 : In1 = Timer0 'izbere pravo spremenljivko in jo napolni z vrednsostjo timerja Case 5 : In2 = Timer0 Case 6 : In3 = Timer0 Case 7 : In4 = Timer0 End Select T = T + 1 'spremenljivko t vsakič poveča za 1 If T > 7 Then T = 4 End If Pcmsk2 = 0 'spremenljivka t določi na katerem pinu bomo čakali pulz Pcmsk2.t = 1 Naprej: 'resetiranje timerja Timer0 = 0 Return |
Koda: |
oddajni mikrokontroler $regfile = "m8def.dat" $baud = 4800 $hwstack = 32 $swstack = 8 $framesize = 24 Config Portb.0 = Input Config Portb.1 = Input Config Portb.2 = Output Dim A As String * 1 Dim B As String * 1 A = Chr(65) B = Chr(66) Do If Pinb.0 = 1 Then Waitms 150 Print A Set Portb.2 End If If Pinb.1 = 1 Then Waitms 150 Print B Reset Portb.2 End If Loop |
Koda: |
sprejemni mikrokontroler $regfile = "m8def.dat" $baud = 4800 $hwstack = 32 $swstack = 8 $framesize = 24 Config Portd = Output Dim A As String * 1 Do A = Waitkey() If A = "{065}" Then Set Portd.7 Else Reset Portd.7 End If Loop |
Koda: |
..... Dim Os_x As Dword Dim Kot_x As Dword Dim Ux_skal As Dword Dim Adc_x As Dword Dim Ux As Dword Dim X_vred As Single Dim X As Single ..... Adc_x = Getadc(4) Adc_y = Getadc(3) Adc_z = Getadc(2) ..... Ux_skal = Adc_x * 1000 Ux = Ux_skal / 1023 Ux = Ux * 500 Kot_x = Ux - 165000 X_vred = Kot_x / 80000 X_vred = Kot_x : X = Asin(x_vred) X = Deg2rad(x) |
davyd1994 je napisal/a: |
Imam eno tažavo. Na mikrokrmilnik bi moral naložiti iz Bascoma program ki je za demo prevelik. Dobil sem neko starejšo krekano različico, ampak ta različica mi pa noče naložiti oz. neka napaka pri povezavi. Čip je ATmega32, nalagam preko ISP, s programatorjem pololu AVR ISP. |
Cule je napisal/a: |
... To je le del programa, program deluje, težava pa je v vrstici: " X_vred = Kot_x / 80000" , saj nevem kako naj definiram spremenljivko X_vred. Spremenljivka Ux ima lahko vrednost med 165000 pa 245000, torej bo X_vred med 0 in 1. Iz teh vrednosti bom izračunal asin (v radijanih) in jih spremenil v stopinje in s tem dobil kot med 0 in 90° Torej kako naj spremenim program, da bo delovalo pribljižno tako kot je napisano zgoraj. |
program_er je napisal/a: |
Kaj točno pa ne dela? Ti javi error (kakšen), ti narobe računa? |
Koda: |
Dim Os_x As Word Dim Os_y As Word Dim Os_z As Word Dim Acc As Single Dim S As Single ... Os_x = Getadc(4) Os_y = Getadc(3) Os_z = Getadc(2) ... Acc = Os_x ^ 2 + Os_y ^ 2 Os_z ^ 2 <-Error S = Sqr(acc) |
protoncek je napisal/a: |
Bascom dovoljuje v eni vrstici samo eno računsko operacijo. |
Cule je napisal/a: |
Eno vprašanje.
V Demo Bascom-AVRju prekoračim 4096 bytov kode, zato sem poskušal programirat s starejšo crackano verzijo bascoma. Program mi lepo "scompila", vendar mi po tem noče sprogramirat čip. Ideja je, da bi program v Hex obliki s drugim programom poslal na čip, vendar ne najdem pravega programa da bi to storil. Potrebujem pa takšnega da bi podpiral Avr ISP programatorje. *Vem da bi lahko kupil original verzijo Bascoma, pa recimo da v tem trenutku to ni opcija. |
protoncek je napisal/a: |
Jaz vedno programiram preko AVR studia, skoraj nikoli z Bascom-ovim vmesnikom. |
mucek je napisal/a: | ||
Če ne zaradi drugega zato, ker ti programiranje iz Bascoma eeprom povozi po defaultu Pa seveda nimaš dostopa do fuse bitov |
Koda: |
If S_la = 1 Then
If Tempc < 22.0 Then Portd.6 = 1 Else Portd.6 = 0 End If If Tempc > 25.0 Then Portd.7 = 1 Portb.1 = 1 Else Portd.7 = 0 Portb.1 = 0 End If End If If S_la = 0 Then If S_pec = 1 Then Portd.6 = 1 Else Portd.6 = 0 End If Portd.2 = 1 Portd.3 = 1 Portd.4 = 1 Portd.5 = 1 End If |
Koda: |
If Tempc > 25.0 Then Portd.7 = 1 Portb.1 = 1 wait 10 //Počaka 10 sekund, ali pa waitms 10 Portd.7 = 0 Portb.1 = 0 Else Portd.7 = 0 Portb.1 = 0 End If |
Koda: |
Digit_1:
Data &B00000000 , &B00001000 , &B00000001 , &B00001001 , &B00000010 , &B00001010 , &B00000011 , &B00001011 , &B00000100 , &B00001100 '0 1 2 3 4 5 6 7 8 9 |
protoncek je napisal/a: |
Upam, da veš, kako deluje XOR |
Koda: |
$crystal = 1000000
$regfile = "ATtiny2313.dat" $hwstack = 32 $swstack = 8 $framesize = 32 Dim Premor As Long Config Portb = Output Config Pind.2 = Input Portd.2 = 1 Config Pind.4 = Input Portd.4 = 1 On Int0 Int0_sub Config Int0 = Change Enable Int0 On Int1 Int1_sub Config Int1 = Change Enable Int1 Enable Interrupts Premor = 10 Do Debounce Pind.2 , 0 , Naprej , Sub Debounce Pind.4 , 0 , Nazaj , Sub Loop End Int0_sub: Debounce Pind.2 , 0 , Naprej , Sub Return Int1_sub: Debounce Pind.4 , 0 , Nazaj , Sub Return ' pol koraka Naprej: Do Portb = &B11111101 Waitms Premor Portb = 0 Portb = &B11110101 Waitms Premor Portb = 0 Portb = &B11110111 Waitms Premor Portb = 0 Portb = &B11110011 Waitms Premor Portb = 0 Portb = &B11111011 Waitms Premor Portb = 0 Portb = &B11101011 Waitms Premor Portb = 0 Portb = &B11101111 Waitms Premor Portb = 0 Portb = &B11101101 Waitms Premor Portb = 0 Loop Return Nazaj: Do Portb = &B11101101 Waitms Premor Portb = 0 Portb = &B11101111 Waitms Premor Portb = 0 Portb = &B11101011 Waitms Premor Portb = 0 Portb = &B11111011 Waitms Premor Portb = 0 Portb = &B11110011 Waitms Premor Portb = 0 Portb = &B11110111 Waitms Premor Portb = 0 Portb = &B11110101 Waitms Premor Portb = 0 Portb = &B11111101 Waitms Premor Portb = 0 Loop Return |
mato1111 je napisal/a: |
zdravo ker sem (popoln) začetnik me zanima če bi lahko nekdo bolj po domače razložil kako lahko sprogramiram da naprimer tipka 1 (PORTB.0) ob pritisku nanjo vklopi LED1 (PORTD.0) in ko pritisnem še enkrat da jo izklopi. |
Koda: |
tipka alias pinb.0 led1 alias portd.0 config tipka = input config led1 = output do debounce tipka,0,tipkasr,SUB loop tipkasr: toggle led1 return |
Koda: |
Dim Number As Eram String * 13 At 10 |
Koda: |
Dim Number As Eram String * 13 At 10
Dim Number2 As Eram String * 13 At 24 Dim Number3 As Eram String * 13 At 38 |
Koda: |
Dim Number As Eram String * 13 Dim Number2 As Eram String * 13 Dim Number3 As Eram String * 13 |
mato1111 je napisal/a: | ||
Mi lahko kdo pojasni kakšen pomen ima tukaj At 10 ? |
Koda: |
dim tekst as eram string*20
dim znaki(21) as eram byte at tekst overlay |
Koda: |
znaki(3) |
Citiram: |
Osebno, tako vedno sestavljam niz bajt po bajt, ko pride na vhodna vrata UART in ga prestrežem z prekinitvenim podprogramom. |
Koda: |
$regfile = "m8def.dat"
$crystal = 4000000 $baud = 9600 $hwstack = 32 $swstack = 8 $framesize = 24 Config Portb.1 = Input Vhod Alias Portb.1 Do If Vhod = 1 Then Print "Vhod sklenjen" End If If Vhod = 0 Then Print "Vhod razklenjen" End If Loop |
Koda: |
$regfile = "m8def.dat"
$crystal = 4000000 $baud = 9600 $hwstack = 32 $swstack = 8 $framesize = 24 Config Portb.1 = Input Vhod Alias Portb.1 dim ss as bit ' staro stanje Do If Vhod = 1 and ss = 0 Then Print "Vhod sklenjen" ss = 1 End If If Vhod = 0 and ss = 1 Then Print "Vhod razklenjen" ss = 0 End If Loop |
Koda: |
$crystal = 10000000 $regfile = "ATtiny2313.dat" $hwstack = 32 $swstack = 8 $framesize = 32 Config Clockdiv = 1 Config Pinb.2 = Output Pinb.2 = 1 Config Pinb.1 = Output Pinb.1 = 1 '( Pcmsk = &B00000001 'PIN Change Int ON PCINT0 pin_change_isr Set Gimsk.5 Enable Interrupts ') Pcmsk = &B00000001 On Pcint0 Pcint0_rutina 'Set Gimsk.1 Enable Pcint0 'Enable Interrupt Do Pinb.1 = 0 Waitms 100 Pinb.1 = Not Pinb.1 Loop End Pcint0_rutina: Pinb.1 = 1 Pinb.2 = 0 Wait 2 Pinb.2 = 1 Return |
Koda: |
On Pcint0 Isr_pcint0 'we jump to this label when one of the pins is changed Pcmsk0 = &B00011011 'enable pcint0-pcint3 (portb.0-portb.3) Eimsk = 0 Eicra = &B00000010 'rising edge generates interrupt Enable Pcint0 'we enable pcint0 as this has pcint0-pcint7 enable interrupts '******************************************************************************* Isr_pcint0: Disable Pcint0 ' tu naredi nekaj Enable Pcint0 Return '******************************************************************************* |
Koda: |
Dim Number As Eram String * 13 At 10 Dim Num As String * 80 Dim Msg As String * 160 Dim Inmsg As String * 160 Dim Gps As Byte Dim Pass_stored As String * 13 |
Koda: |
Pass_stored = Number |
Koda: |
Print "AT"
Wait 2 Print "AT+CMGF=1" 'Sprememba v text mode Wait 2 Print "AT+CMGR=1" ' get the message Getline If Inmsg <> "OK" Then Rled = 1 Gled = 1 Num = Inmsg Getline Gps = Split(num , Ar(1) , ",") Num = Ar(2) Gps = Len(num) Gps = Gps - 2 Num = Mid(num , 2 , Gps) Inmsg = Lcase(inmsg) If Inmsg = "microcontroller1" Then 'Geslo za shranitev številke Pass_stored = Num Number = Pass_stored Msg = "Password 1 Accepted" Send_sms Elseif Num = Pass_stored Then If Inmsg = "light on" Then Relay1 = 1 Status1 = 1 Num = Pass_stored Msg = "Light Switched ON" Send_sms Elseif Inmsg = "light off" Then Relay1 = 0 Status1 = 0 Num = Pass_stored Msg = "Light Switched OFF" Send_sms |
Koda: |
Sub Send_sms
Rled = 1 Wait 3 Print "AT+CMGS=" ; Chr(34) ; Num ; Chr(34) 'pošlji SMS Waitms 200 Print Msg ; Chr(26) Wait 5 Print "AT" Wait 2 Rled = 0 End Sub |
Koda: |
Sub Getline Inmsg = "" Do Gps = Inkey() If Gps > 0 Then Select Case Gps Case 13 : If Inmsg <> "" Then Exit Do ' Če kaj dobimo Case 10 : If Inmsg <> "" Then Exit Do ' Če kaj dobimo Case Else Inmsg = Inmsg + Chr(gps) ' Naredi string End Select End If Loop End Sub |
Koda: |
If Inmsg = "microcontroller1" Then 'Geslo za shranitev številke Pass_stored = Num Number = Pass_stored Msg = "Password 1 Accepted" Send_sms ' Elseif Inmsg = "microcontroller2" Then ' Pass_stored2 = Num ' Number2 = Pass_stored2 ' Msg = "Password 1 Accepted" ' Send_sms ' Elseif Num = Pass_stored Or Num = Pass_stored2 Then If Inmsg = "light on" Then Relay1 = 1 Status1 = 1 Num = Pass_stored Msg = "Light Switched ON" Send_sms Elseif Inmsg = "light off" Then Relay1 = 0 Status1 = 0 Num = Pass_stored Msg = "Light Switched OFF" Send_sms |
Koda: |
Dim Number As Eram String * 13 At 10
Dim Number2 As Eram String * 13 At 24 |
Koda: |
Dim Pass_stored As String * 13
Dim Pass_stored2 As String * 13 |
Koda: |
If Inmsg = "microcontroller1" Then 'Geslo za shranitev številke
Pass_stored = Num Number = Pass_stored Msg = "Password 1 Accepted" Send_sms Elseif Inmsg = "microcontroller2" Then Pass_stored2 = Num Number2 = Pass_stored2 Msg = "Password 2 Accepted" Send_sms Elseif Num = Pass_stored Or Num = Pass_stored2 Then If Inmsg = "light on" Then Relay1 = 1 Status1 = 1 Num = Pass_stored Msg = "Light Switched ON" Send_sms Elseif Inmsg = "light off" Then Relay1 = 0 Status1 = 0 Num = Pass_stored Msg = "Light Switched OFF" Send_sms |
protoncek je napisal/a: |
ammm...zato, ker ga ima(mo) doma, ostalo bi pa moral kupiti? ali pa mogoče zato, ker je mega644 dimenzijsko bogato večja od tiny-a?
poleg tega je neumno dajati 64k kontroler za 1k kode... tiny-a ni prav nič bolj za=bano programirati kot vse ostale. Kot tudi pri megi644 in ostalih moraš pri tiny-u narediti domačo nalogo in pogledati, kaj ima in kaj nima, pa gre brez problema. in, nazadnje ...ne vem, če je cena tiny-a slaba dva evra ravno NEPOMEMBNO manjša od mege644, ki stane dobrih 11.24 (cene HTE). OK; če ti ni problem denar metati stran, potem izvoli, ampak mislim da je vseeno manj za=bancije izbrisati ničlo pri INT kot plačati 5x več za mego... |
Citiram: |
Elseif Num = Pass_stored Or Num = Pass_stored2 Then
If Inmsg = "light on" Then Relay1 = 1 Status1 = 1 Num = Pass_stored Msg = "Light Switched ON" Send_sms Elseif Inmsg = "light off" Then Relay1 = 0 Status1 = 0 Num = Pass_stored Msg = "Light Switched OFF" Send_sms |
Koda: |
If Inmsg = "RING" Then Print "ATH" Rele1 = 0 Wait 5 Rele1 = 1 End if |
Koda: |
I = Instr(inmsg , "RING") ' look for CLIP If I > 0 Then 'found it Print "ATH" Rele1 = 0 Wait 5 Rele1 = 1 End If |
mato1111 je napisal/a: |
Mi lahko kdo prosim malo pomaga pri uporabi ADC-ja? Imam Mega8
Rad bi meril napetost do 12,5V (DC) Vem da moram uporabiti napetostni delilnik iz 12,5V na 5V Ne vem pa kaj moram uporabiti v programu kot REFERENCE |
Koda: |
If Vhod3 = 1 And Ss3 = 0 Then Alarm_sprozen Ss3 = 1 End If If Vhod3 = 0 And Ss3 = 1 Then Ss3 = 0 End If |
Koda: |
If Ss3 = 0 Then Alarm_sprozen Ss3 = 1 End If |
Koda: |
If Vhod1 = 1 And Ss1 = 0 Then Stetje Ss1 = 1 Elseif Vhod1 = 0 And Ss1 = 1 Then Ss1 = 0 End if Sub Stetje Incr A If A = 1 Then Num2 = Pass_stored Msg = "240x sklenjeno" Send_sms Elseif A = 240 Then A = 0 End If End Sub |
Koda: |
If Tipka3 = 0 Then Wait 1 If Tipka3 = 0 Then Cls Cursor Off Locate 2 , 2 Lcd "tipka3 pritisnjena" Wait 2 Cls End If End If |
Koda: |
$regfile = "xm128a3def.dat" $crystal = 16000000 $hwstack = 64 $swstack = 64 $framesize = 64 $lib "xmega.lib" $external _xmegafix_clear $external _xmegafix_rol_r1014 Config Osc = Disabled , Extosc = Enabled , Range = 12mhz_16mhz , Startup = Xtal_256clk ', 32khzosc = Enabled Config Sysclock = External , Prescalea = 1 , Prescalebc = 1_1 Config Com2 = 38400 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 Open "Com2:" For Binary As #2 Dim Spr As Byte Dim Rxc1_b As Bit Config Portf = Output Led Alias Portf.0 Led1 Alias Portf.2 On Usartc1_rxc Rxc_isr Enable Usartc1_rxc , Lo Enable Interrupts '/////////////////////////////////////////////////////////////////////////////// Do If Rxc1_b = 1 Then Print #2 , "Sprejeto=" ; Spr Reset Rxc1_b End If Waitms 200 Reset Led1 Loop '////////////////////////////////////////////////////////////////////////////// End '////////////////////////////////////////////////////////////////////////////// Rxc_isr: Spr = Inkey(#2) Set Rxc1_b Set Led1 Return '///////////////////////////////////////////////////////////////////////////// |
Koda: |
Prosim, kako moram narediti, da je koda v belem okvirju? |
Koda: |
A = Inkey() 'Lcd Hex(a) 'Cls If A = 2 Then ... End If |
Citiram: |
For the other UARTS, the variables are named similar. But they do have a
different number. A 1 for the second UART, a 3 for the third UART and a 4 for the fourth UART. Yes, the '2' is skipped. |
Koda: |
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled |
Koda: |
const Timer1Reload = 7812
config timer1=timer,prescale = 1024 load timer1 , Timer1Reload on ovf1 Timer1_isr enable timer1 start timer1 enable interrupts 'TUKAJ IMAŠ TVOJ PROGRAM, zraven dodaj: if sekunde=60 then sekunde=0 incr minute endif if minute=10 then minute=0 'narediš tisto na 10 minut end if '-------------------------------------- Timer1_ISR: load timer1, Timer1Reload incr sekunde return |
protoncek je napisal/a: |
Imaš par ukazov, s katerimi ga konfiguriraš, ampak v glavnem ne rabiš nič spreminjati, razen oddajno moč, če želiš. |
Ler je napisal/a: |
Tale modul HM-TRP 433Mhz - HopeRF gre z PCB anteno ali mora imeti zunanjo. Namreč rad bi spravil modul + vezje v dozozo fi60, pa sem omejen z prostorom. Kaka žička za anteno bi še šla kaj več pa bo že prostora zmanjkalo. |
Andro82 je napisal/a: |
Druga težava:
Merjenje temperature s petimi senzorji DS18b20. Zaradi konverzije je potrebna sekunda zakasnitve. S tipkami nastavljam željeno temperaturo problem pa je, ker tipka zaradi potrebne zakasnitve sedaj ni več dovolj odzivna. |
Citiram: |
V glavnem, linija DQ bo šla na 0, ko bo master poslal slaveu ti. read slot (vse kar pišem velja za direktno napajanje in ne za parazitno) in bo DS zaseden, brez tega bo ta linija na 1. Torej je branje v smislu digitalRead(sensor) popolnoma brez pomena, ker je sigurno v tistem trenutku na 1. In to pomeni, da, ko boš dal ukaz READ SCRATCHPAD (BEh), boš v času konverzije (44h) bral prejšnjo konverzijo in to toliko časa dokler nova konverzija ni izvršena, kar pomeni, da so bili odčitki, ki si jih dobil, enaki nekaj strani izpisa (kolikokrat je uspel v 750mS prebrati SCRATCHPAD). |
Andro82 je napisal/a: |
Druga težava: Merjenje temperature s petimi senzorji DS18b20. Zaradi konverzije je potrebna sekunda zakasnitve. S tipkami nastavljam željeno temperaturo problem pa je, ker tipka zaradi potrebne zakasnitve sedaj ni več dovolj odzivna. Hvala za pomoč! LP, Andrej |
Koda: |
Dim A As Byte Dim B As Byte Dim C As String * 10 C = "111255abcd" A = Left(C , 3) 'Rad bi dobil vrednost 111 B = Mid(C,4,6) 'Rad bi dobil vrednost 255 |
Koda: |
Dim A As String*5 Dim B As String*5 Dim C As String * 10 Dim A_val as word C = "111255abcd" A = Left(C , 3) 'Rad bi dobil vrednost 111 B = Mid(C,4,6) 'Rad bi dobil vrednost 255 A_val = val(A) 'Tu pretvoriš string A v vrednost A_val |
Koda: |
Dim A As Byte Dim B As Byte Dim C As String * 10 Dim C as string * 3 C = "111255abcd" D = Left(C , 3) A = Val(D) D = Mid(C,4,6) B = Val(D) |
Koda: |
Dim Uart As String * 20 Dim Stringtobyte As String * 4 Dim Izh1set As Byte Dim Time1 As Word Uart = "201100" Do Stringtobyte = Mid(uart , 3) Izh1set = Val(stringtobyte) Stringtobyte = Mid(uart , 4 , 7) Time1 = Val(stringtobyte) Print "/izh1set" ; Izh1set ; "/time1" ; Time1 Wait 1 Loop |
Koda: |
/izh1set76/time1100
|
Koda: |
Stringtobyte = Mid(uart , 3 , 1)
Izh1set = Val(stringtobyte) |
mato1111 je napisal/a: |
Že nekaj časa razmišljam kako, bi naredil, da če tiščim tipko recimo 2 sekundi naredi program1 če pa tiščim 4 sekunde pa naredi program2 brez da bi izvršil program1.
Nič pametnega mi ne pade na pamet |
Koda: |
Config Adc = Single , Prescaler = Auto , Reference = Avcc |
Koda: |
$regfile = "m16def.dat" $crystal = 8000000 $baud = 9600 Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , Rs = Portb.3 , E = Portb.2 Config Lcd = 16 * 2 Dim Keyread As Byte Dim Key As Byte Dim Code As Word Dim Mycode As Word Dim Code1 As Word Dim Digits As Byte Ddrd = 255 Portd = 0 Config Kbd = Portc , Debounce = 40 Cls Cursor Off Noblink Begin: Code = 0 Digits = 0 Point = 0 Scan: Cls Lcd "VNESI KODO" Do Keyread = Getkbd() If Keyread <> 16 Then Gosub Gotkey Waitms 100 Loop Gotkey: Ddrb = 255 Waitms 200 Key = Lookup(keyread , Dta) If Key <> 11 Then 'CE NI # If Key <> 15 Then 'CE NI * If Digits < 4 Then 'ce je manj kot 4 znaki Incr Digits Point = Digits + 6 Code = Code * 10 Code = Code + Key Cls Locate 2 , 1 Lcd Code End If End If End If If Key = 11 And Digits = 4 Then 'CE JE pritisnena # in 4 znaki potem POTRDI PIN Code = Code1 Cls Upperline Lcd "KODA SPREJETA" Lowerline Lcd Code Wait 3 Goto Begin End If If Key = 15 And Digits <= 4 Then 'CE JE pritisnjena * IZBRISI VNESENO Lowerline Lcd " " Code = 0 Digits = 0 Point = 0 Goto Scan End If Return Dta: Data 1 , 4 , 7 , 15 Data 2 , 5 , 8 , 0 Data 3 , 6 , 9 , 11 Data 65 , 66 , 67 , 68 |
Citiram: |
If Key = 11 And Digits = 4 Then 'CE JE pritisnena # in 4 znaki potem POTRDI PIN
Code = Code1 |
Koda: |
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function 'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128 'Because the ADC needs a clock from 50-200 KHz 'The AUTO feature, will select the highest clockrate possible Config Adc = Single , Prescaler = Auto 'Now give power to the chip Start Adc 'With STOP ADC, you can remove the power from the chip 'Stop Adc Dim W As Word , Channel As Byte Channel = 0 'now read A/D value from channel 0 Do W = Getadc(channel) Print "Channel " ; Channel ; " value " ; W Loop |
Koda: |
'Config Adc = Single , Prescaler = Auto, Reference = Internal
'The reference param may be : 'OFF : AREF, internal reference turned off 'AVCC : AVCC, with external capacitor at AREF pin 'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin |
Koda: |
Podatkicas = Mid(podatki_prejeto , 11 , 15) 'podatkicas=02112015223344 Stringtobyte = Mid(podatkicas , 1 , 2) 'dobi dan _day = Val(stringtobyte) Stringtobyte = Mid(podatkicas , 3 , 2) 'dobi mesec _month = Val(stringtobyte) Stringtobyte = Mid(podatkicas , 7 , 2) 'dobi leto (samo zadnji dve številki: 15) _year = Val(stringtobyte) Stringtobyte = Mid(podatkicas , 9 , 2) 'dobi ura _hour = Val(stringtobyte) Stringtobyte = Mid(podatkicas , 11 , 2) 'dobi minuta _min = Val(stringtobyte) Stringtobyte = Mid(podatkicas , 13 , 2) 'dobi sekunda _sec = Val(stringtobyte) Gosub Setdate Waitms 100 Gosub Settime Waitms 100 Gosub Getdatetime If _day < 10 Then Strday = "0" + Str(_day ) Else Strday = Str(_day ) End If If _month < 10 Then Strmonth = "0" + Str(_month ) Else Strmonth = Str(_month ) End If Stryear = "20" + Str(_year ) If _hour < 10 Then Strhour = "0" + Str(_hour ) Else Strhour = Str(_hour) End If If _min < 10 Then Strmin = "0" + Str(_min ) Else Strmin = Str(_min ) End If If _sec < 10 Then Strsec = "0" + Str(_sec ) Else Strsec = Str(_sec ) End If Print Strday ; Strmonth ; Stryear ; Strhour ; Strmin ; Strsec Getdatetime: I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' start address in 1307 I2cstart ' Generate start code I2cwbyte Ds1307r ' send address I2crbyte _sec , Ack I2crbyte _min , Ack ' minute I2crbyte _hour , Ack ' ure I2crbyte _day , Ack ' dan I2crbyte _month , Ack ' mesec I2crbyte _year , Nack ' leto I2cstop _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour) _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year) Return Setdate: _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 4 ' starting address in 1307 I2cwbyte _day ' dan I2cwbyte _month ' mesec I2cwbyte _year ' leto I2cstop Waitms 10 Return Settime: _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' starting address in 1307 I2cwbyte _sec ' sekunde I2cwbyte _min ' minute I2cwbyte _hour ' ure I2cstop Waitms 10 Return |
joze je napisal/a: |
Dan v tednu je od 1 do 7, kaj je kaj, določiš sam, jaz ponavadi rečem, da je 1 ponedeljek, 7 pa nedelja (dan se pri nas začne s ponedeljkom).
Kako določiš sam, kaj ni vezan na datum (dan)? Če pogledaš na kolendar za določeni datum (dan), vidiš kateri dan v tednu je. Se motim? |
Koda: |
I2crbyte _Weekday , Ack |
Koda: |
Getdatetime: I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' start address in 1307 I2cstart ' Generate start code I2cwbyte Ds1307r ' send address I2crbyte _sec , Ack ' sekunde I2crbyte _min , Ack ' minute I2crbyte _hour , Ack ' ure I2crbyte _Weekday , Ack ' < GLEJ TUKAJ I2crbyte _day , Ack ' dan I2crbyte _month , Ack ' mesec I2crbyte _year , Nack ' leto I2cstop _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour) _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year) Return |
Koda: |
'***Casovna prekinitev vsakih 100ms***
Const Timer1reload = 360 Config Timer1 = Timer , Prescale = 1024 Load Timer1 , Timer1reload On Ovf1 Timer1_int Enable Timer1 Start Timer1 Enable Interrupts |
Koda: |
Timer1_int:
Ledica = Not Ledica 'Ledica (Nek izhodni pin) spremeni stanje vsako casovno enoto. Load Timer1 , Timer1reload Incr stevec 'Nek stevec, ki se vsako casovno enoto poveca za 1 in definiran mora biti na zacetku programa. Return |
Koda: |
IF expression THEN
[ ELSEIF expression THEN ] [ ELSE ] END IF |
Koda: |
Dim A As Byte
A = 25 If A < 30 Then Print A < 30 Elseif A = 25 Then Print A = 25 Elseif A > 23 Then Print A > 23 End If |
mato1111 je napisal/a: |
Dva if stavka? |
Koda: |
If T_k > (T_b + 3) Then vklopi_Rele1
elseIf T_k <= T_b Then izklopi_Rele1 EndIf |
Koda: |
If večje Then....
ElseIf enako Then ...... ElseIf manjše Then ..... EndIf |
Jaka57 je napisal/a: | ||
Ne poznam Bascoma, toda naj bi šlo takole:
Če ne pozna operatorja <= potem še en if stavek ali logični OR ( If (T_k<T_b) OR (T_k=T_b) Then........ ). |
Koda: |
T_b1 = T_b + 3 If T_k > (T_c) Then vklopi_Rele1 elseIf T_k <= T_b Then izklopi_Rele1 EndIf |