@Art
I decided to give Cocacolakid's code a whirl,sadly time stand still :-( display is stuck at 00:00:80
I think it's because of the if statement here:
Code:
if portb.4 = 1 then START ' Set initial clock start up if jumper is present
So after removing it since I have no jumper there and re-programming the PIC.
The display shows:
00:30:00 and time stands still :-(
Here's the code I am using :
Code:
'
'using pic18f4520
'
'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines
'Port IO directions and presets for port pins begin here
'TRISX = %76543210 << tris bit order numbering
'TRISA = %11111111 'All pins are outputs
'Define port pins as inputs and outputs ...
'example only - TRISB = %00001111 ;Make 'B4-B7 outputs, B0-B3 inputs
TRISA = %00000000 'assigned to LCD
TRISB = %11111111 'for 4x4 keypad all input
TRISC = %10000000
TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
'End of Port IO directions and presets for port pins begin here
'LCD defines begin here
DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to
DEFINE LCD_EREG PORTD 'defines the port where E line is connected to
DEFINE LCD_EBIT 3 'defines the pin where E line is connected
'DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used)
'DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used)
DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 200 'delay in micro seconds
'END of LCD DEFINES
'includes begin here
INCLUDE "modedefs.bas"
include "c:\pbp\samples\keypad.bas"
'end of includes
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 207 ' 2400 Baud @ 32MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'-------------------------- Clock Variables ---------------------------------
clk var portC.3 ' DS1302 Clock Pin
dq var portC.4 ' DS1302 Data Pin
rst var portD.1 ' DS1302 Reset Pin
'----------------------- Write Commands For DS1302 --------------------------
writectrl con $8E ' Control byte
writeram con $80 ' Write to RAM
writeprotect con $00 ' Write-protect DS1302
writesec con $80 ' Write seconds
writemin con $82 ' Write minutes
writehour con $84 ' Write hour
writedate con $86 ' Write date
writemonth con $88 ' Write month
writeyear con $8C ' Write year
'------------------------- 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
'----------------------- Set Initial Time Variables -------------------------
'if portb.4 = 1 then START ' Set inital clock start up if jumper is present
reg_adr = writectrl ' Set to control byte
outbyte = writeprotect ' Set turn off protection
gosub w_out ' Send both bytes
reg_adr = writesec ' Set to write seconds register
outbyte = $00 ' Set to write 00 to seconds register
gosub w_out
reg_adr = writemin
outbyte = $30
gosub w_out
reg_adr = writehour
outbyte = $00
gosub w_out
reg_adr = writedate
outbyte = $01
gosub w_out
reg_adr = writemonth
outbyte = $01
gosub w_out
reg_adr = writeyear
outbyte = $00
gosub w_out
reg_adr = writectrl
outbyte = writeprotect
gosub w_out
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
I have attached my circuit diagram too ...perhaps that's where the mess-up is ?
Will try asm code as well and feedback
Also going to source a DS1307 and DS1337C tomorrow and later this week, will post an update asap.
Kind regards
Dennis
Bookmarks