Wond3rboy
Member
Hi i made a simple code to read and write in the RTC DS12885's memory and it worked.Now the problem is that when i try to write in its registers then nothing happens.I mean to check out the RTC i tried to program its Square Wave feature for a wave of 2Hz and nothing happenedIs there any difference between writing to the built in RAM of the RTC and its configuration registers?
The code for the read write cycle is:
The code for the read write cycle is:
Code:
#include<p18f1320.h>
#pragma config OSC=INTIO2,WDT=OFF,LVP=OFF,DEBUG=ON
#include<delays.h>
#define ADwritebus LATB
#define AS LATAbits.LATA4
#define DS LATAbits.LATA6
#define RW_bar LATAbits.LATA7
#define ADreadbus PORTB
void write_RTC(unsigned char, unsigned char );
void read_RTC(unsigned char ,unsigned char*);
void main(void)
{ unsigned ram char * d;
OSCCON=0x60;
ADCON1=0x7f;
TRISA=0;
TRISAbits.TRISA4=0;
TRISAbits.TRISA6=0;
TRISAbits.TRISA7=0;
Delay1KTCYx(200);
write_RTC(0x34,0x01);
_asm NOP _endasm
*d=0x00;
read_RTC(0x34,d);
while(1);
}
void write_RTC(unsigned char RTCwaddress, unsigned char RTCwdata)
{
TRISB=0;
DS=1;
RW_bar=1;
AS=1;
ADwritebus=RTCwaddress;
_asm nop _endasm
AS=0; //Latch address
_asm nop _endasm
ADwritebus=0; //Make address/data line zero
RW_bar=0;
_asm nop _endasm
ADwritebus=RTCwdata; //write data on specific address
_asm nop _endasm
RW_bar=1; //Enable writing the data.
_asm NOP _endasm
ADwritebus=0;
AS=1;
}
void read_RTC(unsigned char RTCraddress,unsigned char *pd)
{
DS=1;
RW_bar=1;
AS=1;
ADwritebus=RTCraddress;
_asm nop _endasm
AS=0;
TRISB=0xff;
_asm nop _endasm
DS=0;
_asm nop _endasm
*pd=ADreadbus;
DS=1;
_asm NOP _endasm
AS=1;
LATA=*pd;
}
Last edited: