PDA

View Full Version : DS1302 and 18F452



Astro
- 4th October 2005, 15:08
I need simple code for DS1302 and 18F452.

Astro
- 9th May 2006, 15:25
What it is made a mistake ?


'TESTE
DEFINE LCD_BITS 8
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 3
DEFINE LCD_RWREG PORTD
DEFINE LCD_RWBIT 2

DEFINE LCD_COMMANDUS 10000
DEFINE LCD_DATAUS 100
DEFINE LCD_INITMS 1000

symbol SCL = PORTC.3 ' I2C clock
symbol SDA = PORTC.5 ' I2C data

define osc 40

'INCLUDE "modedefs.bas"
'include "18f452.inc"

DEFINE CHAR_PACING 1000
DEFINE BUTTON_PAUSE 50

DEFINE I2C_SLOW 1

'TRISB = %11111111

S var word 'Segundos
M var word 'Minutos
H var word 'Horas
DD var word 'Dia
MM var word 'Mês
AA var word 'Ano
DIA var word 'Dia da semana

pause 200
lcdout $fe,1 'limpa o display
Pause 500
lcdout "Aprender"

Pause 500
lcdout $fe,1 'limpa o display
'I2CWRITE SDA,SCL,$84,2,"15"

loop:

I2CREAD SDA,SCL,$85,2,[H]
I2CREAD SDA,SCL,$83,2,[M]
LCDOUT $FE,1,dec2(H), ":", DEC2(M)

PAUSE 100

goto loop

BobK
- 9th May 2006, 22:02
Hi Astro,

I did a search of this forum using "DS1302" in the search field and found that on March 10, 2006, Travin77 posted code for using the DS1302. You should be able to use the same code just setup the correct config fuses for the 18F452. I recently used code for the DS1337 that was posted back in 2004 I think and used the same program on both a 16F877A and a 18F452. Same program just different configuration setups. They work great on both PICs. The one thing that I didn't do was pay real close attention to the fine print on the data sheets regarding the type of crystal to use. It turns out I had one with too much capacitance and it is making the clock time faster. Changing to the correct crystal and now everything is okay.

Try it out!

BobK