[ shadow-bg @ 23.05.2012. 20:45 ] @
Ne znam kako da sklopim string :( Prikazuje vreme kako treba, ali kad treba da mi sklopi u varijabli "tekst" vreme, dobijem prazan string. I izbacuje mi "implicit cast of integral value to pointer" u mojoj funkciji str_vreme i izbacuje mi "pointer conversion to int type" kad pozovem funkciju. Kako ovo da uradim? U pitanju je Mikroelektronika C kompajler, u fazonu ANSI C Code: unsigned char sec, min1, hr, week_day, day, mn, year; char *tekst; 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 (DS1307) void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) { Soft_I2C_Start(); Soft_I2C_Write(0xD0); Soft_I2C_Write(0); Soft_I2C_Start(); Soft_I2C_Write(0xD1); *sec =Soft_I2C_Read(1); *min =Soft_I2C_Read(1); *hr =Soft_I2C_Read(1); *week_day =Soft_I2C_Read(1); *day =Soft_I2C_Read(1); *mn =Soft_I2C_Read(1); *year =Soft_I2C_Read(0); Soft_I2C_Stop(); }//~ //-------------------- 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); }//~ void str_vreme(char sec, char min, char hr, char week_day, char day, char mn, char year) { switch(week_day){ case 1: txt="Ned"; break; case 2: txt="Pon"; break; case 3: txt="Uto"; break; case 4: txt="Sre"; break; case 5: txt="Cet"; break; case 6: txt="Pet"; break; case 7: txt="Sub"; break; } tekst = ""; tekst = strcat(tekst, txt); tekst = strcat(tekst, " "); tekst = strcat(tekst, day); tekst = strcat(tekst, "-"); tekst = strcat(tekst, mn); tekst = strcat(tekst, "-20"); tekst = strcat(tekst, year); tekst = strcat(tekst, " "); tekst = strcat(tekst, hr); tekst = strcat(tekst, ":"); tekst = strcat(tekst, min); tekst = strcat(tekst, ":"); tekst = strcat(tekst, sec); } void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) { switch(week_day){ case 1: txt="Ned"; break; case 2: txt="Pon"; break; case 3: txt="Uto"; break; case 4: txt="Sre"; break; case 5: txt="Cet"; break; case 6: txt="Pet"; break; case 7: txt="Sub"; break; } // LCD_Out(1,1,txt); // Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable // Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable // Lcd_Chr(1, 9, (mn / 10) + 48); // Lcd_Chr(1,10, (mn % 10) + 48); // Lcd_Chr(1,15, year + 48); // Print year vaiable + 8 (start from year 2008) // Lcd_Chr(1, 12, (year / 10) + 48); // Lcd_Chr(1,13, (year % 10) + 48); Lcd_Chr(2, 6, (hr / 10) + 48); Lcd_Chr(2, 7, (hr % 10) + 48); Lcd_Chr(2, 9, (min / 10) + 48); Lcd_Chr(2,10, (min % 10) + 48); Lcd_Chr(2,12, (sec / 10) + 48); Lcd_Chr(2,13, (sec % 10) + 48); }//~ void main(){ Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init_EP5, see Autocomplete LCD_Cmd(LCD_CLEAR); // Clear display LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307) Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // format date and time str_vreme(&sec,&min1,&hr,&week_day,&day,&mn,&year); LCD_Out(1,1,tekst); } |