Menu

Formula problem

2006-10-20
2013-05-30
  • Stefano Bonomi

    Stefano Bonomi - 2006-10-20

    I'm here again.

    I found a strange problem defining a mathematical formula.
    The statement is as follows:

    Keycount=((Rowcount-1)*4) + 1

    and here is the program:

    'A program to read 4x4 Keyboard
    'with only 4 I/O Pins
    'and 8 diodes
    ' http://http://www.piclist.com/techref/microchip/4x4key4io8diode.htm?key=4x4+keyboard&from=
    'for schematics
    'Chip model 
    #chip 16F690,4 
    #config _INTRC_OSC_NOCLKOUT, _WDT_OFF,_PWRTE_OFF,_MCLRE_OFF,_CP_OFF, _BOR_OFF, _IESO_OFF,_FCMEN_OFF 
    #Define LED1 PORTC.0
    #Define LED2 PORTC.1
    #Define LED3 PORTC.2
    #Define LED4 PORTC.3
    #Define Delay 1 s

    ANSEL=0
    '    Set RABPU bit OFF thus allowing individual weak pull up
    '    resistor to be set ON or OFF programmatically
    set OPTION_REG.7 OFF

    '    Main routine
        DIR PORTC b'00000000' 'PORTC as output
        PORTC = b'00000000'   'PORTC to 0
    '    PORTB Input
        PORTB = b'00000000'   'PORTB to 0
        DIR PORTB b'11111111' 'PORTB as input
        SET WPUB.4 ON
        SET WPUB.5 ON
        SET WPUB.6 ON
        SET WPUB.7 ON
        do
        Rowcount=0
            do while Rowcount < 4
            Rowcount=Rowcount+1
                Keytemp=0
                 ReadTable Rowmask, Rowcount, Rowprg
                Keycount=((Rowcount-1)*4)+1
                do while Keytemp < 4
                 Keytemp = keytemp+1
                  ReadTable Keymask, Keycount, Keyprg
                 DIR PORTB Rowprg
                 PORT_COPY = PORTB
                 PORT_COPY = PORT_COPY & Rowprg
                 ReadTable Ledmask, Keytemp, Ledout
                  IF PORT_COPY = Keyprg THEN
                   PORTC = Ledout
                               'Put Led connected on PORTC pins 1 to 4 ON to
                               'in order to point out first to
    'fourth Key pressed in a row
    '(only for test purpose)
                   WAIT Delay
                   PORTC = 0
                   WAIT Delay
                  END IF
                  Keycount = Keycount + 1
                LOOP
            LOOP
        LOOP
       
    ''''''''''''''''''''''''''''''''''''''''''
    '    Lookup Tables                        '
    ''''''''''''''''''''''''''''''''''''''''''
    Table Keymask
    b'00100000' 'SW1
    b'01000000'    'SW2
    b'01100000'    'SW3
    b'10000000'    'SW4
    b'00010000'    'SW5
    b'01010000'    'SW6'
    b'01000000'    'SW7'
    b'10010000'    'SW8'
    b'00110000'    'SW9'
    b'00010000'    'SW10'
    b'00100000'    'SW11'
    b'10010000'    'SW12'
    b'00110000'    'SW13'
    b'01010000'    'SW14'
    b'01100000'    'SW15'
    b'00010000'    'SW16'
    End Table
    Table Rowmask
    b'11100000'
    b'11010000'
    b'10110000'
    b'01110000'
    End Table
    Table Ledmask
    b'00000001'
    b'00000010'
    b'00000100'
    b'00001000'
    End Table

    Compiling, I get the following error:

    Far Heap corrupt
    >Terminated with exit code 255

    If I alter the formula writing:

    Keycount=(Rowcount-1)*4
    Keycount=Keycount+1

    No problems from compiler and the program works.

    I've also tried to reproduce the same error compiling a far simpler program that uses the same statement, but in this case all works.....

    Regards

     
    • Hugh Considine

      Hugh Considine - 2006-10-21

      I've got no idea what is causing that error! I can't compile the program either. The line:
      KeyCount = RowCount*4-3
      also compiles fine, and does exactly the same as the line that is causing trouble.

      I'll have a look at GCBASIC, and see if I can fix it. Thanks for posting.

       

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.