Menu

Setting Up Arrays in GCBasic

Help
2006-09-14
2013-05-30
  • Nobody/Anonymous

    Having some problems compiling a simple array program. The errors encountered are:
      -Missing . in SET command! Command:SET SysArrayTemp1 1
      -Missing . in SET command! Command:SET SysArrayTemp1 0

    Fooled around a lot with different formats and couldn't come up with an answer.  Any ideas?

    Dim led(num)
    #define led(1) PORTC.2
    #define led(2) PORTC.1
    #define led(3) PORTC.0
    #define Blink 50 ms
    dir PortC Output

    Main:
    For num = 1 to 3
        set led(num) On
        wait Blink
        set led(num) Off
    Next
    goto Main

    Thanks,
    Kent   

     

     
    • Hugh Considine

      Hugh Considine - 2006-09-14

      That's not quite how arrays work in GCBASIC. An array is a variable that can hold multiple values simultaneously. These values are limited to whole numbers between 0 and 255.

      The Morse Code demo uses an array to store the list of keys that have been pressed - see http://gcbasic.sourceforge.net/examples.html

      To flash several LEDs in turn, you'll need to use individual commands to pulse each one seperately. There is a command that can turn a pin on for a specified period of time called PULSEOUT.

      This is how I would have gone about making a program similar to yours:

      #define led1 PORTC.2 
      #define led2 PORTC.1
      #define led3 PORTC.0
      #define Blink 50 ms
      dir PortC 0

      Main:
      PulseOut led1, Blink
      PulseOut led2, Blink
      PulseOut led3, Blink
      goto Main

      I've used a 0 in the dir command because it doesn't yet recognise output when setting the direction of the whole port. I'll fix this in the next version, which I'll release within the next 12 hours, barring any unforeseen circumstances.

      Thanks for asking about this - it's the only way I can find out what things are confusing and need more explanation in the documentation.

       
    • Nobody/Anonymous

      I was trying to pass a variable address to the array, but really doesn't seem like there is a way to define the variable as a byte, nibble, or bit in GCBASIC so it would recoqnize its value?  

      The interest in arrays is I will be looking to pull data out of a table of constants sometime down the line.  Or another way to do it would be retreiving data out of EEPROM from set locations.  Are two dimensional arrays out of the question?

      Took a quick look at the morse code demo, it will take a bit to sink in.  Thanks for the Pulseout tip.

      Will I2C, SPI, or 1-Wire buses be supported in the future?

      Regards,
      Kent 

       
    • Hugh Considine

      Hugh Considine - 2006-09-14

      In GCBASIC, all variables are defined automatically as bytes, unless DIM is used to set them to words (DIM VariableName AS Word). Nibbles and bits are not supported at present. 2D arrays are also not supported at present, unfortunately.

      For a table of constants, the best approach is to use a lookup table which stores the data in the EEPROM as you said. At the moment this can only be done using assembly, but I hope to add it to GCBASIC natively very soon.

      I2C and SPI are built in to the PIC chip, so shouldn't take too long to implement in GCBASIC. I've been meaning to put them in for a while now - maybe the time has come. 1-Wire bus mightn't make it into GCBASIC for a while, as it would have to be written entirely in software.

      What I will do is hold back the next release a few more days and add I2C, SPI, support for newer A/D converters (ones that use ANSEL) and lookup tables along with some recent bugfixes. They're all things that GCBASIC should have had ages ago!

       
    • Nobody/Anonymous

      I'm treading on very thin ice here, so keep that in mind with my questions.  My probes into GCBASIC capabilities are not meant as prods into action from the developers.  Of course, the more tools available, the better.  Keep up the good work!

      When you mention that I2C, SPI etc. should have been implemented a long time ago, was there a previous life for GCBASIC?

      One more question on software: are there software UART examples written in Basic that might work with GSBASIC?  If there were something like this, would it be used as some sort of header file?

      Regards
      Kent

       
    • Hugh Considine

      Hugh Considine - 2006-09-15

      There was no previous life for GCBASIC, but it's been in development now for around 10 months. By long ago, I meant at around the time when the EEPROM and A/D code was being written (which was back in April). Questions about what GCBASIC can do are good, because they give me an idea of which features are more worthwhile and thus should be added sooner.

      There are some software RS232 routines included in GCBASIC. See http://gcbasic.sourceforge.net/help/ and click on Command Reference > Serial Communications.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.