Menu

two simple questions

Help
2009-07-12
2013-05-30
  • alejandro1957

    alejandro1957 - 2009-07-12

    I am migrating the code from mikrobasic a gcbasic.
    two simple questions:
    1) as the keyword to use the mathematical function MOD?
    2) how states Lowbyte and Highbyte of a word?

    in mikrobasic declare  High (word) or Low (word).

     
    • kent_twt4

      kent_twt4 - 2009-07-12

      1.  Use the % for MOD

      Dec2HexString = test / 16
      convert2Hex
      Dec2HexString = test % 16 'Modulo or remainder
      convert2Hex

      2.  To use a word variable it must be declared, so use" dim LargeVar as Word ".

      If one wants to freely manipulate the high and low bytes of a word variable, look at this discussion:  https://sourceforge.net/forum/forum.php?thread_id=3077406&forum_id=579125

       
    • alejandro1957

      alejandro1957 - 2009-07-13

      thanks.
      but now when the code is fill out this error:
      Error: GCASM: Value out of range: Least significant bits used

      Part of this code is guilty:
      Escribe_Eeprom(0,(vNTC / 256),(vNTC % 256))  

      SUB Escribe_Eeprom(Address as word,wByte1 as byte,wByte2 as byte)
      DIM wAddress As Word Alias Highbyte,Lowbyte
      wAddress=Address
      Start
      TxI2C(160)                                                           
      TxI2C(Highbyte)                                                      
      TxI2C(Lowbyte)                                                        
      TxI2C(wByte1)                                                         
      TxI2C(Highbyte+1)                                                     
      TxI2C(Lowbyte+1)                                                      
      TxI2C(wByte2)                                                                                                                  
      Stop                                                                  
      WAIT 10 ms                                                      
      END SUB

       
    • Nobody/Anonymous

      Not 100% sure, and i don't know if this is the problem, but i think subroutines should be called this way (no brackets):

      Escribe_Eeprom 0, (vNTC / 256), (vNTC % 256)

       
    • Nobody/Anonymous

      is vNTC dim as word?  Here is sub that should send word data to the eeprom:

      sub Write16R16D(WriteID,Addr as word,I2Cdata as Word) #NR
        Start
        TxI2C(WriteID)  'Device ID write byte
        TxI2C(Addr_H)  'Send word address high byte
        TxI2C(Addr)  'Send word address low byte
        TxI2C(I2Cdata_H)  'Send out high data byte
        TxI2C(I2Cdata)  'Send out low data byte
        Stop
      end sub

      Kent

       
    • alejandro1957

      alejandro1957 - 2009-07-14

      I followed everything as I was told.
      Always the same result.
      thanks.

       
    • alejandro1957

      alejandro1957 - 2009-07-14

      this code now work

      Escribe_Eeprom EE_Cont_Bat,vBateria

      SUB Escribe_Eeprom(Address as word,Dato as word)

      DIM wAddress As Word Alias Address_H,Address_L

      DIM wDato As Word Alias Dato_H,Dato_L

      wAddress=Address

      wDato=Dato 

      Start

      TxI2C(160)                                                             'Envia el valor del comando de escritura

      TxI2C(Address_H)                                                       'Envia el valor alto de la EEPROM

      TxI2C(Address_L)                                                       'Envia el valor bajo de la EEPROM

      TxI2C(Dato_H)                                                          'Envia el valor alto de la lectura

      TxI2C(Address_H+1)                                                     'Envia el valor alto de la EEPROM

      TxI2C(Address_L+1)                                                     'Envia el valor bajo de la EEPROM 

      TxI2C(Dato_L)                                                          'Envia el valor bajo de la lectura                                                       

      Stop                                                                   'Termina la transmiciòn

      WAIT 10 ms                                                             'Espera para asegurar la escritura Eeprom

      END SUB

       
    • alejandro1957

      alejandro1957 - 2009-07-14

      thanks,Kent.
      If you for example to a transmission code manchester???

       
    • kent_twt4

      kent_twt4 - 2009-07-14
       
    • alejandro1957

      alejandro1957 - 2009-07-15

      thanks.
      we will work it.

       
  • Nobody/Anonymous

    Mod is the rermaider of a devide
    How big a number are you deviding
    and what are you placing the number into
    A word?
    often its very small number any way

    Lex

     

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.