Has anyone tried AI with PICBASIC


+ Reply to Thread
Results 1 to 40 of 111

Hybrid View

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

    Default Re: Has anyone tried AI with PICBASIC

    I finally give it some try, but the code does not looks like a picbasic? It seems like it is using a different syntax to call subroutines? (can't verify right now, do not have PBP on this PC)


    Code:
    ' PICBASIC PRO code to read hours and minutes from DS3231 and send over serial port
    
    
    ' Define PIC16F877A configuration bits
    #CONFIG
        CONFIG FOSC = HS     ; High-speed oscillator
        CONFIG WDTE = OFF    ; Watchdog Timer disabled
        CONFIG PWRTE = ON    ; Power-up Timer enabled
        CONFIG BOREN = ON    ; Brown-out Reset enabled
        CONFIG LVP = OFF     ; Low-Voltage Programming disabled
        CONFIG CPD = OFF     ; Data memory code protection disabled
        CONFIG WRT = OFF     ; Flash Program Memory Write protection off
        CONFIG CP = OFF      ; Flash Program Memory Code protection off
    #ENDCONFIG
    
    
    ' Define constants
    DS3231_SDA   VAR PORTB.0  ; DS3231 Serial Data line
    DS3231_SCL   VAR PORTB.1  ; DS3231 Serial Clock line
    SERIAL_TX    VAR PORTD.1  ; Serial transmit pin
    
    
    ' Define variables
    Hours        VAR BYTE    ; Variable to store hours
    Minutes      VAR BYTE    ; Variable to store minutes
    
    
    ' Main program
    MAIN:
        TRISB.0 = 1         ; Set DS3231 SDA pin as input
        TRISB.1 = 1         ; Set DS3231 SCL pin as input
        TRISD.1 = 0         ; Set serial transmit pin as output
    
    
        ' Initialize I2C communication
        I2CSetup DS3231_SDA, DS3231_SCL, 100000
    
    
        ' Main loop
        DO
            ' Read hours from DS3231
            I2CStart
            I2CSend($D0)       ; DS3231 I2C address for writing
            I2CSend($00)       ; Send the register address for hours
            I2CStart
            I2CSend($D1)       ; DS3231 I2C address for reading
            Hours = I2CRead(1) ; Read hours and send acknowledgment
            I2CStop
    
    
            ' Read minutes from DS3231
            I2CStart
            I2CSend($D0)       ; DS3231 I2C address for writing
            I2CSend($01)       ; Send the register address for minutes
            I2CStart
            I2CSend($D1)       ; DS3231 I2C address for reading
            Minutes = I2CRead(0) ; Read minutes and send acknowledgment
            I2CStop
    
    
            ' Send hours and minutes over serial port
            SEROUT SERIAL_TX, T9600_16, ["Time: ", DEC Hours, ":", DEC2 Minutes, 13, 10]
    
    
            PAUSE 1000         ; Delay for some time before reading again
        LOOP
    
    
    ' Subroutine to initialize I2C communication
    I2CSetup:
        I2CWrite SDApin, SCLpin, I2C_HIGH   ; Set pins and speed
        RETURN

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134

    Default Re: Has anyone tried AI with PICBASIC

    AI did some progress on learning PICBasic compiler but has long way...

    It uses some kind of function call to subroutines but sure it is not valid.

    Ioannis

  3. #3
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    I checked, that is Great Cow Basic syntax

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

    Default Re: Has anyone tried AI with PICBASIC

    I told him that he's using GCbasic syntax instead of PBP, and asked to fix it.

    While he (she, it?) is no longer using GCBasic style subroutine calls, it now uses some C++ syntax

    Code:
    ' PICBASIC PRO code for reading voltage from ADS1115 via I2C
    
    
    ' Define I2C settings
    #IFNDEF __PCM
      DEFINE I2C_SDA_PORT = PIN_A0   ' Define SDA pin
      DEFINE I2C_SCL_PORT = PIN_A1   ' Define SCL pin
    #ENDIF
    DEFINE I2C_CLOCK 100000   ' Set I2C clock frequency to 100 kHz
    
    
    ' Define constants
    ADS1115_ADDRESS   CON   $48   ' I2C address of ADS1115 (A5 and A4 connected to GND)
    CONFIG_REG        CON   $01   ' Address of the configuration register
    CONVERSION_REG    CON   $00   ' Address of the conversion register
    
    
    ' Define variables
    Data_MSB          VAR   BYTE
    Data_LSB          VAR   BYTE
    ConversionResult  VAR   WORD
    Voltage           VAR   FLOAT
    
    
    ' Initialize I2C communication
    I2CWRITE ADS1115_ADDRESS, [CONFIG_REG, $C3, $83] ' Set configuration for continuous conversion mode
    
    
    ' Main loop
    DO
      ' Request a conversion
      I2CWRITE ADS1115_ADDRESS, [CONFIG_REG, $C3, $83] ' Start a new conversion
      
      ' Wait for conversion to complete
      PAUSE 50   ' Adjust the delay based on your requirements
      
      ' Read conversion result
      I2CREAD ADS1115_ADDRESS, [CONVERSION_REG], Data_MSB, Data_LSB
      ConversionResult = MAKEWORD(Data_MSB, Data_LSB)
    
    
      ' Process the result (assuming full-scale range is 4.096V)
      Voltage = ConversionResult * 4.096 / 32768.0
      
      ' Your code to use the Voltage value as needed
      
      ' Add a delay or perform other tasks as needed
      PAUSE 1000   ' Adjust the delay based on your requirements
    LOOP

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

    Default Re: Has anyone tried AI with PICBASIC

    Have tried many times to make it learn PBP syntax and seemed not willing to follow the manual of the compiler.

    I suppose it has its own preferences as to what links will follow and how it will learn new things. Users can interact but not purposely make it to learn from users links! And this makes sense, as we the users could make it to learn bad things, right?

    Ioannis

  6. #6
    Join Date
    Feb 2013
    Posts
    1,127

    Default Re: Has anyone tried AI with PICBASIC

    Well, at least, above code is more manageable, and only two areas need to be fixed - MAKEWORD and floating point math. I'll fix that code tomorrow, compile it and give a try on a real hardware

  7. #7

    Default Re: Has anyone tried AI with PICBASIC

    I would think that for now....... the AI can give a general computer algorithm to do a task but not exact syntax
    Last edited by amgen; - 1st January 2024 at 20:51.

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