• AVR Freaks

Hot!Confused with XC8 errors.

Author
Ron Hayes
Super Member
  • Total Posts : 1324
  • Reward points : 0
  • Joined: 2003/11/07 12:38:10
  • Location: Ontario, Canada
  • Status: offline
2020/02/27 15:34:30 (permalink)
0

Confused with XC8 errors.

Hello,
 
I'm not much of a C guy but I'm trying to figure it out.
I have an LED matrix 8 elements wide 8x8 matrix.
 
I'm using a double long array [8] for the screen buffer and a char array [8] as a back buffer. I'm shifting bits out of the back buffer into the screen buffer to do scrolling and after each 8 bits are shifted from the back buffer another character is written to the back buffer. If this in not how you'd do this I like to hear that too.
 
but I'm getting these errors:
 
main.c:115: error: (209) type conflict
union Buffer / int
main.c:115: error: (209) type conflict
union Buffer / int
main.c:115: error: (182) illegal conversion between types
union Buffer -> long
main.c:115: error: (181) non-scalar types can't be converted to other types
main.c:117: warning: (373) implicit signed to unsigned conversion

 
from this code:
 
           
ScreenBuffer1[ScreenRow].Row = ScreenBuffer1[ScreenRow].Row >>1; //shift ScreenBuffer to oblivion
            
            if (BackBuffer[ScreenRow] & 0x0000000000000001){
                ScreenBuffer1[ScreenRow].Row = (ScreenBuffer1[ScreenRow] >>1) | 0x8000000000000000;
            }
            else BackBuffer[ScreenRow] = BackBuffer[ScreenRow] >>1;//shift carry into screen buffer
 

 
With the this line being line 115 - ScreenBuffer1[ScreenRow].Row = (ScreenBuffer1[ScreenRow] >>1) | 0x8000000000000000;
 
declarations:
union Buffer
{
   long long Row;
   char bytes[8];
};

union Buffer ScreenBuffer1[8];

char BackBuffer[8];

 
What am I doing wrong?

Ron
#1

16 Replies Related Threads

    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/27 15:48:31 (permalink)
    +1 (1)
    Was
    ScreenBuffer1[ScreenRow].Row = (ScreenBuffer1[ScreenRow] >>1) | 0x8000000000000000;
    meant to be
    ScreenBuffer1[ScreenRow].Row = (ScreenBuffer1[ScreenRow].Row >>1) | 0x8000000000000000;
     
    Probably more efficient to do
    ScreenBuffer1[ScreenRow].Row >>= 1;
    ScreenBuffer1[ScreenRow].bytes[7] |= 0x80;
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 18388
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/27 15:52:52 (permalink)
    +1 (1)
    Start with how many bits is long long int in your compiler?
    What compiler version and C90 or C99 mode?
    #3
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/27 15:54:51 (permalink)
    +2 (2)
    Also, if Backbuffer is a character array, then
    if (BackBuffer[ScreenRow] & 0x0000000000000001)
    is silly, it should just be
    if (BackBuffer[ScreenRow] & 0x01)
     
    Also, you really should make all these variables unsigned.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/27 15:59:24 (permalink)
    +2 (2)
    NKurzman
    Start with how many bits is long long int in your compiler?
    What compiler version and C90 or C99 mode?

    Good point.
    "long long" is only supported in C99 mode, and only on PIC18 or enhanced PIC16F.
    C90 mode just treats "long long" as "long". (You can have as many longs as you want, it's still just treated as one).
    Better to #include stdint.h and use "uint64_t" instead.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/27 16:07:34 (permalink)
    +1 (1)
    Assuming the variables are the correct size, change:
    if (BackBuffer[ScreenRow] & 0x0000000000000001){
        ScreenBuffer1[ScreenRow].Row = (ScreenBuffer1[ScreenRow] >>1) | 0x8000000000000000;
    }
    else BackBuffer[ScreenRow] = BackBuffer[ScreenRow] >>1;//shift carry into screen buffer

    to just
    ScreenBuffer1[ScreenRow].Row >>= 1;
    if (BackBuffer[ScreenRow] & 0x01)
        ScreenBuffer1[ScreenRow].Byte[7] |= 0x80;




    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    mlp
    boots too small
    • Total Posts : 880
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 11:14:55 (permalink)
    0
    Ron Hayes
    I'm using a double long array [8]

    No, you're not.
     
    union Buffer
    {
       long long Row;
       char bytes[8];
    };

     
    You're trying to use an array of long long (although as noted elsewhere that may not be occurring).
     
    The word "double" has special meaning in a C program, and unless you're using that meaning you'd best avoid the word.
     
    Also, if you're going to mention C-language things in the body of your text, you can change the Font Family to "Courier New" as I did in my second sentence, to make those things distinct from the non-C-language things around them.

    Mark (this opinion available for hire)
    #7
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 12:17:48 (permalink)
    0
    mark.pappin
    Ron Hayes
    I'm using a double long array [8]

    No, you're not.

    I know type long double is a valid C type, but is double long valid? ;)  I don't think so.
     
    #8
    Ron Hayes
    Super Member
    • Total Posts : 1324
    • Reward points : 0
    • Joined: 2003/11/07 12:38:10
    • Location: Ontario, Canada
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 16:05:16 (permalink)
    0
    I'm using 2.10 C99.
    From the Manual:
    The long long types are 64-bit C99 standard types when building for PIC18
    devices, but this implementation limits their size to only 32 bits for projects conforming
    to the C90 Standard or any project targeting any other device.

     
     
    #9
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 16:12:31 (permalink)
    +1 (1)
    That is correct.
    As you have still not mentioned which PIC device you are using, we don't know if you're actually getting 64 bit variables.
    (Note the text you quote is from the 2.05 manual. The 2.10 manual also mentions enhanced PIC16 devices.)
    Have you added the fix from my first post?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    Ron Hayes
    Super Member
    • Total Posts : 1324
    • Reward points : 0
    • Joined: 2003/11/07 12:38:10
    • Location: Ontario, Canada
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 16:17:23 (permalink)
    0
    ric
    That is correct.
    As you have still not mentioned which PIC device you are using, we don't know if you're actually getting 64 bit variables.
    (Note the text you quote is from the 2.05 manual. The 2.10 manual also mentions enhanced PIC16 devices.)
    Have you added the fix from my first post?
     


    Sorry, PIC is 18F4550.
     
    Yes I did apply your fix and the errors went away, can you explain why? I'm curious to learn what is it I did wrong. To me those statement were functionally the same.
     
    Ron
    #11
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/28 16:26:48 (permalink)
    +1 (1)
    Ron Hayes
    To me those statement were functionally the same.

    You left out the ".Row" field specifier, so you were pointing to the base of a union, not to a "long long" variable.
    I assume it was a typo, as you had done it correctly only three lines higher.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    Ron Hayes
    Super Member
    • Total Posts : 1324
    • Reward points : 0
    • Joined: 2003/11/07 12:38:10
    • Location: Ontario, Canada
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/29 23:24:10 (permalink)
    0
    ric
    You left out the ".Row" field specifier, so you were pointing to the base of a union, not to a "long long" variable.
    I assume it was a typo, as you had done it correctly only three lines higher.
     

    Yes! I didn't notice I did that.
     
    So after too many headaches I've given up on using c99 and I've switched back to c90 with multiple Longs.
    Not a huge deal I just thought it would be easier.
     
    Now I've noticed this code:
     
     
                ScreenBuffer1[ScreenRow].Row >>=1; //shift ScreenBuffer to oblivion
                
                if (BackBuffer[ScreenRow] & 0x01)
                {
                    ScreenBuffer1[ScreenRow].bytes[3] |= 0x80;
                    BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
                }
                else BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
                
            }
            LEDPos=0;

     
    isn't being fully compiled.
     
    ! ScreenBuffer1[ScreenRow].bytes[3] |= 0x80;
    0x7CFE: MOVF ScreenRow, W, ACCESS
    0x7D00: MULLW 0x4
    0x7D02: MOVLW 0x24
    0x7D04: ADDWF PROD, W, ACCESS
    0x7D06: MOVWF FSR2, ACCESS
    0x7D08: MOVLW 0x0
    0x7D0A: ADDWFC PRODH, W, ACCESS
    0x7D0C: MOVWF FSR2H, ACCESS
    0x7D0E: MOVLW 0x0
    0x7D10: BSF PLUSW2, 7, ACCESS
    ! BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
    0x7D12: MOVLW 0x41
    0x7D14: ADDWF ScreenRow, W, ACCESS
    0x7D16: MOVWF FSR2, ACCESS
    0x7D18: CLRF FSR2H, ACCESS
    0x7D1A: MOVLW 0x0
    0x7D1C: ADDWFC FSR2H, F, ACCESS
    0x7D1E: BCF STATUS, 0, ACCESS
    0x7D20: RRCF INDF2, F, ACCESS
    ! }
    ! else BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
    !
    ! }
    ! LEDPos=0;
    0x7D2A: MOVLW 0x0
    0x7D2C: MOVWF LEDPos, ACCESS

     
    else BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
    is being ignored, is this due to maybe the condition only every testing as true? Can't see why.
     
    Ron
    #13
    ric
    Super Member
    • Total Posts : 26057
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Confused with XC8 errors. 2020/02/29 23:45:08 (permalink)
    0
    You did not show enough disassembly to make any comment.

    What does it do when the
    if (BackBuffer[ScreenRow] & 0x01)
    test returns false?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11673
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Confused with XC8 errors. 2020/03/01 00:17:46 (permalink)
    +1 (1)
    Why are you looking at the assembly language, is something not working?  BackBuffer[ScreenRow] >>=1 is duplicated in a way that is a very obvious optimization for the compiler.
    #15
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Confused with XC8 errors. 2020/03/01 01:33:54 (permalink)
    +1 (1)
    Ron Hayes
    else BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
    is being ignored, is this due to maybe the condition only every testing as true? Can't see why.

    It is because this
        if (BackBuffer[ScreenRow] & 0x01)
        {
            ScreenBuffer1[ScreenRow].bytes[3] |= 0x80;
            BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer
        }
        else BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer

    has been optimized by the optimizer as this
        if (BackBuffer[ScreenRow] & 0x01)
        {
            ScreenBuffer1[ScreenRow].bytes[3] |= 0x80;
        }
        BackBuffer[ScreenRow] >>=1;//shift carry into screen buffer

    #16
    mlp
    boots too small
    • Total Posts : 880
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Confused with XC8 errors. 2020/03/01 21:33:58 (permalink)
    0
    1and0
    mark.pappin
    Ron Hayes
    I'm using a double long array [8]

    No, you're not.

    I know type long double is a valid C type, but is double long valid? ;)  I don't think so.

    If it's valid, OP's code is not using it.
    If it's not valid, OP's code is not using it.
     

    Mark (this opinion available for hire)
    #17
    Jump to:
    © 2020 APG vNext Commercial Version 4.5