Please note that I am not a C expert, I am a self-taught C hacker. This means some of teh things I do may not be the most elegant or efficient, and some may not even work... 8-) but I do use CCS and I'll try to help. On Fri, 15 Mar 2002, Fran=E7ois ELISE wrote: > void write_ds1615_byte(DS1615OP cmd, byte adr,byte dut) Shouldn't that be : void write_ds1615_byte(byte cmd, byte adr, byte aut) unless you have DS1615OP defined as a type somewhere?? > { > byte i; > byte test[3]; //Array for bytes to transmit > test[0]=3Dcmd; //Define the 3 contents > test[1]=3Dadr; > test[2]=3Ddut; > output_high(RTC_RST); //Enable Write operation > for(i=3D1;i<=3D3;++i) Aren't you missing a { here?? Otherwise you just shift the... well, I'm not sure *WHAT* it will shift in this case, the shift_right function is one I have not used. But it will do it all in one shot, not loop through like I think you intended... > shift_right(cmd,3,0);//Put at first the byte cmd then adr and dut > for(i=3D0;i<8;++i) > { > output_low(RTC_SCLK);// write to DS1615 the 3 bytes bit by bit > delay_us(2); // the bit 0 at first on each rise clk(0to1) > output_bit(RTC_IO, shift_right(test,3,0)); > output_high(RTC_SCLK); > delay_us(2); // send a bit each 2 micro-second > > } > output_low(RTC_RST); //Stop at the end of operation > } > ***WARNING: UNTESTED CODE AHEAD*** char i,x; byte test[3]; //Array for bytes to transmit test[0]=3Dcmd; //Define the 3 contents test[1]=3Dadr; test[2]=3Ddut; output_high(RTC_RST); //Enable Write operation for(i=3D0;i<3;i++) { for(y=3D0;y<8;y++) { output_low(RTC_SCLK); delay_us(2); output_bit(RTC_IO,shift_right(&test[x],1,0)); // OR: output_bit(RTC_IO,bit_test(test[x],y)); output_high(RTC_SCLK); delay_us(2); } } } I'm not sure you need those 2uS delays in there, have not looked at the DS1615 data sheet. I have done similar with the DS1620 (same 3-wire itnerface), but haven't tested it with hardware yet. > reados_ds1615_byte(DS1615OP cmd, byte adr) Same observations for this function... > { > byte i; //Send the reader command to DS1615 > byte test[2]; //and the adress wanted > test[0]=3Dcmd; //Array for byte to transmit > test[1]=3Dadr; //Define the 2 contents > > for(i=3D1;i<=3D2;++i) > shift_right(cmd,2,0); //Put at first the byte cmd then adr I think you intended this to be an outer loop, but it's missing the curly braces if so. > for(i=3D0;i<8;++i) > { > output_low(RTC_SCLK);//the bit 0 at first on each rise clk(0to1) > delay_us(2); //every 2 micro second > output_bit(RTC_IO, shift_right(test,2,0)); > output_high(RTC_SCLK); > delay_us(2); > } > } > > byte read_ds1615() > { > byte i,data; > output_high(RTC_RST); > reados_ds1615_byte(0x33,0x5e);// 0x33=3Dcmd read at adresse=3D5e > data[1]; // define array You define a 1-byte array? > for (i=3D0;i<8;++i) // read the data bit by bit > // during rise clk > { > output_low(RTC_SCLK); // each 2 micro-secondes > delay_us(2); > shift_right(data,1,input(RTC_IO)); > output_high(RTC_SCLK); > delay_us(2); > > } > output_low(RTC_RST); > return (data); //Return the value of this funct. > data =3D val; > return val; > } > > void tost() //Define the function > { > if(!input(PIN_B0)) //If push button is pressed > { > /* buffer[0] =3D read_ds1615(); TEST N=B01 !!! result Strange > printf("%x",buffer[0]);*/ > //printf("%u\r\n",val); // TEST N=B02 !!!result Strange > value =3D read_ds1615(); // Read the value at adress 5e > output_low(LED); //Light the led on > printf("%u\r\n",value); // put the value from adress 5e to PC > } > else > { > write_ds1615_byte(0x22,0x5e,0x25);//22 =3D cmd write value 25 at adre= ss 5e > output_high(LED); //Light off the led > } > } > > main() > > { > > while (TRUE) > { > tost(); // Call this function > } > setup_adc_ports(NO_ANALOGS); > setup_adc(ADC_CLOCK_DIV_2); > setup_spi(FALSE); > setup_psp(PSP_DISABLED); > setup_counters(RTCC_INTERNAL,RTCC_DIV_2); > setup_ccp1(CCP_OFF); > setup_ccp2(CCP_OFF); > } > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.