Menu

table of binary numbers

2019-11-24
2019-11-25
  • David Stephenson

    I'm getting a problem with reading a table such as the following:

    table1
    0b00001111, 0b11111111, 0b11111111, 0b11111111, 0b11111110, 0b00000000 ' ####
    0b11100000, 0b11111111, 0b11111111, 0b11111111, 0b11111110, 0b00000000 ' #### 
    end table
    table2
    b'00111111', 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b11111000 'comment
    b'00011111', 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b01111000 'comment
    end table
    

    when reading the 12 values in table1 number 1 and 7 are read as zero.
    Using the b'xxxxxxxx' notation in table2 the numbers read correctly.
    There is no problem with any of the other numbers

     
  • Anobium

    Anobium - 2019-11-25

    Interesting.

    Can you tie this download a little more please.
    Compiler version?
    Got code that compiles? So, I can look at the ASM.
    Is this chipset specific?

     
  • David Stephenson

    version 98.04 (I've not updated recently!).
    All the numbers in the test table should be 255, but the middle two lines give the first value as 0.

    #chip 16F18326,1
    #config RSTOSC=hfint1, MCLRE=Off, WDTE=off, boren=off, FEXTOSC_OFF, CLKOUTEN_OFF, CP_OFF, WRT_OFF
    
    for i=1 to 24
    readtable test1,i,q1
    next i
    table test1
    b'11111111', 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111
    0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111
    0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111
    b'11111111', 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111
    end table
    
    ;Program compiled by Great Cow BASIC (0.98.04 2018-10-20 (Windows 32 bit))
    
    
    ;Set up the assembler options (Chip type, clock source, other bits and pieces)
     LIST p=16F18326, r=DEC
    #include <P16F18326.inc>
     __CONFIG _CONFIG1, _CLKOUTEN_OFF & _RSTOSC_HFINT1 & _FEXTOSC_OFF
     __CONFIG _CONFIG2, _BOREN_OFF & _WDTE_OFF & _MCLRE_OFF
     __CONFIG _CONFIG3, _LVP_OFF & _WRT_OFF
     __CONFIG _CONFIG4, _CP_OFF
    
    ;********************************************************************************
    
    ;Set aside memory locations for variables
    I   EQU 32
    Q1  EQU 33
    SYSSTRINGA  EQU 119
    _HEF_DUMMY  EQU 34
    
    ;********************************************************************************
    
    ;Vectors
        ORG 0
        pagesel BASPROGRAMSTART
        goto    BASPROGRAMSTART
        ORG 4
        retfie
    
    ;********************************************************************************
    
    ;Start of program memory page 0
        ORG 5
    BASPROGRAMSTART
    ;Call initialisation routines
        call    INITSYS
    
    ;Start of the main program
    ;for i=1 to 24
        clrf    I
    SysForLoop1
        incf    I,F
    ;readtable test1,i,q1
        movf    I,W
        movwf   SYSSTRINGA
        call    TEST1
        movwf   Q1
    ;next i
        movlw   24
        subwf   I,W
        btfss   STATUS, C
        goto    SysForLoop1
    ENDIF1
    SysForLoopEnd1
    BASPROGRAMEND
        sleep
        goto    BASPROGRAMEND
    
    ;********************************************************************************
    
    INITSYS
    ;Set up internal oscillator
    ;Handle OSCCON1 register for parts that have this register
    ;asm showdebug OSCCON type is 100 'This is the routine to support OSCCON1 config addresss
    ;osccon type is 100
    ;OSCCON1 = 0x60 ' NOSC HFINTOSC; NDIV 1 - Common as this simply sets the HFINTOSC
        movlw   96
        banksel OSCCON1
        movwf   OSCCON1
    ;OSCCON3 = 0x00 ' CSWHOLD may proceed; SOSCPWR Low power
        clrf    OSCCON3
    ;OSCEN = 0x00   ' MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled
        clrf    OSCEN
    ;OSCTUNE = 0x00 ' HFTUN 0
        clrf    OSCTUNE
    ;asm showdebug OSCCON type is 102 'therefore not CHIPFamily 16
    ;osccon type is 102
    ;OSCFRQ = 0b00000000
        clrf    OSCFRQ
    ;Ensure all ports are set for digital I/O and, turn off A/D
    ;SET ADFM OFF
        banksel ADCON1
        bcf ADCON1,ADFM
    ;Switch off A/D Var(ADCON0)
    ;SET ADCON0.ADON OFF
        bcf ADCON0,ADON
    ;Commence clearing any ANSEL variants in the part
    ;ANSELA = 0
        banksel ANSELA
        clrf    ANSELA
    ;ANSELC = 0
        clrf    ANSELC
    ;End clearing any ANSEL variants in the part
    ;Comparator register bits for 12F510,16F506, PIC16F1535 classes
    ;C2ON = 0
        banksel CM2CON0
        bcf CM2CON0,C2ON
    ;C1ON = 0
        bcf CM1CON0,C1ON
    ;Turn off all ports
    ;PORTA = 0
        banksel PORTA
        clrf    PORTA
    ;PORTC = 0
        clrf    PORTC
        return
    
    ;********************************************************************************
    
    TEST1
        movlw   25
        subwf   SysStringA, W
        btfsc   STATUS, C
        retlw   0
        movf    SysStringA, W
        addlw   low TableTEST1
        movwf   SysStringA
        movlw   (high TableTEST1) & 127
        btfsc   STATUS, C
        addlw   1
        movwf   PCLATH
        movf    SysStringA, W
        movwf   PCL
    TableTEST1
        retlw   24
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   0
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   0
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
    
    ;********************************************************************************
    
    ;Start of program memory page 1
        ORG 2048
    ;Start of program memory page 2
        ORG 4096
    ;Start of program memory page 3
        ORG 6144
    ;Start of program memory page 4
        ORG 8192
    ;Start of program memory page 5
        ORG 10240
    ;Start of program memory page 6
        ORG 12288
    ;Start of program memory page 7
        ORG 14336
    
     END
    
     
  • Anobium

    Anobium - 2019-11-25

    Can you test with the latest version please? That is the baseline I would have to investigate against.

     
  • David Stephenson

    It's always very worrying to install a new version, but I've done it and it works (though when opening the IDE I've found it best to ignore the configuration change as it can throw off the programmer configurations).
    Anyway it gives much the same when compiled to ASM

    ;Program compiled by Great Cow BASIC (0.98.06 2019-06-12 (Windows 32 bit))
    ;Need help? See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
    ;check the documentation or email w_cholmondeley at users dot sourceforge dot net.
    
    ;********************************************************************************
    
    ;Set up the assembler options (Chip type, clock source, other bits and pieces)
     LIST p=16F18326, r=DEC
    #include <P16F18326.inc>
     __CONFIG _CONFIG1, _CLKOUTEN_OFF & _RSTOSC_HFINT1 & _FEXTOSC_OFF
     __CONFIG _CONFIG2, _BOREN_OFF & _WDTE_OFF & _MCLRE_OFF
     __CONFIG _CONFIG3, _LVP_OFF & _WRT_OFF
     __CONFIG _CONFIG4, _CP_OFF
    
    ;********************************************************************************
    
    ;Set aside memory locations for variables
    I   EQU 32
    Q1  EQU 33
    SYSSTRINGA  EQU 119
    
    ;********************************************************************************
    
    ;Vectors
        ORG 0
        pagesel BASPROGRAMSTART
        goto    BASPROGRAMSTART
        ORG 4
        retfie
    
    ;********************************************************************************
    
    ;Start of program memory page 0
        ORG 5
    BASPROGRAMSTART
    ;Call initialisation routines
        call    INITSYS
    
    ;Start of the main program
    ;for i=1 to 24
        clrf    I
    SysForLoop1
        incf    I,F
    ;readtable test1,i,q1
        movf    I,W
        movwf   SYSSTRINGA
        call    TEST1
        movwf   Q1
    ;next i
        movlw   24
        subwf   I,W
        btfss   STATUS, C
        goto    SysForLoop1
    SysForLoopEnd1
    BASPROGRAMEND
        sleep
        goto    BASPROGRAMEND
    
    ;********************************************************************************
    
    INITSYS
    ;Set up internal oscillator
    ;Handle OSCCON1 register for parts that have this register
    ;asm showdebug OSCCON type is 100 'This is the routine to support OSCCON1 config addresss
    ;osccon type is 100
    ;OSCCON1 = 0x60 ' NOSC HFINTOSC; NDIV 1 - Common as this simply sets the HFINTOSC
        movlw   96
        banksel OSCCON1
        movwf   OSCCON1
    ;OSCCON3 = 0x00 ' CSWHOLD may proceed; SOSCPWR Low power
        clrf    OSCCON3
    ;OSCEN = 0x00   ' MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled
        clrf    OSCEN
    ;OSCTUNE = 0x00 ' HFTUN 0
        clrf    OSCTUNE
    ;asm showdebug The MCU is a chip family ChipFamily
    ;the mcu is a chip family 15
    ;asm showdebug OSCCON type is 102
    ;osccon type is 102
    ;OSCFRQ = 0b00000000
        clrf    OSCFRQ
    ;Ensure all ports are set for digital I/O and, turn off A/D
    ;SET ADFM OFF
        banksel ADCON1
        bcf ADCON1,ADFM
    ;Switch off A/D Var(ADCON0)
    ;SET ADCON0.ADON OFF
        bcf ADCON0,ADON
    ;Commence clearing any ANSEL variants in the part
    ;ANSELA = 0
        banksel ANSELA
        clrf    ANSELA
    ;ANSELC = 0
        clrf    ANSELC
    ;End clearing any ANSEL variants in the part
    ;Set comparator register bits for many MCUs with register CM2CON0
    ;C2ON = 0
        banksel CM2CON0
        bcf CM2CON0,C2ON
    ;C1ON = 0
        bcf CM1CON0,C1ON
    ;Turn off all ports
    ;PORTA = 0
        banksel PORTA
        clrf    PORTA
    ;PORTC = 0
        clrf    PORTC
        return
    
    ;********************************************************************************
    
    TEST1
        movlw   25
        subwf   SysStringA, W
        btfsc   STATUS, C
        retlw   0
        movf    SysStringA, W
        addlw   low TableTEST1
        movwf   SysStringA
        movlw   (high TableTEST1) & 127
        btfsc   STATUS, C
        addlw   1
        movwf   PCLATH
        movf    SysStringA, W
        movwf   PCL
    TableTEST1
        retlw   24
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   0
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   0
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
        retlw   255
    
    ;********************************************************************************
    
    ;Start of program memory page 1
        ORG 2048
    ;Start of program memory page 2
        ORG 4096
    ;Start of program memory page 3
        ORG 6144
    ;Start of program memory page 4
        ORG 8192
    ;Start of program memory page 5
        ORG 10240
    ;Start of program memory page 6
        ORG 12288
    ;Start of program memory page 7
        ORG 14336
    
     END
    
     

Log in to post a comment.