Enrock
20.11.2007, 08:25
Servus und Hallo,
ich habe ein Problem mit meinem SHT75 Temperatur und Feuchte-Sensor. Und zwar bekomme ich diesen an meinem PIC 16F877A nicht zum laufen.
Hier erstmal mein Code
list p=16f877a ; list directive to define processor
#include <p16f877a.inc> ; processor specific variable definitions
; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
EXTERN LCD_AN
;***********************Variablendefinition******* ********************
D_SENSOR_DATA UDATA 0x040 ;start of general purpose registers
COUNTER_SEN res 1 ; Counter in Init
TEMP_DATA res 1 ; TEMP_DATA
TEMP_ACK RES 1 ; TEMP_ACK
TEMP_TEST res 1 ; TEMP_TEST
ADDR_COMM res 1 ; Address and Command
HIGH_BYTE res 1 ; Oberste 8 bit
LOW_BYTE res 1 ; untere 8 bit
GLOBAL HIGH_BYTE, LOW_BYTE
EXTERN DELAY_30ms
#define SENSOR_DATA PORTA, 1
#define SENSOR_SCK PORTB, 2
#define SENSOR_DATA_DIR TRISA, 1
#define SENSOR_SCK_DIR TRISB, 2
PROG1 Code ; START
;ORG 0x000
goto START_SHT
;
;org 0x0005 ; Interrupt
;retfie
START_SHT
GLOBAL START_SHT
;***********************Init********************** ******************
movlw 0x005
movwf HIGH_BYTE
movwf LOW_BYTE
movwf ADDR_COMM
movlw b'00000101' ; Messe Feuchte
movwf ADDR_COMM
bsf STATUS, RP0 ; Bank1
bcf SENSOR_SCK_DIR ; Output
bcf SENSOR_DATA_DIR ; Output
bcf STATUS, RP0 ; Bank0
;***********************Transmission*Start******** ********************
bsf SENSOR_DATA
bsf SENSOR_SCK
bcf SENSOR_DATA
bcf SENSOR_SCK
bsf SENSOR_SCK
bsf SENSOR_DATA
movlw d'8'
movwf COUNTER_SEN
;***********************Feuchte messen****************************
SEND_BIT_TO_SENSOR
bcf SENSOR_SCK
btfss ADDR_COMM,7
goto SEND_NULL
bsf SENSOR_DATA
goto SEND_BIT
SEND_NULL
bcf SENSOR_DATA
SEND_BIT
bsf SENSOR_SCK
rlf ADDR_COMM,f ; rotate
decfsz COUNTER_SEN,F
goto SEND_BIT_TO_SENSOR
bcf SENSOR_SCK
bsf STATUS, RP0
bsf SENSOR_DATA_DIR ; Input
bcf STATUS, RP0
bsf SENSOR_SCK
btfss SENSOR_DATA ; Acknowledge bekommen?
goto ACK_GET_FROM_SENSOR
goto ACK_LOST
;***********************Get Acknowledge****************************
ACK_GET_FROM_SENSOR ; Ack bekommen
;movlw b'00001111'
;movwf PORTB
bcf SENSOR_SCK
movlw d'30'
movwf COUNTER_SEN
call DELAY_30ms
;***********************Daten empfangen****************************
WAIT_FOR_SENSORDATA
btfss SENSOR_DATA
goto READ_DATA
decfsz COUNTER_SEN,f
goto WAIT_FOR_SENSORDATA
goto ACK_LOST ; wenn keine Daten dann ende
;***********************Lese*Daten**************** *****************
READ_DATA
call GET_BYTE
movf ADDR_COMM,w
movwf HIGH_BYTE ; oberes Byte
call SEND_ACK_TO_SENSOR
call GET_BYTE
movf ADDR_COMM,w
movwf LOW_BYTE ; unteres Byte
call SEND_ACK_TO_SENSOR
call GET_BYTE
goto geschafft
;***********************Get*Byte****************** *****************
GET_BYTE
clrf ADDR_COMM
movlw d'8'
movwf COUNTER_SEN
GET_BYTE_LOOP
bsf SENSOR_SCK
btfss SENSOR_DATA
goto GET_ZERO_BIT
bsf ADDR_COMM,0
goto GOT_BIT
GET_ZERO_BIT
bcf ADDR_COMM,0
GOT_BIT
bcf SENSOR_SCK
decfsz COUNTER_SEN,f
goto GET_NEXT_BIT
goto DONE
GET_NEXT_BIT
rlf ADDR_COMM,f ; rotate
goto GET_BYTE_LOOP
DONE
return
;***********************Sende*Acknowledge********* *******************
SEND_ACK_TO_SENSOR
bsf STATUS,RP0
bcf SENSOR_DATA
bcf STATUS, RP0
bcf SENSOR_DATA
bsf SENSOR_SCK
bcf SENSOR_SCK
bsf STATUS, RP0
bsf SENSOR_DATA
bcf STATUS, RP0
return
;***********************Kein* Acknowledge****************************
ACK_LOST
movlw b'11110000'
movwf HIGH_BYTE
movlw b'00001111'
movwf LOW_BYTE
geschafft
bsf PORTB,2
;movwf PORTB
;***********************Ende********************** ******************
ABM
goto LCD_AN
;return
;goto ABM
end
Gibt es jemanden, der mit dem Sensor Erfahrung hat und ebenfalls wie ich in Assembler programmiert?
Jemand ne Idee, was ich falsch mache oder wo der Fehler ist. Vielleicht in der Initialisierung….
Danke
Gruß
ich habe ein Problem mit meinem SHT75 Temperatur und Feuchte-Sensor. Und zwar bekomme ich diesen an meinem PIC 16F877A nicht zum laufen.
Hier erstmal mein Code
list p=16f877a ; list directive to define processor
#include <p16f877a.inc> ; processor specific variable definitions
; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
EXTERN LCD_AN
;***********************Variablendefinition******* ********************
D_SENSOR_DATA UDATA 0x040 ;start of general purpose registers
COUNTER_SEN res 1 ; Counter in Init
TEMP_DATA res 1 ; TEMP_DATA
TEMP_ACK RES 1 ; TEMP_ACK
TEMP_TEST res 1 ; TEMP_TEST
ADDR_COMM res 1 ; Address and Command
HIGH_BYTE res 1 ; Oberste 8 bit
LOW_BYTE res 1 ; untere 8 bit
GLOBAL HIGH_BYTE, LOW_BYTE
EXTERN DELAY_30ms
#define SENSOR_DATA PORTA, 1
#define SENSOR_SCK PORTB, 2
#define SENSOR_DATA_DIR TRISA, 1
#define SENSOR_SCK_DIR TRISB, 2
PROG1 Code ; START
;ORG 0x000
goto START_SHT
;
;org 0x0005 ; Interrupt
;retfie
START_SHT
GLOBAL START_SHT
;***********************Init********************** ******************
movlw 0x005
movwf HIGH_BYTE
movwf LOW_BYTE
movwf ADDR_COMM
movlw b'00000101' ; Messe Feuchte
movwf ADDR_COMM
bsf STATUS, RP0 ; Bank1
bcf SENSOR_SCK_DIR ; Output
bcf SENSOR_DATA_DIR ; Output
bcf STATUS, RP0 ; Bank0
;***********************Transmission*Start******** ********************
bsf SENSOR_DATA
bsf SENSOR_SCK
bcf SENSOR_DATA
bcf SENSOR_SCK
bsf SENSOR_SCK
bsf SENSOR_DATA
movlw d'8'
movwf COUNTER_SEN
;***********************Feuchte messen****************************
SEND_BIT_TO_SENSOR
bcf SENSOR_SCK
btfss ADDR_COMM,7
goto SEND_NULL
bsf SENSOR_DATA
goto SEND_BIT
SEND_NULL
bcf SENSOR_DATA
SEND_BIT
bsf SENSOR_SCK
rlf ADDR_COMM,f ; rotate
decfsz COUNTER_SEN,F
goto SEND_BIT_TO_SENSOR
bcf SENSOR_SCK
bsf STATUS, RP0
bsf SENSOR_DATA_DIR ; Input
bcf STATUS, RP0
bsf SENSOR_SCK
btfss SENSOR_DATA ; Acknowledge bekommen?
goto ACK_GET_FROM_SENSOR
goto ACK_LOST
;***********************Get Acknowledge****************************
ACK_GET_FROM_SENSOR ; Ack bekommen
;movlw b'00001111'
;movwf PORTB
bcf SENSOR_SCK
movlw d'30'
movwf COUNTER_SEN
call DELAY_30ms
;***********************Daten empfangen****************************
WAIT_FOR_SENSORDATA
btfss SENSOR_DATA
goto READ_DATA
decfsz COUNTER_SEN,f
goto WAIT_FOR_SENSORDATA
goto ACK_LOST ; wenn keine Daten dann ende
;***********************Lese*Daten**************** *****************
READ_DATA
call GET_BYTE
movf ADDR_COMM,w
movwf HIGH_BYTE ; oberes Byte
call SEND_ACK_TO_SENSOR
call GET_BYTE
movf ADDR_COMM,w
movwf LOW_BYTE ; unteres Byte
call SEND_ACK_TO_SENSOR
call GET_BYTE
goto geschafft
;***********************Get*Byte****************** *****************
GET_BYTE
clrf ADDR_COMM
movlw d'8'
movwf COUNTER_SEN
GET_BYTE_LOOP
bsf SENSOR_SCK
btfss SENSOR_DATA
goto GET_ZERO_BIT
bsf ADDR_COMM,0
goto GOT_BIT
GET_ZERO_BIT
bcf ADDR_COMM,0
GOT_BIT
bcf SENSOR_SCK
decfsz COUNTER_SEN,f
goto GET_NEXT_BIT
goto DONE
GET_NEXT_BIT
rlf ADDR_COMM,f ; rotate
goto GET_BYTE_LOOP
DONE
return
;***********************Sende*Acknowledge********* *******************
SEND_ACK_TO_SENSOR
bsf STATUS,RP0
bcf SENSOR_DATA
bcf STATUS, RP0
bcf SENSOR_DATA
bsf SENSOR_SCK
bcf SENSOR_SCK
bsf STATUS, RP0
bsf SENSOR_DATA
bcf STATUS, RP0
return
;***********************Kein* Acknowledge****************************
ACK_LOST
movlw b'11110000'
movwf HIGH_BYTE
movlw b'00001111'
movwf LOW_BYTE
geschafft
bsf PORTB,2
;movwf PORTB
;***********************Ende********************** ******************
ABM
goto LCD_AN
;return
;goto ABM
end
Gibt es jemanden, der mit dem Sensor Erfahrung hat und ebenfalls wie ich in Assembler programmiert?
Jemand ne Idee, was ich falsch mache oder wo der Fehler ist. Vielleicht in der Initialisierung….
Danke
Gruß