-
        

Ergebnis 1 bis 2 von 2

Thema: 1Wire DS1820 no eins

  1. #1
    gothe
    Gast

    1Wire DS1820 no eins

    Anzeige

    folgendes....
    Code:

    //////////////////////////////////////////////////////////////////////////////
    // OW_RESET - performs a reset on the one-wire bus and
    // returns the presence detect. Reset is 480us, so delay

    unsigned char ow_reset(void)
    {
    unsigned char presence;
    DQ = 0; //pull DQ line low
    delay(29); // leave it low for 480us
    DQ = 1; // allow line to return high
    delay(3); // wait for presence
    presence = DQ; // get presence signal
    delay(25); // wait for end of timeslot
    return(presence); // presence signal returned
    } // 0=presence, 1 = no part


    DQ=0 und DQ=1 DAS IST MEIN PROBLEM, denk ich!!

    ich hab s nämlich mit :

    Code:

    unsigned char ow_reset(void)
    {
    unsigned char presence;
    output_low(DQ); //pull DQ line low
    delay_us(480); // leave it low for 480us
    output_high(DQ); // allow line to return high
    delay_us(70); // wait for presence
    presence = DQ; // get presence signal
    delay_us(410); // wait for end of timeslot
    return(presence); // presence signal returned
    } // 0=presence, 1 = no part



    gemacht..

    jetzt Frage: DQ=0 bzw. 1 nimmt er nicht an!
    muss ich jeweils selber den TRIS des PIns verändern?
    und könnt mir jemand sagen wo ich überall die TRIS verändern muss
    und wo die outputs passen, oder sollte ich inputs verwenden ..................?




    Code:


    #include <16f870.h>
    #use delay(clock=4000000)
    #fuses XT,NOWDT,NOLVP

    #define SKIP_ROM 0xCC
    #define CONVERT_T 0x44
    #define READ_SCRATCHPAD 0xBE

    #define DQ PIN_C4
    //#define Tx_DS1820 PIN_C5

    #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)


    //////////////////////////////////////////////////////////////////////////////
    // OW_RESET - performs a reset on the one-wire bus and
    // returns the presence detect. Reset is 480us, so delay
    // value is (480-24)/16 = 28.5 - we use 29. Presence checked
    // another 70us later, so delay is (70-24)/16 = 2.875 - we use 3.
    //
    unsigned char ow_reset(void)
    {
    unsigned char presence;
    output_low(DQ); //pull DQ line low
    delay_us(480); // leave it low for 480us
    output_high(DQ); // allow line to return high
    delay_us(70); // wait for presence
    presence = DQ; // get presence signal
    delay_us(410); // wait for end of timeslot
    return(presence); // presence signal returned
    } // 0=presence, 1 = no part




    //////////////////////////////////////////////////////////////////////////////
    // READ_BIT - reads a bit from the one-wire bus. The delay
    // required for a read is 15us, so the DELAY routine won't work.
    // We put our own delay function in this routine in the form of a
    // for() loop.
    //
    unsigned char read_bit(void)
    {
    unsigned char i;
    output_low(DQ); // pull DQ low to start timeslot
    output_high(DQ); // then return high
    for (i=0; i<3; i++); // delay 15us from start of timeslot
    return(DQ); // return value of DQ line
    }




    //////////////////////////////////////////////////////////////////////////////
    // WRITE_BIT - writes a bit to the one-wire bus, passed in bitval.
    //
    void write_bit(char bitval)
    {
    output_low(DQ); // pull DQ low to start timeslot
    if(bitval==1) output_high(DQ); // return DQ high if write 1
    delay_us(104); // hold value for remainder of timeslot
    output_high(DQ);
    }// Delay provides 16us per loop, plus 24us. Therefore delay(5) = 104us


    //////////////////////////////////////////////////////////////////////////////
    // READ_BYTE - reads a byte from the one-wire bus.
    //
    unsigned char read_byte(void)
    {
    unsigned char i;
    unsigned char value = 0;
    for (i=0;i<8;i++)
    {
    if(read_bit()) value|=0x01<<i; // reads byte in, one byte at a time and then
    // shifts it left
    delay_us(120); // wait for rest of timeslot
    }
    return(value);
    }



    //////////////////////////////////////////////////////////////////////////////
    // WRITE_BYTE - writes a byte to the one-wire bus.
    //
    void write_byte(char val)
    {
    unsigned char i;
    unsigned char temp;
    for (i=0; i<8; i++) // writes byte, one bit at a time
    {
    temp = val>>i; // shifts val right 'i' spaces
    temp &= 0x01; // copy that bit to temp
    write_bit(temp); // write bit in temp into
    }
    delay_us(104);
    }

    void main()
    {
    char get[10];
    int k;
    char temp_f,temp_c;

    while(1)
    {

    ow_reset();
    write_byte(0xCC); //Skip ROM
    write_byte(0x44); // Start Conversion
    delay_us(104);
    ow_reset();
    write_byte(0xCC); // Skip ROM
    write_byte(0xBE); // Read Scratch Pad
    for (k=0;k<9;k++)
    { get[k]=read_byte();
    }

    printf("\n ScratchPAD DATA = %X%X%X%X%X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);


    }
    }



    thx

  2. #2
    Neuer Benutzer Öfters hier
    Registriert seit
    18.04.2005
    Beiträge
    7
    Hallo,

    also wenn ihr schon ein wenig Code hier rein postet dan tut es doch ein wenig strukturierter nicht jeder hat lust sich in so was mal einzulesen!!!!!

    Gruß

Benutzer, die dieses Thema gelesen haben: 0

Derzeit gibt es keine Benutzer zum Anzeigen.

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •