I think it is someting to do with these lines:
Code: Select all
min = ((min && 0xF0) >> 4)*10 + (min && 0x0F);
hour = ((hour && 0xF0) >> 4)*10 + (hour && 0x0F);
Whole program code:
Code: Select all
void gettime()
{
unsigned short sekunti, min, hour, vuosi, vkpv, sek;
char *txt;
I2C_Start(); //generate start
I2C_Wr(0xA0); //write addres of PCF8583
I2C_Wr(2); //select second register
I2C_Repeated_Start(); //generate repeated start
I2C_Wr(0xA1); //write address for reading info
sekunti = I2C_Rd(1); //read seconds
while (I2C_Is_Idle() == 0) asm nop;
min = I2C_Rd(1); //read minutes
while (I2C_Is_Idle() == 0) asm nop;
hour = I2C_Rd(1); //read hours
while (I2C_Is_Idle() == 0) asm nop;
vuosi = I2C_Rd(1); //read year and days
while (I2C_Is_Idle() == 0) asm nop;
vkpv = I2C_Rd(0); //read weekday and month
while (I2C_Is_Idle() == 0) asm nop;
I2C_Stop(); //generate stop
min = ((min && 0xF0) >> 4)*10 + (min && 0x0F);
hour = ((hour && 0xF0) >> 4)*10 + (hour && 0x0F);
byteToStr(hour,txt);
LCD_Out(2,1,tunti);
byteToStr(min,txt);
LCD_Out(2,6,minuutti);
//byteToStr(sekunti,txt);
//LCD_Out(2,10,sekunti);
}
void main(){
int sekunti, minuutti, tunti, paiva, kuukausi, vuosi, vkpv;
TRISA = 0;
TRISB = 0; // PORTB asetetaan lähdöksi
TRISC = 0; // PORTC asetetaan lähdöksi
Lcd_Init(&PORTB); // Alustetaan LCD
Lcd_Cmd(Lcd_CLEAR); // Tyhjennetään näyttö
Lcd_Cmd(Lcd_CURSOR_OFF); // Kursori pois
Lcd_Out(1, 1, "I2C Kello"); // Tulostetaan näyttöön, 1. rivi, 1. sarake
Lcd_Cmd(Lcd_RETURN_HOME); // Kursori kotiin
Delay_ms(1000);
I2C_Init(100000);
sekunti = 40;
minuutti = 15;
tunti = 11;
paiva = 19;
kuukausi = 12;
sekunti = Dec2Bcd(sekunti); //seconds
minuutti = Dec2Bcd(minuutti); //minuts
tunti = Dec2Bcd(tunti); //hours
paiva = Dec2Bcd(paiva); //days
kuukausi = Dec2Bcd(kuukausi); //months
I2C_Start(); //generate start
I2C_Wr(0xA0); //write address
I2C_Wr(0); //select control register
I2C_Wr(8); //set year and day bit for masking
I2C_Stop(); //generate stop
delay_ms(100);
I2C_Start(); //generate start
I2C_Wr(0xA0); //write mode
I2C_Wr(2); //select seconds Register
I2C_Wr(sekunti); //write seconds
I2C_Wr(minuutti); //write minuts
I2C_Wr(tunti); //write hours
I2C_Wr(paiva); //write days
I2C_Wr(kuukausi); //write months
I2C_Stop();
while (1 == 1)
{
gettime();
delay_ms(200);
}
}