[SOLVED] [Help Needed] PCF8583 RTC in MikroC using PIC18F4455

Status
Not open for further replies.

jinang

Junior Member level 1
Joined
May 14, 2011
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,532
hi,

we are working on a project that uses PCF8583 RTC and soft I2C of PIC18F4455 to send data to SCL and SDA at port B1 and B0 respectively. we made use of portD for the LCD display of the date and time (since we are required to display those) and portB for the RTC. can you help us out in our code. it does not work properly as expected. it displays:

Date: 45.25.2013
Time: @5.@5.@5

will it be possible that we only have some errors in getting the data? can you suggest ways on how we can eliminate the error. THANK YOU VERY MUCH!

also, there is this issue with our hardware. the LCD does not display anything upon turning on the supply, but after holding the capacitor (22pF) attached to the oscillator, it eventually works but there are times that it does not work at all. we don't think that it has anything to do with the 8Mhz clock because we tried several oscillators already.

here's our code.

char seconds, minutes, hours, day, month, year; // Global date/time variables

//--------------------- Reads time and date information from RTC (PCF8583)
void Read_Time() {

Soft_I2C_Config(&PORTB, 0, 1); // Initialize full master mode
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xA0); // Address PCF8583, see PCF8583 datasheet
Soft_I2C_Write(2); // Start from address 2
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(0xA1);

seconds = Soft_I2C_Read(1); // Read seconds byte
minutes = Soft_I2C_Read(1); // Read minutes byte
hours = Soft_I2C_Read(1); // Read hours byte
day = Soft_I2C_Read(1); // Read year/day byte
month = Soft_I2C_Read(0); // Read weekday/month byte
Soft_I2C_Stop(); // Issue stop signal

}

//-------------------- Formats date and time
void Transform_Time() {
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); // Transform hours
year = (day & 0xC0) >> 6; // Transform year
day = ((day & 0x30) >> 4)*10 + (day & 0x0F); // Transform day
month = ((month & 0x10) >> 4)*10 + (month & 0x0F); // Transform month

EEPROM_Write(0x20, seconds);
EEPROM_Write(0x30, minutes);
EEPROM_Write(0x40, hours);
EEPROM_Write(0x50, year);
EEPROM_Write(0x60, day);
EEPROM_Write(0x70, month);
}

//-------------------- Output values to LCD
void Display_Time() {

Lcd_Chr(1, 6, (EEPROM_Read(0x60) / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (EEPROM_Read(0x60) % 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (EEPROM_Read(0x70) / 10) + 48);
Lcd_Chr(1,10, (EEPROM_Read(0x70) % 10) + 48);
Lcd_Chr(1,15, EEPROM_Read(0x50) + 48); // Print year variable (start from year 2010)


Lcd_Chr(2, 6, (EEPROM_Read(0x40) / 10) + 48);
Lcd_Chr(2, 7, (EEPROM_Read(0x40) % 10) + 48);
Lcd_Chr(2, 9, (EEPROM_Read(0x30) / 10) + 48);
Lcd_Chr(2,10, (EEPROM_Read(0x30) % 10) + 48);
Lcd_Chr(2,12, (EEPROM_Read(0x20) / 10) + 48);
Lcd_Chr(2,13, (EEPROM_Read(0x20) % 10) + 48);
}

//------------------ Performs project-wide init
void Init_Main() {

TRISD = 0;
PORTD = 0xFF;
TRISD = 0xFF;
//PORTE = 0x00;
//CCP1CON = 0x00;

//INTCON = 0x00;
ADCON1 = 0x0F;
SPPCON = 0x00;
SPPCFG = 0x00;
UCON = 0x00;

SSPCON1 = 0x20;

Soft_I2C_Config(&PORTB, 0, 1); // Initialize Soft I2C communication
Lcd_Init(&PORTD); // Initialize LCD
Lcd_Cmd(Lcd_CLEAR); // Clear LCD display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off

Lcd_Out(1,1,"Date:"); // Prepare and output static text on LCD
Lcd_Chr(1,8,'.');
Lcd_Chr(1,11,'.');
Lcd_Chr(1,16,'.');
Lcd_Out(2,1,"Time:");
Lcd_Chr(2,8,':');
Lcd_Chr(2,11,':');
Lcd_Out(1,12,"201"); // start from year 2010
}

//----------------- Main procedure
void main() {
Delay_ms(500);

Init_Main(); // Perform initialization

while (1) { // Endless loop
Read_Time(); // Read time from RTC(PCF8583)
Transform_Time(); // Format date and time
Display_Time(); // Prepare and display on LCD
}
}
 

The SCL and SDA lines need to be pulled up; have you done that? You could use either external 4.7k(s) or enable the internal weak pullups available on the 18F4455 port B.

Regards,

Anand Dhuru
 
Reactions: jinang

    jinang

    Points: 2
    Helpful Answer Positive Rating
yes. we've already done that. we also grounded the other pins of the RTC besides SCL and SDA, but still, it display the same output. we are not really sure of the connection in the breadboard, we assume that we can just connect the RTC pins directly to the equivalent pins in the microcontroller. is that right?
 

On the LCD problem, can you try and add on the lcd.c init librarie ( i haven´t posted it but i guess you are using one ^^) something like:

__delay_ms(200);

right after enable the ADCON, and the ports and before setting up the RS,EN and RW pins, this helped me out alot, i used to have a problem similar to yours.

This delay on the init routine of the lcd solved it out.



About the other problem i do believe you have some error on the code. mainly on the configs of the SPPCON. But this i will try to check out when i have time.

Are you using the routines given by default on the Hi Tech C compiler?

Best regads,
Zwi
 

re: LCD problem

hi, thank you for the suggestion. we'll try it immediately. if that seems to work then i think the other problem might also work (probably). =)

re: I2C problem

(note:we transferred to PIC18F4520, it is basically the same with what we used before, PIC18F4455, the only difference is that it doesn't have USB feature which greatly helped us because we don't have to configure the USB registers that sometimes really messes up with the general IO ports).

actually we've checked the code already and it does work at the EASYPIC5 development board wherein all components needed are already built in. we have used the PIC18F4520, having the SCL and SDA at RC3 and RC4 respectively. however, trying it in the breadboard, (i assume we have the right connections) the whole thing does not work. so, we thought that maybe there are just some hidden or i mean internal connections that we fail to consider. it might not be due to the code error.

we have been using the code example in the MikroC compiler, we just add several lines to display the reading at the LCD.

THANK YOU VERY MUCH!
 

@zwi: your suggestion worked! it does resolve the same problem with ours. thank you very much!

@ard: yes we have done that. THANK YOU VERY MUCH! the circuit worked already!!! it seems that we just had connected a pull up for RC3 and RC4, instead of pull ups for all of the pins except that pin intended for ground.

THANK YOU ard and zwi
 

i don't think so. the LCD does not have any brand printed on it hahahaha, only the model number - C3100371110305.

 

:s

okey i only asked because for what i know only this particular manufacturer makes this LCD so.... hmmmm slow* ( to not say other things) to start ^^.

and in the datasheets they don´t mention it anywhere... i found that out with trial and error :S
 


Hi,

Would you like to post please your code?

Because it seems that I have the same problem. My date is displayed: dd/mm/yy and time: hh:mm:ss, but it displays:

45/25/2012
45:165:1
As far as the seconds are concerned, they are incrementing correctly.

Thank you in advance.
 

Your readings show the way they do perhaps because you're treating the data stream from the RTC as binary; its actually BCD. So, break up each digit and you should have the right reading.

Regards,

Anand Dhuru
 




You should create a new thread

If trying to get strings by printf to the LCD check this site https://www.cplusplus.com/reference/clibrary/cstdio/printf/ , it explains the output procedures.

GLHF
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…