It is currently 23 Jul 2019 03:43

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 23 Apr 2008 22:45 
Offline

Joined: 15 Jan 2008 22:51
Posts: 6
Location: Mexico
Hi everybody i need some help with because my program don't work correctly i can`t read the time from RTC board (PCF8583) on port D i use pic 18f452 and this is my code for
set the RTC using Soft_I2C

void main() {

Soft_I2C_Config(&PORTD, 4, 3); // Initialize full master mode
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xA0); // Address PCF8583
Soft_I2C_Write(0); // Start from word at address 0 (configuration word)
Soft_I2C_Write(0x80); // Write 0x80 to config. (pause counter...)
Soft_I2C_Write(0); // Write 0 to cents word
Soft_I2C_Write(0); // Write 0 to seconds word
Soft_I2C_Write(0x30); // Write 0x30 to minutes word
Soft_I2C_Write(0x11); // Write 0x11 to hours word
Soft_I2C_Write(0x30); // Write 0x24 to year/date word
Soft_I2C_Write(0x08); // Write 0x08 to weekday/month
Soft_I2C_Stop(); // Issue stop signal

Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xA0); // Address PCF8530
Soft_I2C_Write(0); // Start from word at address 0
Soft_I2C_Write(0); // Write 0 to config word (enable counting)
Soft_I2C_Stop(); // Issue stop signal

}//~!

and my code for read the time from RTC using Soft_I2C

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;
}
}
//--------------------- lee la hora y la fecha desde el RTC (PCF8583)
void Read_Time(char *sec, char *min, char *hr, char *day, char *mn, char *year){
Soft_I2C_Start();
Soft_I2C_Write(0xA0);
Soft_I2C_Write(2);
Soft_I2C_Write(0xA1);
*sec= Soft_I2C_Read(1);
*min= Soft_I2C_Read(1);
*hr = Soft_I2C_Read(1);
*day= Soft_I2C_Read(1);
*mn = Soft_I2C_Read(0);
*year =Soft_I2C_Read(1);
Soft_I2C_Stop();
}//~
//--------------------Formato de fecha y tiempo
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 = ((*year & 0xC0) >> 4);
*day = ((*day & 0x30) >> 4)*10 + (*day & 0x0F);
*mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
}//~

//-------------------- Valores de salida para el 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,4,txt);
ByteToStr(mn,tnum);
txt = rtrim(tnum);
Zero_Fill(txt);
LCD_Out(1,7,txt);
LCD_Chr(1,13,44+year);
ByteToStr(hr,tnum);
txt = rtrim(tnum);
Zero_Fill(txt);
LCD_Out(2,5,txt);
ByteToStr(min,tnum);
txt = rtrim(tnum);
Zero_Fill(txt);
LCD_Out(2,8,txt);
ByteToStr(sec,tnum);
txt = rtrim(tnum);
Zero_Fill(txt);
LCD_Out(2,11,txt);
}//~

//------------------ Empieza el despliegue del menu en el LCD
void Init_Main() {
ADCON1=7;
TRISD = 0; // PORTD es salida
Soft_I2C_Config(&PORTD, 4,3 ); // inicializa modo completo maestro
LCD_Init(&PORTC);
LCD_Cmd(LCD_CLEAR);
// txt = "FECHA:";
//LCD_Out(1,1,txt);
LCD_Chr(1,6,'/');
LCD_Chr(1,9,'/');
//txt = "HORA:";
//LCD_Out(2,1,txt);
LCD_Chr(2,7,':');
LCD_Chr(2,10,':');
txt = "200";
LCD_Out(1,10,txt);
LCD_Cmd(LCD_CURSOR_OFF);
}//~

//----------------- Procedimiento Principal
void main() {
Init_Main(); // iniciatlizacion.
TRISB = 0x01;
PORTB = 0x08;

while (1)
{
Read_Time(&sec,&min1,&hr,&day,&mn,&year); // lee el tiempo del RTC(PCF8583)
Transform_Time(&sec,&min1,&hr,&day,&mn,&year); // formato de fecha y hora
Display_Time(sec, min1, hr, day, mn, year); // prepara para enviar al LCD

}

}


Top
 Profile  
 
 Post subject:
PostPosted: 24 Apr 2008 07:11 
Offline

Joined: 22 Oct 2005 17:35
Posts: 49
Location: Poznan, Poland
Hi

look at this post.
http://www.mikroe.com/forum/viewtopic.php?t=14073

soft i2c in 8.1 not working correctly ....


Top
 Profile  
 
 Post subject:
PostPosted: 24 Apr 2008 14:16 
Offline

Joined: 18 May 2005 00:59
Posts: 5465
Location: NYC
radiofm wrote:
soft i2c in 8.1 not working correctly ....


Has that been confirmed... And by whom?

_________________
xor
CircuitED -


Top
 Profile  
 
 Post subject:
PostPosted: 24 Apr 2008 15:25 
Offline

Joined: 15 Jan 2008 22:51
Posts: 6
Location: Mexico
hi radiofm, yes i tried with the program you sent me but don't work because didn't read the rtc from pcf8583 i don´t know why, can you help me please ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: