Estudiante

Páginas: 4 (996 palabras) Publicado: 21 de enero de 2013
PROGRAMAS DE DS1307 E I2C
void start1307s();
void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year);
void Transform_Time(char *sec, char *min, char *hr,char *week_day, char *day, char *mn, char
*year);
void Display_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char
*year);
void Init_Main();
void start1307s(){
//STARTSIGNAL FOR DS1307***********
I2C_Start(); // issue start signal
I2C_Wr(0xD0); // address PCF8530
I2C_Wr(0); // start from word at address 0
I2C_Wr(0); // write 0 to config word (enable counting)I2C_Stop(); // issue stop signal
//**********************************
}//~
unsigned char sec, min1, hr, week_day, day, mn, year;
char *txt, tnum[4];
void Zero_Fill(char *value) { // fill textrepesentation
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)
voidRead_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year)
{
I2C_Start();
I2C_Wr(0xD0);
I2C_Wr(0);
I2C_Repeated_Start();
I2C_Wr(0xD1);
*sec =I2C_Rd(1);
*min=I2C_Rd(1);
*hr =I2C_Rd(1);
*week_day =I2C_Rd(1);
*day =I2C_Rd(1);
*mn =I2C_Rd(1);
*year =I2C_Rd(0);
I2C_Stop();
}//~

1

//-------------------- 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: txt="Sun"; break;
case 2:...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Estudiante
  • Estudiante
  • Estudiante
  • Estudiante
  • El estudiante
  • Estudiante
  • Estudiante
  • Estudiante

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS