Depok Instruments

We Present Technologies As Arts

Source Code BASCOM-AVR for SHT11

$regfile = “m8535.dat”

$crystal = 11059200

‘$lib “lcd4busy.lib”

$baud = 9600

‘Const _lcdport = Porta

‘Const _lcdddr = Ddra

‘Const _lcdin = Pina

‘Const _lcd_e = 2

‘Const _lcd_rw = 1

‘Const _lcd_rs = 0

Ddrc = 255

Portc = 255

Ddra = 255

Porta = 255

‘Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.3

‘Config Lcd = 16 * 2

‘Config Adc = Single , Prescaler = Auto , Reference = Avcc

‘Start Adc

Dim Ctr As Byte

Dim Dataword As Word

Dim Command As Byte

Dim Dis 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 A As Word , I As Integer

Sck Alias Portc.0

Dataout Alias Portc.1

Datain Alias Pinc.1

Declare Sub Getit()

Declare Sub Connectionreset

Call Connectionreset

Const C1 = -4

Const C2 = 0.0405

Const C3 = -0.0000028

Const T1c = 0.01

Const T2 = 0.00008

‘Const T1f = .018

Do

‘Cls

‘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

 Dis = Fusing(tempc , “###.##”)

 Print “Temp = ” ; Dis ; “C”

 ‘Lcd “Temp  = ” ; Dis ; Chr(0) ; “C”

 ‘Portc = Tempc

 ‘Reset Portc.7

 ‘Porta = Tempc

 ‘Reset Porta.0

 Waitms 250

 ‘Waitms 250

 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

 Dis = Fusing(rhlinear , “##.##”)

 Print “Humidity adjusted for linear = ” ; Dis

 Calc = T2 * Dataword

 Calc = Calc + T1c

 Calc2 = Tempc – 25

 Calc = Calc2 * Calc

 Rhlintemp = Calc + Rhlinear

 Dis = Fusing(rhlintemp , “##.##”)

 Print “Humidity adjusted for temperature = ” ; Dis

 Print

 ‘Locate 2 , 1

 ‘Lcd “Humi = ” ; Dis ; ” %”

 ‘Portc = Rhlintemp

 ‘Set Portc.7

 ‘Porta = Rhlintemp

 ‘Set Porta.7

 Waitms 250

 ‘Waitms 250

 Cls

Loop

Sub Connectionreset()

Ddrc = &B11111111                                           ‘all port b are output

Config Pinc.0 = Output                                      ‘sck

Config Pinc.1 = Output                                      ‘datain

Set Dataout

For Ctr = 1 To 10

 Set Sck

 Waitms 2

 Reset Sck

 Waitms 2

Next Ctr

 Set Sck

 Reset Dataout

 Reset Sck

 Set Sck

 Set Dataout

 Reset Sck

End Sub

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 = &B1111_1101                                         ‘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 = &B1111_1111

 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

 Ddrc = &B1111_1101                                         ‘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 = &B1111_1111

 Config Pinc.1 = Output

 Reset Dataout

 Set Sck

 Reset Sck

 Ddrc = &B1111_1101                                         ‘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 = &B1111_1111

 Config Pind.1 = Output

 Set Dataout

 Set Sck

 Reset Sck

End Sub

About these ads

November 15, 2011 - Posted by | 2.6 AVR [III], 3.2 Program

8 Komentar »

  1. mas bs d pake buat atmega8535 gk???
    trus portd buat sck dan data bs diganti k port lain gk???
    cara download ke atmega gmana????
    minta bantuannya y….
    soalnya saya dh beli sht11 buatan depok instrument v blum bs pake…..

    Komentar oleh randy | April 22, 2012 | Balas

    • Sdr. Randy,

      DI-Smart SHT11 dapat dihubungkan langsung dengan ATmega8535, kami sarankan menggunakan DIM.001 DI-Smart AVR System.
      PIN-PIN yg digunakannya pun dapat disesuaikan dengan sistem yang dibuat.
      Cara mendownload ke ATmega8535 perlu adanya downloader, kami sarankan menggunakan DIM.024 DI-USB AVR ISP V2

      Salam,
      Depok Instruments Support

      Komentar oleh depokinstruments | April 23, 2012 | Balas

  2. mas… saya punya punya tugas buat sistem monitorin gas CO2 pake sensor TGS4161 dan sensor suhu menggunakan LM35 kira2 coding di atas bisa di modif gk ya mas? atau ada codingnya sendiri? thx mas..

    Komentar oleh roni | Juni 13, 2012 | Balas

    • Terlalu berbeda prinsip kerja sensor-sensornya.

      Komentar oleh depokinstruments | Juni 15, 2012 | Balas

  3. mas…saya sudah ada Super smart AVR, artinya Smart SHT11 bisa digabung/rangkai. bagaimana caranya ? kalo baca/record/save data(nilai suhu/kelembaban) bisa di tampil/simpan di Excel ga mas ? trim’s mas

    Komentar oleh Arton | Agustus 29, 2012 | Balas

    • Untuk merangkai dapat dilihat petunjuknya pada DI-Smart SHT11. Sedangkan untuk program lanjutan silakan dipelajari lebih lanjut.

      Komentar oleh depokinstruments | Agustus 29, 2012 | Balas

  4. praximax depok sebelah mana yah? oh iya, apakah dalam pembelian sensor sht11 ini akan mendapat tata cara penggunaanya? atau misalkan tutorial untuk pemograman di atmega8535 dng bahasa c?

    Komentar oleh kurif | April 21, 2013 | Balas


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.

Bergabunglah dengan 58 pengikut lainnya.

%d bloggers like this: