elizabeth ann
Junior Member level 2
- Joined
- Feb 16, 2008
- Messages
- 21
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,468
elizabeth ann said:hello everyone.
i'm new here, i would like to ask for some assistance regarding my project, which on interfacing DS1307 with 16F877. basically i will be using this on my programmable medicine dispenser, and i need DS1307 as my clock source and synchronization so that the medications will always be on time. how do i call the DS1307 so that if a preset time is reached (input through keypad), the microcontroller will signal an alarm and a blinking LED indicator?
by the way, i'm using C language and CCS C Compiler.
Thank you very much.
Elizabeth Ann
elizabeth ann said:hello H_D_R...
that's correct, i am using PIC 16F877a as my microcontroller.
how do i store time manually using keypad and how can i check if my preset time is reached?
thanks a lot.
elizabeth ann
elizabeth ann said:wow, very fast reply, thank you.
yes i am storing both the alarm and the clock.
i am using DS1307 with 16F877a, and i am constructing the program in CCS C.
any suggestions? thank you again.
////////////////////////////////////////////////////////////////////////
void init_I2C ( void )
{
output_float( I2C_SCL ) ;
output_float( I2C_SDA ) ;
}
////////////////////////////////////////////////////////////////////////
int1 i2c_ready ( unsigned int8 address )
{
int1 ack ;
i2c_start() ; // If the write command is acknowledged,
ack = i2c_write( address ) ; // then the device is ready.
i2c_stop() ;
return ( !ack ) ;
}
////////////////////////////////////////////////////////////////////////
void I2CSendByte ( unsigned int8 Chip , unsigned int8 address , unsigned int8 data_value )
{
/// while ( ! i2c_ready ( address ) ) ;
/// i2c_stop() ;
delay_us ( 10 ) ; /* Solucao Empirica */
i2c_start() ; /* START CONDITION */
i2c_write( Chip | ESCRITA ) ; /* SLAVE ADDRESS -> WRITE */
i2c_write( address ) ; /* WORD ADDRESS */
i2c_write( data_value ) ; /* WRITE DATA */
i2c_stop() ; /* STOP CONDITION */
delay_ms ( 50 ) ; /* Solucao Empirica */
}
////////////////////////////////////////////////////////////////////////
unsigned int8 I2CGetByte( unsigned int8 Chip , unsigned int8 address )
{
unsigned int8 data_value ;
/// i2c_stop() ;
delay_us ( 10 ) ; /* Solucao Empirica */
i2c_start() ; /* START CONDITION */
i2c_write( Chip | ESCRITA ) ; /* SLAVE ADDRESS -> WRITE */
if ( Chip == SELECT_LM75A )
i2c_write( ENDERECO_TEMPERATURA ) ; /* WORD ADDRESS */
else
i2c_write( address ) ; /* WORD ADDRESS */
delay_us ( 10 ) ; /* Solucao Empirica */
i2c_start() ; /* SATRT CONDITION */
i2c_write( Chip | LEITURA ) ; /* SLAVE ADDRESS -> READ */
if ( Chip == SELECT_LM75A )
{
TemperaturaDaPlaca = i2c_read() ; /* READ DATA */
data_value = (unsigned int8)TemperaturaDaPlaca ;
TemperaturaDaPlaca <<= 8 ;
TemperaturaDaPlaca |= i2c_read() ; /* READ DATA */
}
else
data_value = i2c_read() ; /* READ DATA */
i2c_stop() ; /* STOP CONDITION */
delay_ms ( 50 ) ; /* Solucao Empirica */
return( data_value ) ;
}
////////////////////////////////////////////////////////////////////////
void ds1307_send_byte ( unsigned int8 address, unsigned int8 data_value )
{
I2CSendByte ( SELECT_DS1307 , address , data_value ) ;
}
////////////////////////////////////////////////////////////////////////
unsigned int8 ds1307_get_byte ( unsigned int8 address )
{
unsigned int8 Resposta ;
Resposta = I2CGetByte( SELECT_DS1307 , address ) ;
return ( Resposta ) ;
}
////////////////////////////////////////////////////////////////////////
void ds1307_send_time( void )
{
delay_us ( 10 ) ; /* Solucao Empirica */
i2c_start() ; /* START CONDITION */
i2c_write( SELECT_DS1307 | ESCRITA ) ; /* SLAVE ADDRESS -> WRITE */
i2c_write( MINUTES ) ; /* WORD ADDRESS */
i2c_write( Minuto_ds1307_digitos ) ; /* WRITE DATA */
i2c_write( Hora_ds1307_digitos ) ; /* WRITE DATA */
i2c_write( Semana_ds1307_digitos ) ; /* WRITE DATA */
i2c_write( Dia_ds1307_digitos ) ; /* WRITE DATA */
i2c_write( Mes_ds1307_digitos ) ; /* WRITE DATA */
i2c_write( Ano_ds1307_digitos ) ; /* WRITE DATA */
i2c_stop() ; /* STOP CONDITION */
delay_ms ( 50 ) ; /* Solucao Empirica */
}
////////////////////////////////////////////////////////////////////////
void ds1307_get_time( void )
{
i2c_start() ;
i2c_write( SELECT_DS1307 | ESCRITA ) ;
i2c_write( MINUTES ) ;
i2c_start() ;
i2c_write( SELECT_DS1307 | LEITURA ) ;
Minuto_ds1307_digitos = i2c_read() ;
Hora_ds1307_digitos = i2c_read() ;
Semana_ds1307_digitos = i2c_read() ;
Dia_ds1307_digitos = i2c_read() ;
Mes_ds1307_digitos = i2c_read() ;
Ano_ds1307_digitos = i2c_read() ;
i2c_stop() ;
}
////////////////////////////////////////////////////////////////////////
ds1307_send_byte( CONTROL, CONTROL_WORD );
ds1307_send_byte( SECONDS , ( CH | 0 ) ) ;
ds1307_send_byte( MINUTES , ( ( MinutoDezena << 4 ) | MinutoUnidade ) ) ;
ds1307_send_byte( HOURS , ( ( HoraDezena << 4 ) | HoraUnidade ) ) ;
ds1307_send_byte( DAY , INIT_DAY ) ;
ds1307_send_byte( DATE , ( ( DiaDezena << 4 ) | DiaUnidade ) ) ;
ds1307_send_byte( MONTH , ( ( MesDezena << 4 ) | MesUnidade ) ) ;
ds1307_send_byte( YEAR , ( ( AnoDezena << 4 ) | AnoUnidade ) ) ;
i am implementing my project first in simulation only. i am using PROTEUS VSM 7.1, and the KEYPAD-PHONE in that simulator is the one that i'm using.
H_D_R said:elizabeth ann said:wow, very fast reply, thank you.
yes i am storing both the alarm and the clock.
i am using DS1307 with 16F877a, and i am constructing the program in CCS C.
any suggestions? thank you again.
sorry to say but i dont have any experience of 16F877a not even CCS C too.
i am using 89S52 with DS1307 in ASM language.
so i can help you only DS1307 side part. but if you can understand flow then you can implement in your CCS C.
please let me know have u read datasheet of DS1307..??
if yes then the details regarding storing time is already given there.
by the way according to me, first you need to interface you MCU with LCD and keypad..then only you move to RTC.
have you done above both the interfacing parts..??
may i know which keypad r u using ?
IF YOU REALLY WANT TO LEARN PROGRAMMING THEN KEEP ONE THING ALWAYS IN MIND. DONT USE READYMADE CODE. YA U CAN REFER IT BUT PLEASE AVAOID TO USE IT AS IT IS IN YOU PROGRAM.
penoy_balut said:You have to poll DS1307 not PIC16F877A, most compilers have built-in I2C functions making it very easy to code project like yours.
elizabeth ann said:thanks for your patience, HDR..
well i have been developing my own code right now but any help from everyone else will be very important to the success of this project. to explain our project further, i would be very glad to send you a simple flowchart of how things are going to be done. if you're interested to get this, please just tell me.
by the way, as i have previously mentioned, everything has to be in C language. they say that i have to continuously poll the micro (16f877a) to get time from DS1307. hope that simple info helps. again, about the flowchart, you can help me better if you could have a copy of it. just tell me if you want to. i honestly need help on this.
thank you very much.
elizabeth ann
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?