cni
21.06.2007, 00:03
Hallo,
habe folgendes Problem:
Ich habe einen AVR ATMega8, der einen Sensor SHT75 (Feuchte und Themperatur) auslesen soll. Später soll das ganze dann auf einem Display dargestellt werden und 3 Ausgänge abhängig von der Themperatur bzw. Luftfeuchte geschaltet werden.
Nun, hier mal das Programm:
'************************************************* ****************************'
' Basic application for sensor SHT75. Humidity measuring is 8 bit and tempera-'
' ture is 12 bit resolution. Result is display on 16 char LCD module . '
' Sensor DATA pin is connect on PD1 and SCK on PD0. One LED is connect on PD2 '
' MCU pin to indicate measuring sequence. '
' Program size is 1800 bytes '
' '
'************************************************* ****************************'
$regfile = "m8def.dat"
$crystal = 16000000 ' used crystal frequency
$baud = 9600 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 ' default use 10 for the SW stack
$framesize = 32 ' default use 40 for the frame space
'Config Lcd = 16 * 1
'Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Dim Command As Byte , Msb As Byte , Lsb As Byte , Humi As Word
Dim I As Byte , Temp As Word , Celi As Word , Deseti As Word , Big_celi As Word
Deflcdchar 0 , 6 , 9 , 9 , 6 , 32 , 32 , 32 , 32 'Creating "°" character
Sck Alias Portd.6 'Serial CLOCK
Sdata Alias Pind.7 'Serial DATA for INPUT
Sdata_out Alias Portd.7 'Serial DATA for OUTPUT
Ddrd.6 = 1 'Data direction for SCK
Config Watchdog = 2048 'Watchdog time setting
Start Watchdog 'watchdog enable
'Cursor Off
'Cls 'LCD must move back to DATA mode after creating chr
'Waitms 20 'Must wait to stabilize LCD
Start1: 'Main program
'Ddrd.2 = 1
Ddrd.6 = 1
'Set Portd.2 'Switch ON LED (measuring start)
Command = &B00011110 'SOFTWARE RESET command
Gosub Trans_start
Gosub Send_cmd
Gosub Write_status
Gosub Conn_reset
Gosub Read_humidity
Gosub Conn_reset
Gosub Read_temp
'Cursor Off
'Reset Portd.2 'Switch OFF LED (measuring finish)
'Cls ' Clear display
'Waitms 10
'Locate 1 , 5
'Lcd "%RH"
'Locate 1 , 2
'Lcd Humi
Print "Luftfeuchte: " ; Humi ; " %"
'If Celi < 10 Then
' Locate 1 , 10
' Lcd Celi
'Else
'Locate 1 , 9
'End If
'Lcd Celi
'Locate 1 , 11
'Lcd "."
'Locate 1 , 12
'Lcd Deseti
'Locate 1 , 14
'Lcd Chr(0)
'Locate 1 , 15
'Lcd "C"
Print "Themperatur: " ; Celi ; "," ; Deseti ; " " ; Chr(167) ; "C"
Print
Reset Watchdog
Powerdown
'***************'
' HUMIDITY READ '
'***************'
Read_humidity:
Command = &B00000101 'Command "READ HUMIDITY"
Gosub Send_cmd
Waitms 20 'Wait to finish measuring
Gosub Sensor_readout
Humi = 0 'Start of humidity calculation (see App. note)
Humi = Humi + Msb
Shift Humi , Left , 8
Humi = Humi + Lsb
If Humi <= 107 Then
Humi = 143 * Humi
If Humi < 512 Then Humi = 512
Humi = Humi - 512
Else
Humi = 111 * Humi
Humi = Humi + 2893
If Humi > 25600 Then Humi = 25600
End If
Shift Humi , Right , 8
Return
'******************'
' TEMPERATURE READ '
'******************'
Read_temp:
Command = &B00000011 'Command "READ TEMPERATURE"
Gosub Send_cmd
Waitms 60
Gosub Sensor_readout
Temp = 0 'Calculation (see App. note)
Temp = Temp + Msb
Shift Temp , Left , 8
Temp = Temp + Lsb
Temp = Temp * 10
Temp = Temp / 25
Temp = Temp - 400
Celi = Temp / 10
Big_celi = Celi * 10
Deseti = Temp - Big_celi
Return
'******************'
' TRANSMISION START'
'******************'
Trans_start:
Config Sdata = Output
Set Sdata_out
Set Sck
Reset Sdata_out
Reset Sck
Waitus 5
Set Sck
Set Sdata_out
Reset Sck
Return
'******************'
' CONNECTION RESET '
'******************'
Conn_reset:
Config Sdata = Output
Reset Sck
Set Sdata_out
For I = 1 To 12
Set Sck
Reset Sck
Next I
Goto Trans_start
Return
'**************'
' COMMAND SEND '
'**************'
Send_cmd:
Config Sdata = Output
Shiftout Sdata_out , Sck , Command , 1 ', 8 , 1 'data change when sck goes low, 8bit out, 1uS delay
Ddrd.7 = 0
Reset Sck
Set Sck
Bitwait Sdata , Reset 'Wait ACK
Reset Sck
Return
Sensor_readout:
Config Sdata = Input
Shiftin Sdata , Sck , Msb , 1 , 8 , 1
Config Sdata = Output
Reset Sdata_out
Set Sck
Reset Sck
Config Sdata = Input
Shiftin Sdata , Sck , Lsb , 1 , 8 , 1
Config Sdata = Output
Set Sdata_out 'pull-up ACK (CRC not use)
Set Sck
Reset Sck
Return
Write_status:
Gosub Trans_start
Command = &B00000110
Gosub Send_cmd
Command = &B00000001 'Switch to 8/12 bit resolution
Gosub Send_cmd
Return
End
Das Problem ist nun, das auf der RS232 Schnittstelle immer das gleiche ankommt:
Luftfeuchte: 0 %
Themperatur: 11,2 °C
Anscheinend wird der SHT nicht richtig angesprochen oder so.
Kann mir evtl. jemand helfen?
Danke
habe folgendes Problem:
Ich habe einen AVR ATMega8, der einen Sensor SHT75 (Feuchte und Themperatur) auslesen soll. Später soll das ganze dann auf einem Display dargestellt werden und 3 Ausgänge abhängig von der Themperatur bzw. Luftfeuchte geschaltet werden.
Nun, hier mal das Programm:
'************************************************* ****************************'
' Basic application for sensor SHT75. Humidity measuring is 8 bit and tempera-'
' ture is 12 bit resolution. Result is display on 16 char LCD module . '
' Sensor DATA pin is connect on PD1 and SCK on PD0. One LED is connect on PD2 '
' MCU pin to indicate measuring sequence. '
' Program size is 1800 bytes '
' '
'************************************************* ****************************'
$regfile = "m8def.dat"
$crystal = 16000000 ' used crystal frequency
$baud = 9600 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 ' default use 10 for the SW stack
$framesize = 32 ' default use 40 for the frame space
'Config Lcd = 16 * 1
'Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
Dim Command As Byte , Msb As Byte , Lsb As Byte , Humi As Word
Dim I As Byte , Temp As Word , Celi As Word , Deseti As Word , Big_celi As Word
Deflcdchar 0 , 6 , 9 , 9 , 6 , 32 , 32 , 32 , 32 'Creating "°" character
Sck Alias Portd.6 'Serial CLOCK
Sdata Alias Pind.7 'Serial DATA for INPUT
Sdata_out Alias Portd.7 'Serial DATA for OUTPUT
Ddrd.6 = 1 'Data direction for SCK
Config Watchdog = 2048 'Watchdog time setting
Start Watchdog 'watchdog enable
'Cursor Off
'Cls 'LCD must move back to DATA mode after creating chr
'Waitms 20 'Must wait to stabilize LCD
Start1: 'Main program
'Ddrd.2 = 1
Ddrd.6 = 1
'Set Portd.2 'Switch ON LED (measuring start)
Command = &B00011110 'SOFTWARE RESET command
Gosub Trans_start
Gosub Send_cmd
Gosub Write_status
Gosub Conn_reset
Gosub Read_humidity
Gosub Conn_reset
Gosub Read_temp
'Cursor Off
'Reset Portd.2 'Switch OFF LED (measuring finish)
'Cls ' Clear display
'Waitms 10
'Locate 1 , 5
'Lcd "%RH"
'Locate 1 , 2
'Lcd Humi
Print "Luftfeuchte: " ; Humi ; " %"
'If Celi < 10 Then
' Locate 1 , 10
' Lcd Celi
'Else
'Locate 1 , 9
'End If
'Lcd Celi
'Locate 1 , 11
'Lcd "."
'Locate 1 , 12
'Lcd Deseti
'Locate 1 , 14
'Lcd Chr(0)
'Locate 1 , 15
'Lcd "C"
Print "Themperatur: " ; Celi ; "," ; Deseti ; " " ; Chr(167) ; "C"
Reset Watchdog
Powerdown
'***************'
' HUMIDITY READ '
'***************'
Read_humidity:
Command = &B00000101 'Command "READ HUMIDITY"
Gosub Send_cmd
Waitms 20 'Wait to finish measuring
Gosub Sensor_readout
Humi = 0 'Start of humidity calculation (see App. note)
Humi = Humi + Msb
Shift Humi , Left , 8
Humi = Humi + Lsb
If Humi <= 107 Then
Humi = 143 * Humi
If Humi < 512 Then Humi = 512
Humi = Humi - 512
Else
Humi = 111 * Humi
Humi = Humi + 2893
If Humi > 25600 Then Humi = 25600
End If
Shift Humi , Right , 8
Return
'******************'
' TEMPERATURE READ '
'******************'
Read_temp:
Command = &B00000011 'Command "READ TEMPERATURE"
Gosub Send_cmd
Waitms 60
Gosub Sensor_readout
Temp = 0 'Calculation (see App. note)
Temp = Temp + Msb
Shift Temp , Left , 8
Temp = Temp + Lsb
Temp = Temp * 10
Temp = Temp / 25
Temp = Temp - 400
Celi = Temp / 10
Big_celi = Celi * 10
Deseti = Temp - Big_celi
Return
'******************'
' TRANSMISION START'
'******************'
Trans_start:
Config Sdata = Output
Set Sdata_out
Set Sck
Reset Sdata_out
Reset Sck
Waitus 5
Set Sck
Set Sdata_out
Reset Sck
Return
'******************'
' CONNECTION RESET '
'******************'
Conn_reset:
Config Sdata = Output
Reset Sck
Set Sdata_out
For I = 1 To 12
Set Sck
Reset Sck
Next I
Goto Trans_start
Return
'**************'
' COMMAND SEND '
'**************'
Send_cmd:
Config Sdata = Output
Shiftout Sdata_out , Sck , Command , 1 ', 8 , 1 'data change when sck goes low, 8bit out, 1uS delay
Ddrd.7 = 0
Reset Sck
Set Sck
Bitwait Sdata , Reset 'Wait ACK
Reset Sck
Return
Sensor_readout:
Config Sdata = Input
Shiftin Sdata , Sck , Msb , 1 , 8 , 1
Config Sdata = Output
Reset Sdata_out
Set Sck
Reset Sck
Config Sdata = Input
Shiftin Sdata , Sck , Lsb , 1 , 8 , 1
Config Sdata = Output
Set Sdata_out 'pull-up ACK (CRC not use)
Set Sck
Reset Sck
Return
Write_status:
Gosub Trans_start
Command = &B00000110
Gosub Send_cmd
Command = &B00000001 'Switch to 8/12 bit resolution
Gosub Send_cmd
Return
End
Das Problem ist nun, das auf der RS232 Schnittstelle immer das gleiche ankommt:
Luftfeuchte: 0 %
Themperatur: 11,2 °C
Anscheinend wird der SHT nicht richtig angesprochen oder so.
Kann mir evtl. jemand helfen?
Danke