Well, I asked both to create a simple code - Read time from DS3231 and display it on HD44780 display.
Judge by yourself 
Code:
' PICBasic Pro Code to Read DS3231 RTC and Display Time on LCD
' Connections:
' - DS3231: SDA -> PORTC.4, SCL -> PORTC.3
' - LCD: Connected in 4-bit mode to PORTB
' Define LCD
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
' I2C Pin Assignments
SDA VAR PORTC.4
SCL VAR PORTC.3
' Time Variables
second VAR BYTE
minute VAR BYTE
hour VAR BYTE
' DS3231 I2C Address
RTC_ADDR CON $D0 ' 7-bit address shifted left
' Convert BCD to Decimal
FUNC_BCD2DEC:
ASM
MOVF second, W
ANDLW 0x0F
MOVWF _temp1
SWAPF second, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF second
ADDWF _temp1, F
MOVF minute, W
ANDLW 0x0F
MOVWF _temp1
SWAPF minute, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF minute
ADDWF _temp1, F
MOVF hour, W
ANDLW 0x0F
MOVWF _temp1
SWAPF hour, W
ANDLW 0x0F
MOVWF _temp2
MOVF _temp2, W
MOVWF hour
ADDWF _temp1, F
ENDASM
RETURN
' Read Time from DS3231
Read_Time:
I2CWRITE SDA, SCL, RTC_ADDR, 0, [0] ' Set register pointer to 0
I2CREAD SDA, SCL, RTC_ADDR, [second, minute, hour] ' Read time
GOSUB FUNC_BCD2DEC ' Convert BCD to decimal
RETURN
' Initialize LCD
PAUSE 500
LCDOUT $FE, 1 ' Clear LCD
LCDOUT $FE, $80, "Time: "
' Main Loop
Main:
GOSUB Read_Time ' Read DS3231 time
LCDOUT $FE, $C0, DEC2 hour, ":", DEC2 minute, ":", DEC2 second ' Display time
PAUSE 1000 ' Wait 1 second
GOTO Main
;
Code:
' PICBASIC PRO code to read time from DS3231 and display on HD44780 LCD
' Define PIC microcontroller (e.g., PIC16F877A)
#CONFIG
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
#ENDCONFIG
' Define LCD pins
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' Starting data bit (D4)
DEFINE LCD_RSREG PORTE ' RS pin port
DEFINE LCD_RSBIT 0 ' RS pin bit
DEFINE LCD_EREG PORTE ' Enable pin port
DEFINE LCD_EBIT 1 ' Enable pin bit
' Define I2C pins
DEFINE I2C_SCL PORTB, 1 ' SCL pin (RB1)
DEFINE I2C_SDA PORTB, 2 ' SDA pin (RB2)
' Include necessary libraries
INCLUDE "DS3231.bas" ' DS3231 I2C RTC library
INCLUDE "LCD.bas" ' HD44780 LCD library
' Variables
Dim second As Byte
Dim minute As Byte
Dim hour As Byte
Dim day As Byte
Dim month As Byte
Dim year As Byte
' Initialize LCD
LCDOUT $FE, $01 ' Clear LCD
LCDOUT $FE, $0C ' Turn on display, no cursor
' Main loop
Main:
' Read time from DS3231
DS3231_ReadTime hour, minute, second
' Display time on LCD
LCDOUT $FE, $80, "Time: ", DEC2 hour, ":", DEC2 minute, ":", DEC2 second
' Wait for 1 second
PAUSE 1000
' Repeat
GOTO Main
Bookmarks