Gunakan MimeTex/LaTex untuk menulis simbol dan persamaan matematika.

Welcome to Forum Sains Indonesia. Please login or sign up.

Maret 29, 2024, 01:18:21 PM

Login with username, password and session length

Topik Baru

Artikel Sains

Anggota
Stats
  • Total Tulisan: 139,653
  • Total Topik: 10,405
  • Online today: 191
  • Online ever: 1,582
  • (Desember 22, 2022, 06:39:12 AM)
Pengguna Online
Users: 0
Guests: 181
Total: 181

Aku Cinta ForSa

ForSa on FB ForSa on Twitter

coba program bascom avr sensor sht11 kontrol heater dan motor tapi error

Dimulai oleh Candra, Mei 23, 2013, 01:34:35 PM

« sebelumnya - berikutnya »

0 Anggota dan 1 Pengunjung sedang melihat topik ini.

Candra

$sim
$regfile = "m8535.dat"
$crystal = 12000000
$swstack = 40
$hwstack = 32
$framesize = 32

'Configuration Lcd
'----------------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
Config Lcd = 16 * 2
Cursor Off
Deflcdchar 1 , 28 , 20 , 28 , 32 , 32 , 32 , 32 , 32        'membuat karakter derajat

'Configuration  dan deklarasi variabel  sht11
'-----------------------------------------------
Config Pinc.0 = Output                                      'sck
Config Pinc.1 = Output                                      'motor
Dim Ctr As Byte
Dim Dataword As Word
Dim Command As Byte
Dim Suhu As String * 20

Dim Calc As Single
Dim Calc2 As Single
Dim Rhlinear As Single
Dim Rhlintemp As Single
Dim Tempc As Single
Dim Tempf As Single
Dim X As Single
Dim Faktor As Single
Dim Hasilc As Single
Dim Hum As Single

Const C1 = -4
Const C2 = 0.0405
Const C3 = -0.0000028
Const T1c = .01
Const T2 = .00008
Const T1f = .018

Sck Alias Portc.0
Dataout Alias Portc.1
Datain Alias Pinc.1
Declare Sub Getit()


'--Declaration of the other variables
'----------------------------------

Dim Svt As Single , Svt_s As Eram Single                    'set value temp
Dim Cvt As Single                                           'current value temp
Dim Cvh As Single                                           'current value humidity
Dim Hvt_h As Single , Hvt_l As Single                       ' histerisis temp
Declare Sub Main
Declare Sub Sv_up
Declare Sub Sv_down
Declare Sub Measure
Declare Sub Check_temp

'----Declaration the other i/o
'------------------------------------
Config Pina.0 = Input
Config Pina.1 = Input
Config Pina.2 = Input
Config Pina.3 = Input
Ddra = &B00000000
Porta = &B11111111                                          'activ Resistor Pul-up intern micro

Ok Alias Pina.0
Up Alias Pina.1
Down Alias Pina.2
Cancel Alias Pina.3

Config Portb.0 = Output
Config Portb.1 = Output
Motor Alias Portb.0
Heater Alias Portb.1
Heater = 0

Cls
Lcd "T=" ; Spc(3) ; Chr(1) ; "C" ; "H=" ; Spc(2)
Lowerline
Lcd "Sv=" ; Spc(3) ; Chr(1) ; "C" ; "Menit" ; Spc(2)
Svt = Svt_s
Main :
Gosub Measure
Gosub Check_temp
Debounce Up , 0 , Sv_up
Debounce Down , 0 , Sv_down
Goto Main


Measure :

Set Dataout                                                 'reset the serial communications first, it is easily confused!
For Ctr = 1 To 12
Set Sck
Waitus 2
Reset Sck
Waitus 2
Next Ctr


Do                                                          'continually read the tempfature and humidity

Command = &B00000011
Call Getit                                                 'Get the temperature, puts result in "dataword" for us
'
Tempf = T1f * Dataword
Tempf = Tempf - 40

Tempc = T1c * Dataword                                     'get celcius for later calculations and for "the rest of the world"
Tempc = Tempc - 40
X = Tempc - 32
Faktor = 5 / 9
Hasilc = X * Faktor
Suhu = Fusing(hasilc , "###.##")
Print "Temperature = " ; Suhu ; " (c)"
Cvt = Hasilc
Locate 1 , 3
Lcd Spc(3)
Locate 1 , 3
Lcd Cvt
Locate 2 , 4
Lcd Spc(3)
Locate 2 , 4
Lcd Svt


Command = &B00000101
Call Getit                                                 'get the humidity
Calc = C2 * Dataword
Calc2 = Dataword * Dataword                                'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
Calc2 = C3 * Calc2
Calc = Calc + C1
Rhlinear = Calc + Calc2


Calc = T2 * Dataword
Calc = Calc + T1c
Calc2 = Tempf - 25
Calc = Calc2 * Calc
Rhlintemp = Calc + Rhlinear

Hum = Fusing(rhlintemp , "##.##")
Print "Humidity adjusted for temperature = " ; Hum
Cvh = Rhlintemp
Locate 1 , 12
Lcd Spc(2)
Locate 1 , 12
Lcd Cvh

Wait 1
Loop
Return

Sub Getit()

Local Datavalue As Word
Local Databyte As Byte

                                               'start with "transmission start"
Set Sck
Reset Dataout
Reset Sck
Set Sck
Set Dataout
Reset Sck


                                                 'now send the command
Shiftout Dataout , Sck , Command , 1

Ddrc = &B11111101                                          'datain is now input
Config Pinc.1 = Input                                      'datain
Set Sck                                                    'click one more off
Reset Sck
Waitus 10                                                  'no idea why, but it doesn't work without it!
Bitwait Pinc.1 , Reset                                     'wait for the chip to have data ready

Shiftin Datain , Sck , Databyte , 1                        'get the MSB
Datavalue = Databyte

Ddrc = &B11111111
Config Pinc.1 = Output

Reset Dataout                                              'this is the tricky part- Lot's of hair pulling- have to tick the ack!
Set Sck
Reset Sck

Ddrb = &B11111101                                          'datain is now input
Config Pinc.1 = Input

Shiftin Datain , Sck , Databyte , 1                        'get the LSB
Shift Datavalue , Left , 8
Datavalue = Datavalue Or Databyte
                                      'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
Dataword = Datavalue

Ddrc = &B11111111
Config Pinc.1 = Output

Reset Dataout
Set Sck
Reset Sck

Ddrc = &B11111101                                          'datain is now input
Config Pinc.1 = Input

Shiftin Datain , Sck , Databyte , 1                        'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
                                    'Print "CRC value was - " ; Databyte

Ddrc = &B11111111
Config Pinc.1 = Output

Set Dataout
Set Sck
Reset Sck
Return


'+++++Increase Set temp by 1
'++++++++++++++++++++++++++++++++++

Sv_up:
Incr Svt
If Svt > 120 Then
Svt = 0
End If
Svt_s = Svt
Locate 2 , 4
Lcd Spc(3)
Locate 2 , 4
Lcd Svt
Goto Main

'-------Decrease set temp by1
'--------------------------------------

Sv_down:
If Svt <> 0 Then
Decr Svt
Else
Svt = 110
End If
Svt_s = Svt
Locate 2 , 4
Lcd Spc(3)
Locate 2 , 4
Lcd Svt
Goto Main

'===================================================
'

Check_temp:
Hvt_h = Svt + 3                                            'Hysteresis +3
If Cvt >= Hvt_h Then
Heater = 0
End If

Hvt_l = Svt - 3                                            'Hysteresis -3
If Cvt <= Hvt_l Then
Heater = 1

If Cvt > Hvt_l And Cvt < Hvt_h Then
        Heater = 1
End If
Return
'++++++++++++++++++++                                                        'end program
:'( :'( :(