User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
454
//-------------------- Formats date and time
procedure Transform_Time();
begin
seconds := ((seconds and 0xF0) shr 4)*10 + (seconds and 0x0F);// Transform seconds
minutes := ((minutes and 0xF0) shr 4)*10 + (minutes and 0x0F);// Transform months
hours := ((hours and 0xF0) shr 4)*10 + (hours and 0x0F); // Transform hours
year := (day and 0xC0) shr 6; // Transform year
day := ((day and 0x30) shr 4)*10 + (day and 0x0F); // Transform day
month := ((month and 0x10) shr 4)*10 + (month and 0x0F); // Transform month
end;
//-------------------- Output values to LCD
procedure Display_Time();
begin
Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (day mod 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (month / 10) + 48);
Lcd_Chr(1,10, (month mod 10) + 48);
Lcd_Chr(1,15, year + 57);// Print year vaiable + 9 (start from year 2009)
Lcd_Chr(2, 6, (hours / 10) + 48);
Lcd_Chr(2, 7, (hours mod 10) + 48);
Lcd_Chr(2, 9, (minutes / 10) + 48);
Lcd_Chr(2,10, (minutes mod 10) + 48);
Lcd_Chr(2,12, (seconds / 10) + 48);
Lcd_Chr(2,13, (seconds mod 10) + 48);
end;
//------------------ Performs project-wide init
procedure Init_Main();
begin
ADPCFG := 0xFFFF; // initialize AN pins as digital
Soft_I2C_Init(); // Initialize Soft I2C communication
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1,’Date:’); // Prepare and output static text on LCD
Lcd_Chr(1,8,’:’);
Lcd_Chr(1,11,’:’);
Lcd_Out(2,1,’Time:’);
Lcd_Chr(2,8,’:’);
Lcd_Chr(2,11,’:’);
Lcd_Out(1,12,’200’);
end;
//----------------- Main procedure
begin
Delay_ms(1000);
Init_Main(); // Perform initialization
while TRUE do // Endless loop
begin
Read_Time(); // Read time from RTC(PCF8583)
Transform_Time(); // Format date and time
Display_Time(); // Prepare and display on LCD
end;
end.