Menu

Issues with Hserprinting Arrays

Phil
2018-08-29
2018-09-15
1 2 > >> (Page 1 of 2)
  • Phil

    Phil - 2018-08-29

    Hi Guys, this is driving me mad. I'm trying to print an array to a Vt100 monitor (simulated at the mo), everything has been working great untill I wanted to print an array. It's almost as if the array has been nulled. See code.
    Any help sorting this out would be most appreciated..

          dim country(8) as String * 15
          dim test as string * 15
    
          test = "Test CHINA     "
          country(0) = "    CHINA     "
          country(1) = "   FRANCE     "
          country(2) = "    INDIA     "
          country(3) = "   PAKISTAN   "
          country(4) = "UNITED KINGDOM"
          country(5) = "UNITED STATES "
          country(6) = "   U.S.S.R.   "
    
          HSerPrintStringCRLF test ' This works
    
          HSerPrintStringCRLF country(0) ' This doesn't work
          HSerPrintStringCRLF country(1) ' This doesn't work
    

    There is sommit wierd going on.

    Thanks :)

     
  • bed

    bed - 2018-08-29

    As I am not sure, I looked into Help:

    Array
    A list of whole numbers ranging from 0 to 255

    Maybe you are not allowed to store Strings in Arrays ?

     
  • Theo

    Theo - 2018-08-29

    Hello Phil,

    try this line:
    Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6) as String * 15
    for your line:
    dim country(8) as String * 15

    You mix up two dim commands, the 8 in your command has to do with the size of the array but not with the number of strings (in this case with the name country)
    I understand that this is a littlebit weird because in other Basic languages the implementation of the Dim command is different.

     

    Last edit: Theo 2018-08-29
  • Theo

    Theo - 2018-08-29

    as addition:
    it is not allowed to use the number in your string as index in a loop or a for-next construction.

    This not allowed:
    For index = 0 to 6
    print country(index)
    next

    BUT this work:

    Select Case index
    Case 1
    print country(1)

    Case 2
      print country(2)
    

    Case Else
    print country(0)

    End Select
    

    Give it a try.

    Theo.

     
  • Phil

    Phil - 2018-08-29

    Hi Theo,
    Yup tried your suggestion but to no avail im afraid.
    Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6),country(7),country(8) as String * 15

          country(0) = "    CHINA     "
          country(1) = "   FRANCE     "
    

    etc
    HSerPrintStringCRLF country(0)
    etc

    still nothing

    I am using a pic18f47k42, would that make a difference..

     
  • Phil

    Phil - 2018-08-29

    Hi Theo,
    If i was to use the select case scenario then i might aswell use:

    select case num
        case 0
            Hserprintsreingcrlf "   CHINA   "
    

    and do it that way. and abandon the array altogether.

     
  • Theo

    Theo - 2018-08-29

    Of course, if you only need to print a string and no further calculations or so than go for it!

     
  • Anobium

    Anobium - 2018-08-29

    This looks like a casting issue where currently the passing of the string array as a parameter is not passing the string but the first byte value of the string array.

    So, use the 'select case' as a workaround.

     
  • Phil

    Phil - 2018-08-29

    Hi Theo,
    Well I think thats pretty poor of GCbasic where it can't handle string arrays. Even the Oshonsoft can do it quite seemlesly, but unfortunately it cant handle the pic chip in question.

     
    • Chris Roper

      Chris Roper - 2018-08-29

      Actually I would be surprised if Great Cow, or any other BASIC, supported String arrays on 8 BIT PIC's.

      If you look at the architecture used in the PIC Core there is very little address space allocated to RAM and that available RAM is segmented.

      The example code you posted would require 144 Bytes of RAM just to store the array data, I don't think many 8 Bit PIC's have that much contiguous RAM, in fact not many PICs even have that much RAM in total.

      Then you have all the working storage needed by the compiler and any other functions you use, such as the serial communications, and you begin to see the problem.

      PIC's are fantastic devices for interfacing with hardware and the real world environment. They have a vast array of device independent peripherals available, but they are NOT Computers based on Von Neumann Architecture, they are Interface Controllers based on Harvard Architecture.

      As Such they are not intended to manipulate RAM hungry applications like Strings and Floating Point Mathematics.

      If Strings are Important to you I would suggest that you use an ATMEL device based on the 8051 core rather than a PIC. But if you want to design and build Controller hardware then the PIC is first choice.

      Just My 2c,
      Cheers,

      Chris

       

      Last edit: Chris Roper 2018-08-29
  • Anobium

    Anobium - 2018-08-29

    @Phil. Great Cow BASIC does support string arrays. I think, as I have not confirmed, you have discovered an issue. I will investigate and resolve.

     
  • Phil

    Phil - 2018-08-29

    Thanks Anobium, trust me to find a bug.. I'm not even that a good a programmer.. LOL

     
  • Phil

    Phil - 2018-08-29

    @Cris, I see where you are coming from with pic chips having limited RAM, which is why I chose the 18F47K42 as it has 128K flash and 8K of RAM which is plenty for my purposes, oh and it runs at 64Mhz, which is quite nippy I think for most things.

     
  • Anobium

    Anobium - 2018-08-29

    I fall on my virtual sword. Handling of arrays of any type other than byte needs to be improved.

    Use the Select-Case or Tables to create solutions until we have improved.

     
  • Phil

    Phil - 2018-08-29

    Hi Anobium,
    I think its just select case, as looking as the table's help it says it does not handle strings or decimals.

     
    • Anobium

      Anobium - 2018-08-29

      Stick with the Select-Case. I have routines to automatically create string tables etc etc. I will post a demo when I get time... which I wont for a some time.

       
  • Theo

    Theo - 2018-08-29

    Hello Phil,

    studying your first question again I have the following question:
    because the command HSerPrintStringCRLF is relatively new, have you tried to use the old command HSerPrint instead?

    Do you get the same error(output) as before; if so than the problem is probebly caused by the string variable country(x).

     
  • Phil

    Phil - 2018-08-29

    Hi Theo,
    I have tried with HserPrint also and it did print zero's, but if you read a little further down, Anobium has found there to be bugs which stops string arrays. Which he is now investigating.
    Thanks for the suggestions though. :)

     
  • stan cartwright

    stan cartwright - 2018-08-29

    I tried the code on a 328 uno and get

     
  • Anobium

    Anobium - 2018-08-29

    @Guys. Please.....

    Handling of arrays of any type other than byte needs to be improved. It is not going to work.

    Use the Select-Case with the same strings to create solutions until we have improved the compiler.

     
  • stan cartwright

    stan cartwright - 2018-08-30

    In gcb arrays start as array(1) as 1st element , not 0.
    country(0) = " CHINA " try country(1) = " CHINA " and so on. Not the problem though.
    hserprint Len (country(1)) doesn't work either.
    gcb doesn't do multi dimentioned arrays .. which I suppose string arrays are,the chars are just numbers.
    Assuming plenty of ram and all countries same length, a string can be 255 chars,
    country(n) in the string would be mid(county,n*15+1,15)

     
  • Anobium

    Anobium - 2018-08-30

    Handling of arrays of this string type needs to be improved.

    Use the Select-Case with the same strings to create solutions until we have improved the compiler.

     
  • stan cartwright

    stan cartwright - 2018-08-30

    This works

    #chip mega328p,16
        #define USART_BAUD_RATE 9600
        #define USART_TX_BLOCKING
        #define USART_DELAY 10 ms
    
    dim country as String * 255
    dim var as byte
    country ="    CHINA     "+"   FRANCE     "+"    INDIA     "+"   PAKISTAN   "+"UNITED KINGDOM"+"UNITED STATES "+"   U.S.S.R.   "
    wait 5 s
    
    do
      for var=0 to 7
        HSerPrintStringCRLF mid(country,var*14+1,14)
      next
      HSerPrintCRLF
    loop
    
     
  • Anobium

    Anobium - 2018-08-31

    @Stan. Clever. :-)

     
  • stan cartwright

    stan cartwright - 2018-09-15

    The chip arrived and works. Uno to terminal version.

    #chip mega328p,16
    #option explicit
    
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.4
    #define hi2c_CLOCK PORTC.5
    hi2cMode Master
    
    Dim Si7021_HighByte, Si7021_LowByte as byte
    Dim SiRaw Alias Si7021_HighByte, Si7021_LowByte as Word
    
    Dim Humidity,Temperature,TemperatureC,TemperatureF as Word
    DIM Temperature as WORD
    
    Dim Hundredths as Byte
    
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define USART_DELAY 10 ms
    
    do
    Read_Humidity
    Read_Temperature
    loop
    
    Sub Read_Humidity
      Hi2CStart
      HI2cSend (0x80)  'Write
      Hi2cSend (0xF5)
      Hi2CReStart
      HI2CSend (0x81)  'read
      wait 50 ms   ' for conversion ( could be less)
      Hi2CReStart
    
      HI2CSend (0x81)  'read
      Hi2CReceive (Si7021_HighByte, ACK)
      Hi2CReceive (Si7021_Lowbyte, NACK)
      Hi2Cstop
      'now do the maths
      Humidity = (([long]SiRaw * 125) / 65536) -6
    
    ;  Locate 1,12
      If Humidity  < 10 then hserPrint "0"
      hserPrint "Humidity="+str(Humidity) : hserPrint "%"
      HSerPrintCRLF
    
    End Sub
    
    Sub Read_Temperature
      Hi2CStart
      HI2CSend (0x80)  'Write
      Hi2cSend (0xE0)
    
      Hi2CReStart
      HI2CSend (0x81)  'read
      Hi2CReceive (Si7021_HighByte, ACK)
      Hi2CReceive (Si7021_Lowbyte, NACK)
      Hi2Cstop
      wait 20 ms
    
      TemperatureC = (([long]SiRaw * 17572) / 65536) - 4685
      TemperatureF =   (([long]TemperatureC * 9) /5) + 3200
    
      Hundredths = TemperatureF % 100  'Modulud Divide
      TemperatureF = TemperatureF / 100
    
    ;  Locate 2,14
      hserPrint "Temp.="+str(TemperatureF) : hserPrint "." : hserPrint str(Hundredths)+" "
    
    End Sub
    
     
1 2 > >> (Page 1 of 2)

Log in to post a comment.