ADGAN
Full Member level 5
- Joined
- Oct 9, 2013
- Messages
- 295
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 18
- Activity points
- 1,837
Hi! I'm trying to port a code written for DS1307 in MikroC to MPLAB. It compiles but when I simulate in Proteus nothing shows on the I2C debugger. What have I done wrong?
My main function: (This is a part of it)
Code:
#include <stdlib.h>
#include <i2c.h>
char tnum[4],txt;
void start1307s(){
OpenI2C1(SLAVE_7_STSP_INT,SLEW_OFF);
//START SIGNAL FOR DS1307***********
StartI2C1() ;// issue start signal
WriteI2C1(0xD0); // address PCF8530
WriteI2C1(0); // start from word at address 0
WriteI2C1(0); // write 0 to config word (enable counting)
StopI2C1 (); // issue stop signal
//**********************************
}
void Zero_Fill(char *value) { // fill text representation
if (value[1] == 0) { // with leading zero
value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}
//--------------------- Reads time and date information from RTC (DS1307)
void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
StartI2C1();
WriteI2C1(0xD0);
WriteI2C1(0);
RestartI2C1 ();
WriteI2C1(0xD1);
*sec =ReadI2C1();
*min =ReadI2C1();
*hr =ReadI2C1();
*week_day =ReadI2C1();
*day =ReadI2C1();
*mn =ReadI2C1();
*year =ReadI2C1();
StopI2C1 ();
}
//-------------------- Formats date and time
void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) {
*sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);
*min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
*hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);
*week_day =(*week_day & 0x07);
*day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);
*mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
*year = ((*year & 0xF0)>>4)*10+(*year & 0x0F);
}
//-------------------- Output values to LCD
void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) {
switch(week_day){
case 1: strcpypgm2ram(txt,"Sun"); break;
case 2: strcpypgm2ram(txt,"Mon"); break;
case 3: strcpypgm2ram(txt,"Tue"); break;
case 4: strcpypgm2ram(txt,"Wed"); break;
case 5: strcpypgm2ram(txt,"Thu"); break;
case 6: strcpypgm2ram(txt,"Fri"); break;
case 7: strcpypgm2ram(txt,"Sat"); break;
}
LCD_TextOut(3,4,txt);
btoa(day,tnum);
Zero_Fill(txt);
LCD_TextOut(3,7,txt);
btoa(mn,tnum);
Zero_Fill(txt);
LCD_TextOut(3,11,txt);
btoa(year,tnum);
Zero_Fill(txt);
LCD_TextOut(3,17,txt);
}
My main function: (This is a part of it)
Code:
unsigned char sec, min1, hr, week_day, day, mn, year;
void __init(void){
LCD_Init();
Init_Delay();
}
char txt1[] = "ENERGY CONSUMPTION";
void main(void)
{
LCD_TextOut(0,1,txt1);
start1307s();
Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year);
Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year);
Display_Time(sec, min1, hr, week_day, day, mn, year);