Hi,
Ich hab ein Problem mit dem Scratchpad, es zeigt nur NULLER
-verwende nur 1nen 1Wire Sensor,
(keinen Touch)
-und hab jeweils einen seperaten Tx und Rx Pin
Kann mal jemand der sich aus kennt einen Blick (oder Zwei)
auf s Programm werfen?
VIELEN DANK!!!!Code:#include <16f870.h> #use delay(clock=4000000) #fuses XT,NOWDT,NOLVP //DS1820 Commandos #define SKIP_ROM 0xCC /* 204*/ #define CONVERT_T 0x44 /*68*/ #define READ_SCRATCHPAD 0xBE /*190*/ #define Rx_DS18S20 PIN_C4 // Rx TempSensor #define Tx_DS18S20 PIN_C5 // Tx TempSensor char D_Presence; char D_ShortCircuit; enum BITSTELLE { Bit0=1,BIT1=2,BIT2=4,BIT3=8,BIT4=16,BIT5=32,BIT6=64,BIT7=128 }; #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) int temp_1,temp_2; long int null,eins; int scratchpad[8]; void D_Reset(void) { set_tris_c(0x99); output_low(Tx_DS18S20); // Pin des DS18S20 auf low setzen delay_us(480); output_high(Tx_DS18S20); // Pin des DS18S20 auf high setzen delay_us(40); D_Presence = input(Rx_DS18S20); delay_us(350); D_ShortCircuit = input(Rx_DS18S20); delay_us(60); } void temp_init() { output_low(Tx_DS18S20); // Pin des DS18S20 auf low setzen delay_us(480); // 480us warten while (input(Rx_DS18S20)); // pruefen ob der 1-wire bus auf low gezogen wird, delay_ms(5); } void temp_send(unsigned char code) { int n=0; for(; n < 8; n++) { if(bit_test(code,n)) { output_low(Tx_DS18S20); //sende 0 delay_us(2); //int write slot output_high(Tx_DS18S20); //send 1 } else { output_low(Tx_DS18S20); //sende 0 } delay_us(65); //duration für 1 und fertig output_high(Tx_DS18S20); delay_us(2); } delay_us(100); //1 Millisekunde } unsigned char temp_read(void) { unsigned char in=0,j=0; delay_us(400); for(; j < 8; j++) { delay_us(1); output_low(Tx_DS18S20); // init read delay_us(3); if (input(Rx_DS18S20)) bit_set(in,j); delay_us(60); } return(in); } void main() { int i; printf("Hallo\r\n"); D_Reset(); printf("Presence:%d ShortCircuit:%d\r\n",D_Presence,D_ShortCircuit); while(1) { temp_init(); temp_send(SKIP_ROM); temp_send(CONVERT_T); delay_ms(500); //warten bis Temp Convert abgeschlossen ist... temp_send(SKIP_ROM); temp_send(READ_SCRATCHPAD); for (i=0; i<8;i++) { scratchpad[i] = temp_read(); printf("i:%d/v:%d %d %d",i,scratchpad[i],D_Presence,D_ShortCircuit); } printf("Temperatur: %d, %02u C\r\n",temp_2,temp_1); delay_ms(500); } }







Zitieren

Lesezeichen