Hello.

I'm fighting with bloody DS1302 and PICBASIC PRO, but have no luck.

I have DS1302 assembled on separate PCB with backup battery, and using Chris Savage's code on Basic Stamp, it runs just fine, time is OK, everything is OK. But, when I decided to use it with picbasic pro, it does not works.

I have PIC16F870 and the simple code is below, I've shorted it quite much, because DS1302 is already preset and no need for time programming:

Code:
include "MODEDEFS.BAS"
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4 
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44 
define OSC 4


 ' ** Declare the Variables ** 


 B0 VAR BYTE
 B1 VAR BYTE
 B2 VAR BYTE


 RST var PORTC.3
 dq var PORTC.2
 clk var PORTC.1

'------------------------- Read Commands For DS1302 -------------------------

readsec con $81 ' Read seconds from DS1302
readmin con $83 ' Read minutes from DS1302
readhour con $85 ' Read hours from DS1302
readdate con $87 ' Read date from DS1302
readyear con $8D ' Read year from DS1302
readmonth con $89 ' Read month from DS1302

'------------------------------ Time Variables ------------------------------

mem var byte ' Temporary data holder
outbyte var byte ' Second byte to ds1302
reg_adr var byte ' First byte to DS1302
date var byte ' Date variable
ss var byte ' Seconds variable
mm var byte ' Minutes varibale
hh var byte ' Hours variable
mo var byte ' Month variable
yr var byte ' Year variable

'------------------------ Initial Settings For Ports ------------------------

low rst ' Set reset pin low
low clk ' Set clock pin low

trisb = 0
trisa = 0

'----------------------- Set Initial Time Variables -------------------------


start:
reg_adr = readsec ' Read seconds
gosub w_in
ss = mem
reg_adr = readmin ' Read minutes
gosub w_in
mm = mem
reg_adr = readhour ' Read Hours
gosub w_in
hh = mem
reg_adr = readyear ' Read Year
gosub w_in
yr = mem
reg_adr = readdate ' Read Date
gosub w_in
date = mem
reg_adr = readmonth ' Read Month
gosub w_in
mo = mem
lcdout $fe,1,"TIME:",HEX2 hh,":",HEX2 mm,":",HEX2 ss
pause 500
goto start

'----------------------- Time Commands Subroutines --------------------------

w_in:
mem = reg_adr ' Set mem variable to reg_adr contents
high rst ' Activate the DS1302
shiftout dq,clk,0, [mem] ' Send control byte
shiftin dq,clk,1, [mem] ' Retrieve data in from the DS1302
low rst ' Deactivate DS1302
return

w_out:
mem = reg_adr ' Set mem variable to reg_adr contents
high rst ' Activate the DS1302
shiftout dq,clk,0, [mem] ' Send control byte
mem = outbyte ' Set mem variable to outbyte contents
shiftout dq,clk,0, [mem] ' Send data stored in mem variable to DS1302
low rst ' Deactivate DS1302
return
The screen always shows 00:00:00, but if I unconnect the data pin, it displays FF FF FF

What I'm doing wrong?

I've checked all treads regarding DS1302, should be OK with this code...