Code: Select all
char time=0x44;
unsigned temp;
unsigned x=0x44;
unsigned i=0;
void main(){
uart1_init(9600);
I2C1_Init(100000);
//µµµµµµµµµµµµµµµµµµµµµ
I2C1_Start();
I2C1_Write(0xD0);
I2C1_Write(0x00);
I2C1_Write(0x00);
I2C1_Write(0x59);
I2C1_Write(0x23);
I2C1_Write(0x2);
I2C1_Write(0x25);
I2C1_Write(0x11);
I2C1_Write(0x11);
I2c1_Stop();
//µµµµµµµµµµµµµµµµµµµµµ
while(1){
I2C1_Start();
I2C1_Write(0xD0);
I2C1_Write(0x00) ;
//µµµµµµµµµµµµµµµµµµµ
I2C1_Restart();
I2C1_Write(0xD1);
x = I2C1_Read(0); //Seconds
time = x & 0x30; //Avoid the CH bit
time >>= 4;
time += '0';
uart1_write_char(time);
time = x & 0x0F;
time += '0';
uart1_write_char(time);
//=======================
//=======================
I2C1_Wait_For_Idle();
x = I2C1_Read(0); //Minutes
temp = x & 0xF0 ;
temp >>= 4;
temp += '0';
time=temp;
uart1_write_char(time);
delay_ms(100);
temp = x & 0x0F;
temp += '0';
time=temp;
uart1_write_char(time);
//=======================
//=======================
I2C1_Wait_For_Idle();
x = I2C1_Read(1);//Read hours register
temp = x & 0xF0 ;
temp >>= 4;
temp +='0';
time=temp;
uart1_write_char(time);
temp = x & 0x0F;
temp += '0';
time=temp;
uart1_write_char(time);
I2c1_Stop();
uart1_write_char(' ');
}
}