Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DS1306 interface with pic18f452 by using SPI protocol

Status
Not open for further replies.

selvakumar c

Newbie level 4
Joined
Jun 5, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,365
hi all,

i am trying to use DS1306 with PIC18F452,and READ the data from DS1306- display the result into LCD display


from DS1306 datasheet i got clear idea that there are two mode of operation with DS1306

that are

1.SPI mode(4-wire mode)
2.3-wire mode

i used SPI mode(SERMODE to vcc)

vcc2 to Ground
vcc1 to +5v
vccif to +sv
vbat to 3v lithium battery
X1,X2 to 32.768khz crystal
SERMODE to +5v
CE to RC2
SCLK to RC3(SCLK)
SDI to RC5(SDO)
SDO to RC4(SDI)

INT0,INT1,1hz,32khz -no connection


here is my sample code..(for read the data,display second only)



#include<pic18.h>
#include<htc.h>
unsigned char spi(unsigned char);

__CONFIG(1, OSC_HS );
__CONFIG(2, PWRT_ON & BOR_OFF & WDT_OFF);
__CONFIG(4, STVR_ON & LVP_OFF & DEBUG_OFF);

#define _XTAL_FREQ 12000000
#define rs RD0
#define rw RD1
#define en RD2
#define ldata PORTB


void delay()
{
unsigned int i,j;
for(i=0;i<=100;i++)
for(j=0;j<=100;j++);
}

lcd_cmd(unsigned char y)
{
ldata=y;
rs=0;
rw=0;
en=1;
delay();
en=0;
}

lcd_data(unsigned char y)
{
ldata=y;
rs=1;
rw=0;
en=1;
delay();
en=0;
}

lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x0c);
lcd_cmd(0x01);
lcd_cmd(0x80);
}

void adc_calc1(unsigned int k)
{
unsigned int L,M;

L=k%10; k=k/10;
M=k;

lcd_cmd(0x83);
lcd_data(48+M);
lcd_data(48+L);
}
unsigned char spi(unsigned char k)
{
SSPBUF=k;
while(!BF);
adc_calc1(SSPBUF);
}

void main()
{
unsigned int i;
unsigned int dinu[];

SSPSTAT=0x00;
SSPCON1=0x22;

TRISC=0;
TRISC4=1;

ADCON1=0x0f;

TRISB=0x00;
TRISD=0x00;

PORTB=0x00;

lcd_init();
delay();


while(1)
{
RC2=1;
delay();
spi(0x0f); //command for controll resistor to read
spi(0x00); // address for read second
__delay_ms(50);
RC2=0;
}
}


but i can't get proper output.i get output like 00,02,08,I5

I replaced the crystal 32.768hz 3 times but i count't get output correctly


Could someone tell me what kind of communication must I use and how have I to configure the registers SSPCON and SSPSTAT


I thing the problem comes from

1.steps sequence used in reading data
2.display the result into lcd

please any one help me to solve my problems
or
any sample program..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top