I am not familiar with the Hi-Tech compilier, but I use a DS1302Z chip in many projects, and bit bang it using ASM, without problems. Have you checked that your CE line is in fact going high before you clock out your command? I see where you assign CE to 1, but does that actually CHANGE the port bit with Hi-Tech? As far as I can see you have just defined CE as RA5 which in normal C would give you an initial value of 0x20 and do nothing to the port. I would suggest triggering the scope using the rising edge of CE if you don't have a 4 channel scope. Then you'll see each command and if the setup is sufficient (which is generally is when bit banging, as long as you don't enable and clock with the same port instruction). You should be able to do a 'read status' command, and see all zeros except for the 'clock stopped' bit. You do have to CLEAR that bit explicitly to start the oscillator. I don't see where you are doing that so even if you were able to load the time, it wouldn't increment. I would hang a 1k pullup on the data line and see if the DS1302 is even driving the line. If it isn't, (0xFF response) it didn't see the command. Robert Trevyn Watson wrote: > Hello, > > I'm trying to bitbang communication from a 16F877A (running at 4 MHz) to > a DS1302, and I haven't managed to get anything out of the DS1302. I'm > using Microchip MPLAB with Hi-Tech PICC-lite 9.50. I'm using delay > functions by Shane Tolmie from http://microchipc.com/sourcecode/#delay. > My program is included. > > So far, I have: > > Read and applied the "gotchas" page > (http://www.piclist.com/techref/microchip/gotchas.htm) > Checked the connections (at least 10 times). > Replaced the 32.786 kHz crystal with one that is known to have the > correct capacitance (new from Digikey). > Replaced the DS1302. > Read the data sheet multiple times. > Searched the PicList archive (I found very few mentions of the DS1302). > > I have put a scope on the clock and data lines, and as far as I can > tell, the proper command byte is being sent. You can see it at > http://trevyn.ca/sclkio.jpg > > The command byte is being transmitted in the way that I intend (but that > may not be the way the DS1302 expects it). There are 8 falling edges > after the last bit of the command byte. > > My only ideas are: > 1. The command byte I am sending is malformed/incorrect. I can't figure > out how to translate a data address (range 81h-FFh) into a 5 bit number > that goes in the middle of the command byte. > > 2. I'm connecting the DS1302 wrong. I still haven't had any confirmation > that the chip actually works. I've seen nothing out of it. > > 3. I am assuming that the counter starts when power is applied, and that > reading it every half second will give some sort of output after one > second. If this is not the case, then what I am seeing is perfectly normal. > > Basically, my questions are: > 1. Should I use a different chip? (I need one that is available in 8-SOIC) > 2. Is there a better way to talk to the DS1302? > 3. If not, what am I doing wrong? > > Thanks for reading. > I appreciate any help or ideas you have. > Trevyn Watson -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist