Selamat datang di ForSa! Forum diskusi seputar sains, teknologi dan pendidikan Indonesia.
0 Anggota dan 1 Pengunjung sedang melihat topik ini.
Ini nh contoh program yang pernah ane pakai, emang perlu dilakukan linierisasi'Routine to read the SHT11 Humidity sensor chip'By Stuart Leslie'Contact stu@4sightinc.com with any questions'Uses BascomAVR'a .01 uf capacitor across VCC and Ground on the SHT11 really cleans up the data'a pullup is required on "data" pin as shown in the data sheetDim Ctr As ByteDim Dataword As WordDim Command As ByteDim Dis As String * 20Dim Calc As SingleDim Calc2 As SingleDim Rhlinear As SingleDim Rhlintemp As SingleDim Tempc As SingleDim Tempf As SingleConst C1 = -4Const C2 = 0.0405Const C3 = -0.0000028Const T1c = .01Const T2 = .00008Const T1f = .018Sck Alias Portb.0Dataout Alias Portb.1Datain Alias Pinb.1Redled Alias Portb.2Declare Sub Getit()Ddrb = &B11111111 'all port b are outputConfig Pinb.0 = Output 'sckConfig Pinb.1 = Output 'datain'reset the serial communications first, it is easily confused!Set DataoutFor Ctr = 1 To 12 Set Sck Waitus 2 Reset Sck Waitus 2Next CtrDo '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(tempf , "###.##") Print "Temperature = " ; Dis ; " (F)" 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 Wait 1LoopSub 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 Ddrb = &B11111101 'datain is now input Config Pinb.1 = Input 'datain Set Sck 'click one more off Reset Sck Waitus 10 'no idea why, but it doesn't work without it! Bitwait Pinb.1 , Reset 'wait for the chip to have data ready Shiftin Datain , Sck , Databyte , 1 'get the MSB Datavalue = Databyte Ddrb = &B11111111 Config Pinb.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 Pinb.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 Ddrb = &B11111111 Config Pinb.1 = Output Reset Dataout Set Sck Reset Sck Ddrb = &B11111101 'datain is now input Config Pinb.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 Ddrb = &B11111111 Config Pinb.1 = Output Set Dataout Set Sck Reset SckEnd SubEnd
eh SHT11 itu kan I2C, kenapa ga pake library yang sudah tersedia di codevision mengenai I2C?
O, sori, aq ga liat programmu dulu iy di codevision dah ada juga
Kutip dari: 0y1k pada Juli 31, 2010, 12:05:10 AMeh SHT11 itu kan I2C, kenapa ga pake library yang sudah tersedia di codevision mengenai I2C?modul sht11 yang ane pake udah gak menggunakan I2C untuk akses datanya, datanya udah langsung masuk ke mikro gan, modulnya ane buatan sini gan http://www.innovativeelectronics.com/sebenarnya dari inovative udah ada contohnya tapi pas ane coba belum bisa juga.Kutip dari: rizqi_fs pada Agustus 01, 2010, 07:29:33 AMO, sori, aq ga liat programmu dulu iy di codevision dah ada jugaprogramnya udah ane upload gan.
Kutip dari: dancyber pada Agustus 03, 2010, 07:59:12 AMKutip dari: 0y1k pada Juli 31, 2010, 12:05:10 AMeh SHT11 itu kan I2C, kenapa ga pake library yang sudah tersedia di codevision mengenai I2C?modul sht11 yang ane pake udah gak menggunakan I2C untuk akses datanya, datanya udah langsung masuk ke mikro gan, modulnya ane buatan sini gan http://www.innovativeelectronics.com/sebenarnya dari inovative udah ada contohnya tapi pas ane coba belum bisa juga.Kutip dari: rizqi_fs pada Agustus 01, 2010, 07:29:33 AMO, sori, aq ga liat programmu dulu iy di codevision dah ada jugaprogramnya udah ane upload gan. trus k'lo ga pake I2C akses datanya pake apa?