Has anyone tried AI with PICBASIC - Page 3


+ Reply to Thread
Page 3 of 3 FirstFirst 123
Results 81 to 104 of 104
  1. #81
    Join Date
    May 2013
    Location
    australia
    Posts
    2,570

    Default Re: Has anyone tried AI with PICBASIC

    I don't see any issues with IC address - it is done according to datasheet.

    1. Write to Config register:
    – First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
    – Second byte: 0b00000001 (points to Config register)
    – Third byte: 0b10000100 (MSB of the Config register to be written)
    – Fourth byte: 0b10000011 (LSB of the Config register to be written

    when has a 7 bit i2c slave address ever worked in pbp?
    Warning I'm not a teacher

  2. #82
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    Does manual say anywhere that it won't ?

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

    Default Re: Has anyone tried AI with PICBASIC

    When manual says byte sized variables, it is implied 8 bits I guess.

    Ioannis

  4. #84
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    So this IC can't be used with PBP ?

  5. #85
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    I cannot see how one can send only 7 bits when the integrated command is set to send 8 bits...

    I think you have to make your own routine, maybe in assembly.

    Ioannis

  6. #86
    Join Date
    May 2013
    Location
    australia
    Posts
    2,570

    Default Re: Has anyone tried AI with PICBASIC

    I think you have to make your own routine, maybe in assembly.
    or convert the 7 bit address to an 8 bit address as i have explained multiple times in other posts
    Warning I'm not a teacher

  7. #87
    Join Date
    May 2013
    Location
    australia
    Posts
    2,570

    Default Re: Has anyone tried AI with PICBASIC

    just spotted this gem on the arduino forum

    you need to know better than the AI in order to know that the solution offered by the AI is wrong
    Warning I'm not a teacher

  8. #88
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    It makes perfectly sense!

    One cannot blindly trust the machine. The replies depend very much on the prompt anyway. So, if you do not how to ask or what to ask, then you cannot expect magic to happen, right?

    Ioannis

  9. #89
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    I would say, that for relatively simple coding routines, PBP knowledge of AI had been improved, but just when you ask something more complex, you'll get this:

    can you create picbasic pro code which will draw a circle on a LCD screen, which uses ST7920 controller?

    (I'm omitting some DEFINE's and other non-relevant stuff)

    Code:
    ' Initialize LCDLCDINIT' Main program loopMain:    ' Clear display    LCDOUT $01    ' Set cursor to home    LCDOUT $02    ' Set display to graphics mode    LCDOUT $3F    ' Set start line to 0    LCDOUT $40    ' Set display start line    LCDOUT $C0    ' Draw circle    CIRCLE 64, 32, 20
    

  10. #90
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    It makes very human-like errors.

    For example, I asked it how to convert the time from GPS receiver, which simply outputs digits in ASCII format to raw decimal digits, and here's the code:

    Code:
    hours = (time_data[0] - "0") * 10 + (time_data[1] - "0")minutes = (time_data[2] - "0") * 10 + (time_data[3] - "0")
    It assumed that "0" is the raw value of ASCII digit "0" In ZX Spectrum Basic it would be VAL("0"), but in PBP there's not VAL...

    Interesting, is there any other syntax of basic, which treats "0" as it's decimal value in ASCII table?

  11. #91
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    Minus "0" means in fact -48.

    Maybe this is what is needed by the rest of the program. With just this line I am not sure if it is right or wrong.

    As always, answer depends on the prompt. If you give enough and precise info you will get better response.

    Ioannis

  12. #92
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    yes sure, I changed "0" to 48 and everything works fine.
    The question is, from where it took "0", is there any programming language that can make ASCII to decimal conversion that way?

  13. #93
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    In every language "0" is equal to 48 dec. or "1" equal to 49, etc.

    Ioannis

  14. #94
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,590

    Default Re: Has anyone tried AI with PICBASIC

    What do you mean you changed "0" to 48 and it worked? I'm sure it worked fine with "0".
    You must stop mixing up the interpreted ZX BASIC with PBP.

    In PBP lingo
    48
    $30
    %00110000
    "0"
    are all representing the exact same thing, just differently for human readability.
    If you were to connect to 8 LEDs to PortB of your PIC and then do PortB = x where x is any of the above they would all result in the exact same thing being displayed on the LEDs.

    So, in your specific example subtracting "0" will subtract the numeric value 48 from the numeric value of the ASCII code for the digit question. This will result a numeric value equal to that of 'the digit'.

  15. #95
    Join Date
    May 2013
    Location
    australia
    Posts
    2,570

    Default Re: Has anyone tried AI with PICBASIC

    The question is, from where it took "0", is there any programming language that can make ASCII to decimal conversion that way?
    nearly all can do that, except that in C,C++ etc it would be '0' not "0" [single quotes is a chr 'literal' double quote is a null terminated "string" c-str]
    Warning I'm not a teacher

  16. #96
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    I'm not mixing, but with PBP

    X-"0" gives syntax error while compiling.

  17. #97
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    I am pretty sure it does not. Compiles just fine because "0" is in fact 48. So if X-48 compiles it will also compile X-"0".

    If course to have correct results you should not mix 0 (zero) with O (capital letter O) because they have different ascii value. But all compile fine.

    Ioannis

  18. #98
    Join Date
    Mar 2005
    Location
    Cocoa, Florida
    Posts
    43

    Default Re: Has anyone tried AI with PICBASIC

    I've found CoPilot to be OK for .net, but useless for PBP.
    ChatGPT can be helpful, but only when used sparingly - "Write me an I2C routine to read a [chip number]".
    AI has improved over the last couple of years.

  19. #99
    Join Date
    Feb 2013
    Posts
    1,117

    Default Re: Has anyone tried AI with PICBASIC

    Yes, there are definitely some improvements with ChatGPT when it comes to PBP, but still a long way to go.
    Very often it has issues with syntax - it confuses PBP with Bascom or GC basic and uses operators from there.
    And when you ask it to check and correct, it says - "oh, you're right, this particular statement is not supported by PBP, let me modify a code for you".

    So while mostly being useless for PBP, at least it gives some direction, when I need to interface with some "fresh" hardware - syntax is usually wrong, and boundaries are not checked and code sequence is also messed, but registers/addresses usually are correct.

  20. #100
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    Default Re: Has anyone tried AI with PICBASIC

    DeepSeek is much better in creating programs.

    Not for a finished job of course, but helps to start.

    Ioannis

  21. #101
    Join Date
    Feb 2013
    Posts
    1,117

    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

  22. #102
    Join Date
    May 2013
    Location
    australia
    Posts
    2,570

    Default Re: Has anyone tried AI with PICBASIC

    which one is which
    Warning I'm not a teacher

  23. #103
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,065

    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

  24. #104
    Join Date
    Feb 2013
    Posts
    1,117

    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, 19:00
  2. Proton PICBASIC vs MeLabs PICBASIC
    By Fredrick in forum General
    Replies: 22
    Last Post: - 11th January 2008, 22:51
  3. PICBasic Pro vs Proton PICBasic
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd November 2006, 17:11
  4. picbasic 2.46
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th April 2005, 04:34
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 22: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