Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 11, 2016, 03:09:05 03:09


Login with username, password and session length


Pages: [1]
Print
Author Topic: pcf8583 pic18f452 mikro c program problem  (Read 5932 times)
0 Members and 1 Guest are viewing this topic.
y0shi18
Inactive

Offline Offline

Posts: 2

Thank You
-Given: 2
-Receive: 0



« on: May 05, 2009, 06:58:17 06:58 »

from the given examples provided by mikroC database (programme) to program a RTC PCF8583 to Pic18F452 using MikroC :

Code:
* Project name:
     RTC_Read (Reading date/time stamp from PCF8583 through I2C)
 * Copyright:
     (c) MikroElektronika, 2005-2008
 * Revision History:
     20050130:
       - initial release;
 * Description:
     This project is simple demonstration how to read date and time from PCF8583
     RTC (real-time clock). The code can be used with any MCU that has MSSP
     module at PORTC. Date and time are printed at LCD.
 * Test configuration:
     MCU:             PIC16F877A/PIC18F4520
     Dev.Board:       EasyPIC5
     Oscillator:      HS, 8.000MHz
     Ext. Modules:    RTC module (PCF8583), LCD 2x16 chars
     SW:              mikroC v8.0
 * NOTES:
     - In order to use the example, address pin A0 of PCF8583 must be set to 0V!
     - For proper I2C communication, pins on PORTC must be in the pull-up mode,
       and the LEDs on board switched OFF!
 */

unsigned char sec, min1, hr, day, mn, year;
char *txt, tnum[4];

void Zero_Fill(char *value) {    // fill text repesentation
  if (value[1] == 0) {           //      with leading zero
    value[1] = value[0];
    value[0] = 48;
    value[2] = 0;
  }
}//~

//--------------------- Reads time and date information from RTC (PCF8583)
void Read_Time(char *sec, char *min, char *hr, char *day, char *mn, char *year) {
  I2C_Start();
  I2C_Wr(0xA0);
  I2C_Wr(2);
  I2C_Repeated_Start();
  I2C_Wr(0xA1);
  *sec =I2C_Rd(1);
  //while (I2C_Is_Idle() == 0) ;
  *min =I2C_Rd(1);
  //while (I2C_Is_Idle() == 0) ;
  *hr =I2C_Rd(1);
  //while (I2C_Is_Idle() == 0) ;
  *day =I2C_Rd(1);
  //while (I2C_Is_Idle() == 0) ;
  *mn =I2C_Rd(0);
  //while (I2C_Is_Idle() == 0) ;
  I2C_Stop();
}//~

//-------------------- Formats date and time
void Transform_Time(char  *sec, char *min, char *hr, char *day, char *mn, char *year) {
  *sec  =  ((*sec & 0xF0) >> 4)*10 + (*sec & 0x0F);
  *min  =  ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
  *hr   =  ((*hr & 0xF0) >> 4)*10 + (*hr & 0x0F);
  *year =  (*day & 0xC0) >> 6;
  *day  =  ((*day & 0x30) >> 4)*10 + (*day & 0x0F);
  *mn   =  ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
}//~

//-------------------- Output values to LCD
void Display_Time(char sec, char min, char hr, char day, char mn, char year) {
   ByteToStr(day,tnum);
   txt = rtrim(tnum);
   Zero_Fill(txt);
   LCD_Out(1,6,txt);
   ByteToStr(mn,tnum);
   txt = rtrim(tnum);
   Zero_Fill(txt);
   LCD_Out(1,9,txt);
   LCD_Chr(1,15,52+year);
   ByteToStr(hr,tnum);
   txt = rtrim(tnum);
   Zero_Fill(txt);
   LCD_Out(2,6,txt);
   ByteToStr(min,tnum);
   txt = rtrim(tnum);
   Zero_Fill(txt);
   LCD_Out(2,9,txt);
   ByteToStr(sec,tnum);
   txt = rtrim(tnum);
   Zero_Fill(txt);
   LCD_Out(2,12,txt);
}//~

//------------------ Performs project-wide init
void Init_Main() {
  ADCON1 = 0x0F;
  Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init_EP5, see Autocomplete
  I2C_Init(100000);         // initialize I2C
  txt = "Date:";            // prepare and output static text on LCD
  LCD_Out(1,1,txt);
  LCD_Chr(1,8,':');
  LCD_Chr(1,11,':');
  txt = "Time:";
  LCD_Out(2,1,txt);
  LCD_Chr(2,8,':');
  LCD_Chr(2,11,':');
  txt = "200";
  LCD_Out(1,12,txt);
  LCD_Cmd(LCD_CURSOR_OFF);   // cursor off
}//~

//----------------- Main procedure
void main() {
  Init_Main();                                     // perform initialization
  while (1) {
    Read_Time(&sec,&min1,&hr,&day,&mn,&year);      // read time from RTC(PCF8583)
    Transform_Time(&sec,&min1,&hr,&day,&mn,&year); // format date and time
    Display_Time(sec, min1, hr, day, mn, year);    // prepare and display on LCD
    Delay_ms(1000);                                // wait 1s
  }
}

It seems like there are compilation errors. i entered the i2c_addresses and the error will always appear at :


Code:
//----------------- Main procedure
void main() {
  Init_Main();                                     // perform initialization
  while (1) {
    Read_Time(&sec,&min1,&hr,&day,&mn,&year);      //   <------------------------- error appears here
    Transform_Time(&sec,&min1,&hr,&day,&mn,&year); // format date and time
    Display_Time(sec, min1, hr, day, mn, year);    // prepare and display on LCD
    Delay_ms(1000);                                // wait 1s
  }
}

Is it something that i have left out or there are some parts of the code requires modification?
i just want to compile this code so that it can be displayed in a 2x16 lcd.
The current source code is to Read only, not for writing time.
Sorry for the noob question.

Logged
smainj
Active Member
***
Offline Offline

Posts: 125

Thank You
-Given: 69
-Receive: 75



WWW
« Reply #1 on: May 05, 2009, 04:17:27 16:17 »

read time from PCF8583  ( tested with real simulation)
Logged

y0shi18
Inactive

Offline Offline

Posts: 2

Thank You
-Given: 2
-Receive: 0



« Reply #2 on: May 11, 2009, 04:56:01 04:56 »

thanks for the source and also the effort to try to make it work.

i was wondering why VRCON and CMCON is used and what are they used for ?
in this case, is USART needed for a Real time clock function?
The PCF 8583 is connected to pic18F452 through the C port, (RC3 and RC4).
how should i go about displaying the time in a 2x16 LCD ?

Thanks and much appreciated
Logged
smainj
Active Member
***
Offline Offline

Posts: 125

Thank You
-Given: 69
-Receive: 75



WWW
« Reply #3 on: May 13, 2009, 11:09:32 23:09 »

i hope this help you
Logged

Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC