-
Re: Has anyone tried AI with PICBASIC
Quote:
I don't see any issues with IC address - it is done according to datasheet.
Quote:
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?
-
Re: Has anyone tried AI with PICBASIC
Does manual say anywhere that it won't ?
-
Re: Has anyone tried AI with PICBASIC
When manual says byte sized variables, it is implied 8 bits I guess.
Ioannis
-
Re: Has anyone tried AI with PICBASIC
So this IC can't be used with PBP ?
-
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
-
Re: Has anyone tried AI with PICBASIC
Quote:
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
-
Re: Has anyone tried AI with PICBASIC
just spotted this gem on the arduino forum
Quote:
you need to know better than the AI in order to know that the solution offered by the AI is wrong
-
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
-
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
-
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?
-
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
-
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?
-
Re: Has anyone tried AI with PICBASIC
In every language "0" is equal to 48 dec. or "1" equal to 49, etc.
Ioannis
-
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'.
-
Re: Has anyone tried AI with PICBASIC
Quote:
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]
-
Re: Has anyone tried AI with PICBASIC
I'm not mixing, but with PBP
X-"0" gives syntax error while compiling.
-
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
-
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.
-
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.
-
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
-
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
-
Re: Has anyone tried AI with PICBASIC
-
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
-
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).