Has anyone tried AI with PICBASIC


+ Reply to Thread
Results 1 to 40 of 104

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,122

    Default Re: Has anyone tried AI with PICBASIC

    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

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631

    Default Re: Has anyone tried AI with PICBASIC

    which one is which
    Warning I'm not a teacher

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115

    Default Re: Has anyone tried AI with PICBASIC

    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

  4. #4
    Join Date
    Feb 2013
    Posts
    1,122

    Default Re: Has anyone tried AI with PICBASIC

    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).

Similar Threads

  1. conversion from picbasic to picbasic pro
    By winjohan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2011, 18:00
  2. Proton PICBASIC vs MeLabs PICBASIC
    By Fredrick in forum General
    Replies: 22
    Last Post: - 11th January 2008, 21:51
  3. PICBasic Pro vs Proton PICBasic
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd November 2006, 16:11
  4. picbasic 2.46
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th April 2005, 03:34
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts