User manual
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
455
seconds = ((seconds and 0xF0) >> 4)*10 + (seconds and 0x0F) ‘ Transform seconds
minutes = ((minutes and 0xF0) >> 4)*10 + (minutes and 0x0F) ‘ Transform months
hours = ((hours and 0xF0) >> 4)*10 + (hours and 0x0F) ‘ Transform hours
year = (day and 0xC0) >> 6 ‘ Transform year
day = ((day and 0x30) >> 4)*10 + (day and 0x0F) ‘ Transform day
month_ = ((month_ and 0x10) >> 4)*10 + (month_ and 0x0F) ‘ Transform month
end sub
‘-------------------- Output values to LCD
sub procedure Display_Time()
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 sub
‘------------------ Performs project-wide init
sub procedure Init_Main()
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 sub
‘----------------- Main procedure
main:
Delay_ms(1000)
Init_Main() ‘ Perform initialization
while TRUE ‘ Endless loop
Read_Time() ‘ Read time from RTC(PCF8583)
Transform_Time() ‘ Format date and time
Display_Time() ‘ Prepare and display on LCD
wend
end.