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.

DS1307 +lcd using PIC

Status
Not open for further replies.

zakir_cool

Junior Member level 3
Joined
Sep 27, 2012
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,558
hi...i am trying a c code for rtc using pic...almost i have done,i have done all function in i2c....can any one tell that,after sending a data or address, we have to call ack funtion or else..it will call automatically..after sending..below is my code..can any body suggest me....


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
unsigned char read_ds1307(unsigned char address)
{
unsigned char data;
I2CStart();
I2CSend(0xd0);
delay_ms(10);
I2CSend(address);
delay_ms(4);
I2CRestart();
delay_ms(10);
I2CSend(0xd1);
delay_ms(4);
data=I2CRead();
delay_ms(10);
I2CStop();
delay_ms(10);
return(data);
}
 
void write_ds1307(unsigned char address,unsigned char w_data)
{
I2CStart(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2CSend(0xD0); // send byte via I2C (device address + W)
delay_ms(10);
I2CSend(address); // send byte (address of DS1307 location)
delay_ms(10);
I2CSend(w_data); // send data (data to be written)
delay_ms(10);
I2CStop(); // issue I2C stop signal
delay_ms(10);
}
 
void I2CInit()
{
TRISC3 = 1; /* SDA and SCL as input pin */
TRISC4 = 1; /* these pins can be configured either i/p or o/p */
SSPSTAT = 0x80; /* Slew rate disabled */
SSPCON = 0x28; /* SSPEN = 1, I2C Master mode, clock = FOSC/(4 * (SSPADD + 1)) */
SSPADD = 0x28; /* 100Khz @ 4Mhz Fosc */
}
 
 
/*
Function: I2CStart
Return:
Arguments:
Description: Send a start condition on I2C Bus
*/
void I2CStart()
{
SEN = 1; /* Start condition enabled */
while(SEN); /* automatically cleared by hardware */
/* wait for start condition to finish */
}
 
/*
Function: I2CStop
Return:
Arguments:
Description: Send a stop condition on I2C Bus
*/
void I2CStop(){
PEN = 1; /* Stop condition enabled */
while(PEN); /* Wait for stop condition to finish */
/* PEN automatically cleared by hardware */
}
 
/*
Function: I2CRestart
Return:
Arguments:
Description: Sends a repeated start condition on I2C Bus
*/
void I2CRestart(){
RSEN = 1; /* Repeated start enabled */
while(RSEN); /* wait for condition to finish */
}
 
/*
Function: I2CAck
Return:
Arguments:
Description: Generates acknowledge for a transfer
*/
void I2CAck(){
ACKDT = 0; /* Acknowledge data bit, 0 = ACK */
ACKEN = 1; /* Ack data enabled */
while(ACKEN); /* wait for ack data to send on bus */
}
 
/*
Function: I2CNck
Return:
Arguments:
Description: Generates Not-acknowledge for a transfer
*/
void I2CNak(){
ACKDT = 1; /* Acknowledge data bit, 1 = NAK */
ACKEN = 1; /* Ack data enabled */
while(ACKEN); /* wait for ack data to send on bus */
}
 
/*
Function: I2CWait
Return:
Arguments:
Description: wait for transfer to finish
*/
void I2CWait(){
while ( ( SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );
/* wait for any pending transfer */
}
 
/*
Function: I2CSend
Return:
Arguments: dat - 8-bit data to be sent on bus
data can be either address/data byte
Description: Send 8-bit data on I2C bus
*/
void I2CSend(unsigned char dat){
SSPBUF = dat; /* Move data to SSPBUF */
while(BF); /* wait till complete data is sent from buffer */
BF = 0;
I2CWait(); /* wait for any pending transfer */
}
 
/*
Function: I2CRead
Return: 8-bit data read from I2C bus
Arguments:
Description: read 8-bit data from I2C bus
*/
unsigned char I2CRead(void){
unsigned char temp;
/* Reception works if transfer is initiated in read mode */
RCEN = 1; /* Enable data reception */
while(!BF); /* wait for buffer full */
BF = 1;
temp = SSPBUF; /* Read serial buffer and store in temp register */
I2CWait(); /* wait to check any pending transfer */
return temp; /* Return the read data from bus */
}

 
Last edited by a moderator:

hi

automaticaly it will send the acknowledgment bit to the master
 

then why,that is not working???progrm gt compiled bt,when i tried in proteus it is not working...

- - - Updated - - -

This is my main file...i think problem with the main file only....is i am setting the time and date is correct??????????????????????????????
can any body suggest that


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
unsigned char I2CData[] = {0x00, 0x15, 0x11, 0x01, 0x25, 0x01, 0x09, 0x12};
    unsigned char *s[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    unsigned char add = 0, d;
 
void main()
{
    
    TRISB =0x00; // Configure PORTB as output
    TRISD=0x00;
    TRISC=0x00;
    init_lcd();
    I2CInit(); //DS1307 I2C is running at 100KHz
 
      
            while(add<=6)   //update real time clock
                        {
                         //display_lcd("It's done here");
                        write_ds1307(add,I2CData[add]); 
                        add++;  
                        }
 
        while(1)
        {
            d=read_ds1307(0x02);//read hour 
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(10);
            write_lcd(':');
            d=read_ds1307(0x01); // read minute;
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(10);
            write_lcd(':');
            d=read_ds1307(0x00); // read second
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(10);
            write_lcd(' ');
           display_lcd(s[read_ds1307(0x03)]); // read day
            delay_ms(10);
            cmd_lcd(0xc0);
            d=read_ds1307(0x04); // read date
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(10);
             write_lcd('/');
            d=read_ds1307(0x05); // read month
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(10);
            write_lcd('/');
            write_lcd('2');
            write_lcd('0');
            d=read_ds1307(0x06); // read year
            write_lcd((d/16)+48);
            write_lcd((d%16)+48);
            delay_ms(75);
            cmd_lcd(0x01);
        }
}

 
Last edited by a moderator:

can be any body suggest...by checking the program...
 

Can we see your DSN file and source code? hope you are using 16f877a MCU
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top