DeepSeek is much better in creating programs.
Not for a finished job of course, but helps to start.
Ioannis
DeepSeek is much better in creating programs.
Not for a finished job of course, but helps to start.
Ioannis
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
which one is which
Warning I'm not a teacher
It is important to know also the prompt given since it plays crucial role for the result.
On deepseek, and on my second attempt, I had to ask for the correct syntax regarding variables and config settings. So that time it got it correct while ChatGPD had really difficulties correcting the errors.
But asking for Tiananmen Square was a failure!
Ioannis
It does not matter, since none of code works.
Sometimes ChatGPT makes really funny moves - Once it created a new type of variable - "svar" which is not in PBP, I asked, what is this - so it replied, "Yes, this is a new type of variable, I've invented it for convience", "but such variable is not supported by picbasic pro?", "Yes I know, this is very sad, below is the code which works without svar variable" (and that code was not compiling anyways).
Here's a working code, written by ChatGPT, which allows to control playback of DY-SV17F and similar "DY" series mp3 modules. These modules provide far better audio quality, no noise and cracking, compared to more common, "Dfplayer" type of modules, and also, they have 4mb of onboard flash (and also MicroSD and USB flash support), which is quite handy, when you need to design an announcement or counter system.
This code took multiple iterations - it was not compiling initially because it used Proton Basic statements randomly. It was figured out. Code compiled, but not working. After reading the datasheet, I've figured out that it was not sending "source selection" statement. After pointing it to that, it took about 20 minutes to generate the code. It was still far from perfect, because "main" part was at the bottom, so module was confused. Now I've moved manually the "Main" code to the proper place and yay, it works!
The moral of story? - It coded a lot of code, which most likely I would never be able to write, considering my limited skills, but until I suggested what is wrong and needs to be fixed, it was struggling with the working code, despite making several attempts.
Code:' Use software UART on a chosen pin MP3_TX VAR PORTB.1 ' pick your PIC output pin BAUD9600 CON 84 ' 9600 baud, N,8,1 for SEROUT2 ' === Constants from DY-SV17F datasheet === USB CON $00 TF_CARD CON $01 FLASH CON $02 ' Command IDs CMD_PLAY CON $02 CMD_PAUSE CON $03 CMD_STOP CON $04 CMD_PREV CON $05 CMD_NEXT CON $06 CMD_PLAY_SPECIFIC CON $07 CMD_SWITCH_DEVICE CON $0B CMD_VOL_SET CON $13 ' === Variables === dyCmd VAR BYTE dyLen VAR BYTE dyBuf VAR BYTE[8] i VAR BYTE sumW VAR WORD crc VAR BYTE track VAR WORD hiB VAR BYTE loB VAR BYTE vol VAR BYTE ' --- Example main --- Main: PAUSE 500 GOSUB DY_SelectDeviceFlash ' set source = FLASH vol = 20 GOSUB DY_SetVolume track = 1 GOSUB DY_PlayTrack PAUSE 5000 GOSUB DY_Pause PAUSE 1500 GOSUB DY_Play PAUSE 3000 GOSUB DY_Stop END ' --- Low-level: send DY-SV17F packet (AA, cmd, len, data..., crc) --- DY_Send: sumW = 0 SEROUT2 MP3_TX, BAUD9600, [$AA] sumW = sumW + $AA SEROUT2 MP3_TX, BAUD9600, [dyCmd] sumW = sumW + dyCmd SEROUT2 MP3_TX, BAUD9600, [dyLen] sumW = sumW + dyLen IF dyLen > 0 THEN FOR i = 0 TO dyLen-1 SEROUT2 MP3_TX, BAUD9600, [dyBuf[i]] sumW = sumW + dyBuf[i] NEXT ENDIF crc = sumW & $FF SEROUT2 MP3_TX, BAUD9600, [crc] PAUSE 10 RETURN ' --- High-level helpers --- DY_SelectDeviceFlash: ' Switch to internal FLASH (02) dyCmd = CMD_SWITCH_DEVICE dyLen = 1 dyBuf[0] = FLASH GOSUB DY_Send PAUSE 150 ' module auto-plays first track after switch ' Stop playback immediately so only source is selected: dyCmd = CMD_STOP dyLen = 0 GOSUB DY_Send RETURN DY_Play: dyCmd = CMD_PLAY : dyLen = 0 GOSUB DY_Send RETURN DY_Pause: dyCmd = CMD_PAUSE : dyLen = 0 GOSUB DY_Send RETURN DY_Stop: dyCmd = CMD_STOP : dyLen = 0 GOSUB DY_Send RETURN DY_Next: dyCmd = CMD_NEXT : dyLen = 0 GOSUB DY_Send RETURN DY_Prev: dyCmd = CMD_PREV : dyLen = 0 GOSUB DY_Send RETURN DY_SetVolume: ' vol = 0..30 dyCmd = CMD_VOL_SET dyLen = 1 dyBuf[0] = vol GOSUB DY_Send RETURN DY_PlayTrack: ' track = 1..65535 hiB = track >> 8 loB = track & $FF dyCmd = CMD_PLAY_SPECIFIC dyLen = 2 dyBuf[0] = hiB dyBuf[1] = loB GOSUB DY_Send RETURN
Despite the progress of AI it is evident that will not replace soon a programmer.
And for the size of projects like the one you showed, probably it is worth the time to do it yourself and expand your experience than spend time in showing AI how to do it!
My 2c.
Ioannis
Last edited by Ioannis; - 24th August 2025 at 13:58.
Bookmarks