PDA

View Full Version : 16f877A and shiftin shiftout



ghdsfier8
- 22nd February 2008, 05:11
I have a program that uses shiftin and shiftout to read and set the time on a ds1302. It works on the 16f876A, but when I move it to the 877A, it no longer reliably reads the ds1302.

I also have some lcdout commands that also get flaky in the transition.

any suggestions?

thanks

bob

skimask
- 22nd February 2008, 06:11
I have a program that uses shiftin and shiftout to read and set the time on a ds1302. It works on the 16f876A, but when I move it to the 877A, it no longer reliably reads the ds1302.
I also have some lcdout commands that also get flaky in the transition.
any suggestions?
thanks
bob

Change the kitty litter in the fuel tank?
How 'bout some code...

ghdsfier8
- 22nd February 2008, 07:33
skimask,

thanks for the suggestion but i just changed the kitty litter last month. here's the code

DEFINE LOADER_USED 1
ADCON1 = 15
CMCON=7
'DEFINE OSC 20

'-------------------Pin assignments
' for Hardware interface with ds1302 and dealing with time
clk_pin_ds1302 var portb.1
data_pin_ds1302 var portb.2
rtccs_pin_ds1302 var portb.4
seconds_subscript CON 2
minutes_subscript CON 1
hours_subscript CON 0
low rtccs_pin_ds1302
low clk_pin_ds1302
trisb=0
trisa=0
'Define RTC Command Constants
regsec CON %00000
regmin CON %00001
reghrs CON %00010
regctrl CON %00111
seconds_sent var byte
minutes_sent var byte
hours_sent var byte
time VAR Byte(3)
byteone VAR Byte
bytetwo VAR Byte
nibblefive VAR byte
CR con 13
lsbpre con 1
lsbfirst con 0
' ====================== MAIN PROGRAM LOOP ==========================

main:
GOSUB readthetime
hserout [" time: ",DEC2 time(0),":",DEC2 time(1), ":", DEC2 time(2),cr]
PAUSE 100
GOTO main

' --------------------------------START SUBROUTINES------------------------------------------------------
Readhr:
HIGH rtccs_pin_ds1302
SHIFTOUT data_pin_ds1302, clk_pin_ds1302, LSBFIRST, [%1\1,reghrs\5,%10\2]
SHIFTIN data_pin_ds1302, clk_pin_ds1302, LSBPRE, [time(hours_subscript)]
LOW rtccs_pin_ds1302
time(hours_subscript) = 10*((time(hours_subscript)<<11) >> 15) + ((time(hours_subscript)<<12)>>12)
RETURN

Readmin:
HIGH rtccs_pin_ds1302
SHIFTOUT data_pin_ds1302, clk_pin_ds1302, LSBFIRST, [%1\1,regmin\5,%10\2]
SHIFTIN data_pin_ds1302, clk_pin_ds1302, LSBPRE, [time(minutes_subscript)]
min00:
LOW rtccs_pin_ds1302
byteone = 10*((time(minutes_subscript)<<8) >> 12)
bytetwo = ((time(minutes_subscript)<<12)>>12)
time(minutes_subscript) = byteone + bytetwo
RETURN

Readsec:
HIGH rtccs_pin_ds1302
SHIFTOUT data_pin_ds1302, clk_pin_ds1302, LSBFIRST, [%1\1,regsec\5,%10\2]
SHIFTIN data_pin_ds1302, clk_pin_ds1302, LSBPRE, [time(seconds_subscript)]
LOW rtccs_pin_ds1302
time(seconds_subscript) = 10*((time(seconds_subscript)<<9) >> 13) + ((time(seconds_subscript)<<12)>>12)
RETURN
readthetime:
GOSUB readmin
GOSUB readhr
GOSUB readsec
RETURN

skimask
- 22nd February 2008, 13:47
I got nothing except maybe a hardware problem... Are you using a solderless breadboard? Try a different place on the board, or better yet, cann it and get a new one.