PDA

View Full Version : Mcp79410 rtcc



keymuu
- 22nd January 2011, 11:01
Hi!

I'm new to that RTC.

Are there any pitfalls with it?
Does I2CREAD and I2CWRITE work as one would expect?
Any othere problems?

About the printed board, any concern about it. If you can squeeze all components needed by it clearly within one square inch and ground is practically all around it, it should work. Doesn't it?

PS Does anybody now when PBP 2.60B will come out, it should not take so long any more, or... :rolleyes:

PedRodrigues
- 20th June 2011, 15:32
Hello keymuu.

I'm building a clock based on mcp79410 and would like to ask you if you had problems with I2CREAD and I2Cwrite?

I'm trying with these functions but without success!

regards

mister_e
- 20th June 2011, 23:48
Please, allow us to help you better by providing all the details: PIC, schematic, a snip of your actual code, configuration fuses etc etc etc.

PedRodrigues
- 21st June 2011, 11:55
Hi Steve.

my pic is 18f26j11, but the internal rtcc is not a solution because i need prevent power fail, so i'm choosing the mcp79410 because it have the backup battery.

the schematic is in datasheet of microchip pag 1 in http://ww1.microchip.com/downloads/en/AppNotes/01355A.pdf
SCL and SDA from I2C are connected to pins 14 and 15 from my micro.

After several attempts, finally managed to get the clock working, through the instructions and I2Cwrite I2CREAD. Initially I was not able to because I forgot to set the correct port.
my code:


Define LCD_DREG PORTB ' Port for LCD Data
Define LCD_DBIT 0 ' Use lower 4 bits of Port
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 1 ' Port Pin for RS bit
Define LCD_EREG PORTA ' Port for Enable (E) bit
Define LCD_EBIT 2 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 2000 'Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)
LCDOUT $FE,1 ' start LCD

DEFINE OSC 4
OSCCON = %01100000 ' UTILIZAR OSCILADOR INTERNO DE 4MHz
T1CON = %10001001 ' CRISTAL EXTERNO, 1:1 PRESCALE, NO SYNCH, 8-BIT, TIMER1 ON
INTCON2.7 = 1 ' DISABLE PULL UP'S NAS PORTB'S
CM1CON = 0 ' DISABLE COMPARADORES
CM2CON = 0
ANCON0 = %11111111 ' SELECT ANALOG AND DIGITAL PINS IN PORTA
ANCON1 = %10011111
ADCON1 = %10000000

TRISA = %00000000
TRISB = %00000000
TRISC = %00111000

SCLpin var PORTC.3
SDApin var PORTC.4
MFOpin var PORTC.5

RTCSec var byte
RTCMin var byte
RTCHour var byte
RTCWDay var byte
RTCDay var byte
RTCMonth var byte
RTCYear var byte
RTCCtrl var byte
MEMSec VAR BYTE
MEMMin VAR BYTE
MEMHour VAR BYTE
MEMWDay VAR BYTE
MEMDay VAR BYTE
MEMMonth VAR BYTE
MEMYear VAR BYTE
MEMCtrl VAR BYTE

seculo var byte
anos var byte
mes var byte
dias var byte
hora var byte
minu var byte
segu var byte

'habilitar o i2c
SSPSTAT = %00000000
SSPCON1 = %00101000 'MASTER MODE SSPM E ENABLE SSPEN
SSPCON2 = %00011111 'SEN,RSEN,PEN,RCEN,ACKEN

'_________________________________________________ ______________________________
'MCP7941 CONFIGURACTION REGISTERS RTCC
'_________________________________________________ _____________________________

RTCSEC = %10000000 'BIT 0-3 SECONDS; BIT4-6 10SECONDS; BIT 7 OSCILLATOR START '00-59
RTCMIN = %00100011 'BIT 0-3 MINUTES; BIT4-6 10MINUTES; BIT 7 NOT USED '00-59
RTCHOUR = %00010001 'BIT 0-3 HOUR; BIT 4 10HOURS; BIT 5 10HOUR AM/PM; BIT 6 12/24; BIT 7 NOT USED '1-12AM/PM OU 00-23
RTCWDAY = %00001010 'BIT 0-2 WEEKDAY; BIT 3 VBATEN; BIT 4 VBAT; BIT 5 OSCON; BIT 6-7 NOT USED '1-7
RTCDAY = %00100001 'BIT 0-3 DAY; BIT 4-5 10DAY; BIT 6-7 NOT USED '0-31
RTCMONTH = %00000110 'BIT 0-3 MONTH; BIT 4 10MONTH; BIT 5 LEAP YEAR; BIT 6-7 NOT USED '01-12
RTCYEAR = %00010001 'BIT 0-3 YEAR; BIT 4-7 10YEAR '00-99
RTCCtrl = %01000011


'seculo = 20

gosub clock_start
PAUSE 100

'-------------------------------------------------------------------------------
start:


I2CREAD SDApin,SCLpin,%11011111,$00,[MEMSec,MEMMin,MEMHour,MEMWDay,MEMDay,MEMMonth,MEMY ear,memctrl]
PAUSE 100
gosub diasemana
gosub meses

LCDOut $FE,$80,#(MEMHOUR>>4) & %00000011,#MEMHOUR & $0F,":"
LCDOut $FE,$83,#(MEMMin>>4) & %00000111,#MEMMin & $0F,":"
LCDOut $FE,$86,#(MEMSEC>>4) & %00000111,#MEMSEC & $0F
'LCDOut $FE,$C0,# MEMWDAY & %00000111
LCDOut $FE,$C3,", ",#(MEMDAY>>4) & %00000011,#MEMDAY & $0F
'LCDOut $FE,$C7,#(MEMMONTH>>4) & %00000001,#MEMMONTH & $0F
LCDOut $FE,$CC,#seculo,#(MEMYEAR>>4) & %00001111,#MEMYEAR & $0F



goto start
'-------------------------------------------------------------------------------
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
' FUNCOES FUNCOES FUNCOES
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
'-------------------------------------------------------------------------------

clock_start:
pause 100
I2CWrite SDApin,SCLpin,%11011110,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,rtcctrl]

return

diasemana:

select case MEMWDAY & %00000111
case 1
lcdout $FE,$C0,"Mon"
case 2
lcdout $FE,$C0,"Tue"
case 3
lcdout $FE,$C0,"Wed"
case 4
lcdout $FE,$C0,"Thu"
case 5
lcdout $FE,$C0,"Fri"
case 6
lcdout $FE,$C0,"Sat"
case 7
lcdout $FE,$C0,"Sun"
end select
return

meses:
select case ((MEMMONTH>>4) & %00000001)*10 + MEMMONTH & $0F
case 1
lcdout $FE,$C8,"Jan"
case 2
lcdout $FE,$C8,"Feb"
case 3
lcdout $FE,$C8,"Mar"
case 4
lcdout $FE,$C8,"Apr"
case 5
lcdout $FE,$C8,"May"
case 6
lcdout $FE,$C8,"Jun"
case 7
lcdout $FE,$C8,"Jul"
case 8
lcdout $FE,$C8,"Aug"
case 9
lcdout $FE,$C8,"Sep"
case 10
lcdout $FE,$C8,"Oct"
case 11
lcdout $FE,$C8,"Nov"
case 12
lcdout $FE,$C8,"Dec"
end select
return

calculo:
hora = ((MEMHOUR>>4) & %00000011) *10 + MEMHOUR & $0F
minu = ((MEMMin>>4) & %00000111) *10 + MEMMin & $0F
segu = ((MEMSEC>>4) & %00000111) *10 + MEMSEC & $0F
dias = ((MEMDAY>>4) & %00000011) *10 + MEMDAY & $0F
mes = ((MEMMONTH>>4) & %00000001) *10 + MEMMONTH & $0F
anos = ((MEMYEAR>>4) & %00001111) *10 + MEMYEAR & $0F
lcdout $FE,$d0,#segu
return


end




Any tip to improve the code? thanks

regards

LGabrielson
- 17th July 2012, 04:36
Lines 57-59 error. Did you end up remarking them out?

SSPSTAT = %00000000
SSPCON1 = %00101000 'MASTER MODE SSPM E ENABLE SSPEN
SSPCON2 = %00011111 'SEN,RSEN,PEN,RCEN,ACKEN

I'm glad you got this RTC to work. I'm going to use it in an upcoming project.

Len