• PicŪ Basic


  • GRAY code

    I propose a little routine for encoding and decoding the Gray code. When I found the solution and I realized that most nice short code is not the fastest. You will find 2 types of routines in the library.
    The routine can manage up to 16 bits Binary and Gray code.

    Example of decode the Gray format.
    Code:
    GrayToBin_Sub:
        xBinaryNumber = 0                               ' BinaryNumber result, clear first.
        nXOR_result = 0                                 ' Temporary variable for Carry Bit.
        xNumberBits = 16                                ' Number GRAY bits to decode.
      
    GrayToBin_Loop:
        xGrayNumber = xGrayNumber << 1                  ' Shift 1 bit to the left to load the Carry.
        nXOR_result = nXOR_result ^ STATUS              ' XOR Carry with the previous bit of BinaryNumber output.
        xBinaryNumber = xBinaryNumber | nXOR_result.0   ' Load the Bit to the BinaryNumber.0 position.
        Dec xNumberBits                                 ' Look for the next bit.
        If xNumberBits > 0 Then
            xBinaryNumber = xBinaryNumber << 1          ' Shift 1 bit to the left to load the next Binary bit.
            GoTo GrayToBin_Loop                         ' Until all bits are done.
        EndIf
        Return
    GrayCode.zip
    Alberto
  • Recent Activity

    Henk57-24049

    Compiler 3.6.1.7 issue with 16F1829 and I2C-LCD

    Thread Starter: Henk57

    Spend this afternoon with a compiler issue; no error's, but my LCD give only first line with squares, no characters, nothing. If I flash an old .hex...

    Henk57 Yesterday, 15:18 Go to last post
    towlerg-21522

    CData Table

    Thread Starter: Beginner

    Is there perhaps the possibility to extend the IDE with a 'Raw Flash' command? Currently I have the huge problem that if I want to program a web page...

    towlerg Yesterday, 13:20 Go to last post