You are on page 1of 4

// Primera version del registrador de datos para el proyecto de titulacion // Notas de la verion V2.

05 (02/enero/2014) // Estado: // - Xlogger registra la presion de forma directa // - lee el RTC (preconfigurado desde un PC) y muestra la hora y fecha en pantalla (Fucking Fixed, need year arr.) // - Implementacion de los datos mostrados en pantalla mediante una sol icitud // Siguiente: // // - Implementacion de registro en una EEPROM externa // - Crear un archivo TXT/CSV con los datos registrados // - plantear interrupciones externas para el envio de datos por telem etria (preeliominar) o por MAIN // - crear una interface para configurar la hora y fecha de forma manu al // de forma provisoria mientras se crea una interface visual prototi po // similar a RW! #include <built_in.h> #include "m_i2c_1.h" //#device 18F4520 *=18 #define __MY_SOFT_I2C__ #define VERSION_STR "Build V2.04" #define YEAR_MIN 13 #define YEAR_MAX 99 //#define DS_sec 0x00; char char char char char Year; Channels; Mode; Details; Csv;

struct { char sec; char min; char hour; char day; char month; unsigned int year; char ctrl_stat; char cents; char bcd; char sec_bcd; char min_bcd; char hour_bcd; char day_bcd; char month_bcd; char year_bcd; } Time;

unsigned int Lectura; char message1[] = "Legioss"; //Nombre :P char message2[] = "Build 2.05"; char message3[] = "hh:mm:ss";

// version // MEGA - dummy

char *temp = "0000 P"; //char *Year = "2013"; char String[40]; void Format_Time(char *p_str); char bcd_to_bin(char bcd); void bcd_to_ascii(char *p_dst, unsigned char bcd); void IntToStrZeroPad(int v, char *p_str, char i); void Format_Time(char *p_str); void Format_date(char *p_str); void Display_Date(void); void Display_Time(void); void Display_Inputs(void); char incdec(char v, char v_min, char v_max); void RTC_Read(void); void RTc_clear(void); void Show_time_date(void); void Show_date(void); void Capture_mess(void); void Show_all(void); int b; int Cantidad_med; int Veces; int Factor_A; int Lect; short Tiempo; int i; int oldstate; void Capture_mess(void){ Factor_A = 48; Lectura = Adc_Read(0); Lectura temp[0] temp[1] temp[2] temp[3] } void bcd_to_ascii(char *p_dst, unsigned char bcd){ p_dst[0] = ((bcd>>4)&0x0f) + '0'; p_dst[1] = (bcd&0x0f) + '0'; } void IntToStrZeroPad(int v, char *p_str, char i){ IntToStr(v,p_str); while (p_str[i]==' ' && i<6){ p_str[i] = '0'; i += 1; } } char bcd_to_bin(char bcd){ return ((bcd>>4)&0x0f)*10 + (bcd&0x0f); = Lectura + 129; = Lectura/1000 + Factor_A; =(Lectura/100)%10 + Factor_A; =(Lectura/10)%10 + Factor_A; = Lectura%10 + Factor_A;

} void RTC_read(void){ i2cstart(); i2csendbyte(0xa0); // Address of RTC. i2cgetack(); i2csendbyte(0x03); // Set first register to read. i2cgetack(); I2C_Receive(0xa0,&Time.sec_bcd,7); I2C_Stop(); if (Time.month_bcd == 0x01&0xFF && Time.day_bcd == 0x01&0xFF){ Year++; } Time.day_bcd &= 0x3f; Time.month_bcd &= 0x1f; Year = 0x14&0xFF;//dec2Bcd(Year); Time.sec = bcd_to_bin(Time.sec_bcd); Time.min = bcd_to_bin(Time.min_bcd); Time.hour = bcd_to_bin(Time.hour_bcd); Time.day = bcd_to_bin(Time.day_bcd); Time.month = bcd_to_bin(Time.month_bcd); } void Format_Date(char *p_str){ strcpy(p_str," / / "); bcd_to_ascii(p_str,Time.day_bcd); bcd_to_ascii(p_str+3,Time.month_bcd); p_str[6] = '2'; p_str[7] = '0'; bcd_to_ascii(p_str+8,Year); } void Format_Time(char *p_str){ strcpy(p_str," : "); bcd_to_ascii(p_str,Time.hour_bcd); bcd_to_ascii(p_str+3,Time.min_bcd); bcd_to_ascii(p_str+6,Time.sec_bcd); } void Show_time_date(){ strcpy(String," : "); Format_Time(String); Lcd_Out(3,11,String); //Delay_ms(300); strcpy(String," / / "); Format_date(String); Lcd_out(4,7,String); //Delay_ms(300); } void Display_inputs(void){ RTC_read(); Show_time_date(); //Delay_ms(300); //Lcd_Cmd(Lcd_Clear); //Delay_ms(300); } void Show_all(void){ Lcd_Cmd(Lcd_Clear);

Lcd_Out(1,3," Ch1"); Lcd_Out(2,11, temp ); //Display_inputs(); RTC_read(); strcpy(String," : "); Format_Time(String); Lcd_Out(3,8,String); //Delay_ms(300); RTC_read(); strcpy(String," / / "); Format_date(String); Lcd_out(4,3,String); //Delay_ms(300); Delay_ms(1000); Lcd_Cmd(Lcd_Clear); } void main(){ ADCON1 = 0x80; PORTB = 1; TRISB = 1; PORTC = 0; TRISC = 0; //I2C_init(1000011); Lcd_Init(&PORTD); Lcd_Cmd(Lcd_Clear); Lcd_Cmd(Lcd_Cursor_Off); Rtc_read(); // for fixing the pos. min-sec VIA... Lcd_out(1,1,message1); delay_ms(500); Lcd_cmd(Lcd_clear); Lcd_out(1,1,message2); delay_ms(500); Lcd_cmd(Lcd_clear); do { Capture_mess(); if (Button(&PORTB, 7, 1, 1)) oldstate = 1; if (oldstate && Button(&PORTB, 7, 1, 0)) { Show_all(); oldstate = 0; } } while(1); }

You might also like