Little problem with this code xc8

Thread Starter

be80be

Joined Jul 5, 2008
2,394
I been playing with this and cant figure out what the deal is
void NeoBit (int 1 Bit) for some reason the it saying it can't find bit .
The if bit shows a error.
Code:
void NeoBit (int 1 Bit)
{
   if (Bit == 1)
   { output_high (NeoPin); delay_cycles (6); output_low (NeoPin); } // delay_cycles (3); // Bit '1'  
   else
   { output_high (NeoPin); delay_cycles (3); output_low (NeoPin); } // delay_cycles (6); // Bit '0'  
}
 

Motanache

Joined Mar 2, 2015
652
Why (int 1 Bit) and not (int Bitt=1)?

I put Bitt as Bit to not be a specific word in C.
You have a listing in assembler ?

if bit shows a error because Bit is not initialized.
I do not think it's getting listed because it's seems a compiler problem here

please give me another example where you use the definition:
int 1;
because I am very curious.
 

Picbuster

Joined Dec 2, 2013
1,057
I been playing with this and cant figure out what the deal is
void NeoBit (int 1 Bit) for some reason the it saying it can't find bit .
The if bit shows a error.
Code:
void NeoBit (int 1 Bit)
{
   if (Bit == 1)
   { output_high (NeoPin); delay_cycles (6); output_low (NeoPin); } // delay_cycles (3); // Bit '1' 
   else
   { output_high (NeoPin); delay_cycles (3); output_low (NeoPin); } // delay_cycles (6); // Bit '0' 
}
Remove the 1 or place a underscore like
void NeoBit(int Bit)
Or
void NeoBit (int 1_Bit) or void Neobit(int 1Bit)

Picbuster
 

AlbertHall

Joined Jun 4, 2014
12,619
'bit' is a data type in XC8 (a one bit integer variable) so is best avoided as a variable name.
I don't understand 'int 1 Bit'. What is the '1' doing in there?
 

Thread Starter

be80be

Joined Jul 5, 2008
2,394
I'm trying to figure it out It's some code for fast leds I'll post the whole code.

The main C file
Code:
#include <NeoCol.h>
#include <stdlib.h>

unsigned int8 NeoGreen [NeoNum];
unsigned int8 NeoBlue [NeoNum];
unsigned int8 NeoRed [NeoNum];

void NeoBit (int1 Bit)
{
   if (Bit == 1)
   { output_high (NeoPin); delay_cycles (6); output_low (NeoPin); } // delay_cycles (3); // Bit '1'  
   else
   { output_high (NeoPin); delay_cycles (3); output_low (NeoPin); } // delay_cycles (6); // Bit '0'  
}
void NeoInit (void)
{
   unsigned int8 NeoPixel;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)  
   {
      if (NeoPixel < 10)
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 10) & (NeoPixel < 20))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 20) & (NeoPixel < 30))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 30) & (NeoPixel < 40))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 40) & (NeoPixel < 50))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 50) & (NeoPixel < NeoNum))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }     
   }
}
void NeoDraw (void)
{
   unsigned int8 NeoPixel;
   signed int8 BitCount;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
   {   
      for (BitCount = 7; BitCount >= 0; BitCount--)     
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));     
      for (BitCount = 7; BitCount >= 0; BitCount--)          
         NeoBit(bit_test(NeoRed[NeoPixel], BitCount));           
      for (BitCount = 7; BitCount >= 0; BitCount--)     
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));     
   }
   output_low (NeoPin);
}
void NeoRotate (void)
{
   unsigned int8 NeoPixel;  
   for (NeoPixel = 0; NeoPixel < NeoNum - 1; NeoPixel++)  
   {          
      NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1];
      NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1];
      NeoRed[NeoPixel] = NeoRed[NeoPixel + 1];
   }
   NeoGreen[NeoNum - 1] = NeoGreen[0];
   NeoBlue[NeoNum - 1] = NeoBlue[0];
   NeoRed[NeoNum - 1] = NeoRed[0];
}
void main()
{  
   NeoInit ();  
   while(true)
   {      
      NeoDraw ();
      NeoRotate ();
      delay_ms (25);
   }
}
This is the header file its not in it.
Code:
#include <18F4550.h>
#device ADC = 16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=48000000,crystal=20000000)

#define NeoPin PIN_E0
#define NeoNum 60
#define RAND_MAX 64
#define ALL_OUT 0x00
#define ALL_IN  0xFF
#byte PORTA = 0xF80
 

MrChips

Joined Oct 2, 2009
34,629
I don't do XC8.

I would assume int8 is a data type.
Is bit also a data type?
Is int1 also a data type?

Then try

void NeoBit ( int1 Bit )

or

void NeoBit ( bit Bit )
 

spinnaker

Joined Oct 29, 2009
7,830
Are you using the XC8 or CCS compiler?
I get a lot of errors trying to compile your code in XC8.

#fuses
#device
...

As well as #include <NeoCol.h>. I don't think this is XC8. Or perhaps it is some other compiler code trying to be compiled under XC8 and that is not going to work.
 

Thread Starter

be80be

Joined Jul 5, 2008
2,394
I download it from a site that was telling how the WS2812.
They said it was xc8 1.30 I installed that the problem is there something missing.
they was using int8 which from what I read is the same as uint8_t

I'm down to this
Code:
void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATB0 =1 (NeoPin); delay_cycles (6); LATB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1' 
   else
   { LATB0 =1 (NeoPin); delay_cycles (3); LATB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0' 
}
delay_cycles I don't no if that should point to a ASM code block.

Here what I have now.
Code:
#include "NeoCol.h"
#include <stdlib.h>
#include <xc.h>

unsigned uint8_t ,NeoGreen [NeoNum];
unsigned uint8_t, NeoBlue [NeoNum];
unsigned uint8_t ,NeoRed [NeoNum];

void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATB0 =1 (NeoPin); delay_cycles (6); LATB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1'  
   else
   { LATB0 =1 (NeoPin); delay_cycles (3);LATB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0'  
}
void NeoInit (void)
{
   unsigned uint8_t, NeoPixel;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)  
   {
      if (NeoPixel < 10)
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 10) & (NeoPixel < 20))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 20) & (NeoPixel < 30))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 30) & (NeoPixel < 40))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 40) & (NeoPixel < 50))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 50) & (NeoPixel < NeoNum))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }    
   }
}
void NeoDraw (void)
{
   unsigned uint8_t ,NeoPixel;
   signed uint8_t ,BitCount;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
   {  
      for (BitCount = 7; BitCount >= 0; BitCount--)    
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));    
      for (BitCount = 7; BitCount >= 0; BitCount--)          
         NeoBit(bit_test(NeoRed[NeoPixel], BitCount));          
      for (BitCount = 7; BitCount >= 0; BitCount--)    
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));    
   }
   output_low (NeoPin);
}
void NeoRotate (void)
{
   unsigned uint8_t NeoPixel;  
   for (NeoPixel = 0; NeoPixel < NeoNum - 1; NeoPixel++)  
   {          
      NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1];
      NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1];
      NeoRed[NeoPixel] = NeoRed[NeoPixel + 1];
   }
   NeoGreen[NeoNum - 1] = NeoGreen[0];
   NeoBlue[NeoNum - 1] = NeoBlue[0];
   NeoRed[NeoNum - 1] = NeoRed[0];
}
void main()
{  
   NeoInit ();  
   while(1)
   {      
      NeoDraw ();
      NeoRotate ();
      __delay_ms (25);
   }
}
header file needs to set ADC shuff and PORT I commented it out for now
this gets me to 2 errors
Code:
#include "NeoCol.h"
#include <stdlib.h>
#include <xc.h>

unsigned uint8_t ,NeoGreen [NeoNum];
unsigned uint8_t, NeoBlue [NeoNum];
unsigned uint8_t ,NeoRed [NeoNum];

void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATB0 =1 (NeoPin); delay_cycles (6); LATB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1'  
   else
   { LATB0 =1 (NeoPin); delay_cycles (3);LATB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0'  
}
void NeoInit (void)
{
   unsigned uint8_t, NeoPixel;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)  
   {
      if (NeoPixel < 10)
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 10) & (NeoPixel < 20))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 20) & (NeoPixel < 30))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 30) & (NeoPixel < 40))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 40) & (NeoPixel < 50))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 50) & (NeoPixel < NeoNum))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }     
   }
}
void NeoDraw (void)
{
   unsigned uint8_t ,NeoPixel;
   signed uint8_t ,BitCount;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
   {   
      for (BitCount = 7; BitCount >= 0; BitCount--)     
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));     
      for (BitCount = 7; BitCount >= 0; BitCount--)          
         NeoBit(bit_test(NeoRed[NeoPixel], BitCount));           
      for (BitCount = 7; BitCount >= 0; BitCount--)     
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));     
   }
   output_low (NeoPin);
}
void NeoRotate (void)
{
   unsigned uint8_t NeoPixel;  
   for (NeoPixel = 0; NeoPixel < NeoNum - 1; NeoPixel++)  
   {          
      NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1];
      NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1];
      NeoRed[NeoPixel] = NeoRed[NeoPixel + 1];
   }
   NeoGreen[NeoNum - 1] = NeoGreen[0];
   NeoBlue[NeoNum - 1] = NeoBlue[0];
   NeoRed[NeoNum - 1] = NeoRed[0];
}
void main()
{  
   NeoInit ();  
   while(1)
   {      
      NeoDraw ();
      NeoRotate ();
      __delay_ms (25);
   }
}
 

Thread Starter

be80be

Joined Jul 5, 2008
2,394
I don't no nothing about unsigned uint8_t ,NeoPixel;
How that should be.

delay_cycles I'm thinking asm delay needs to be made.

Code:
for (BitCount = 7; BitCount >= 0; BitCount--)   
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));
bit_test is missing too

Thank for the help.
 
Last edited:

AlbertHall

Joined Jun 4, 2014
12,619
You can use the built-in function '_delay(constant)' to delay for the specified number of instruction cycles. That is a single underscore at the start. Note that you cannot use a variable with this function.
 

spinnaker

Joined Oct 29, 2009
7,830
I don't no nothing about unsigned uint8_t ,NeoPixel;
How that should be.

delay_cycles I'm thinking asm delay needs to be made.

Code:
for (BitCount = 7; BitCount >= 0; BitCount--)  
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));
bit_test is missing too

Thank for the help.

You might need to write bit_test.

But you do know XC8 gives you some help with bits?

for example

Code:
if (LATCbits.LATC1)
{
    PORTbits.PORTB2 = 1;

}
This might not be 100% correct as it is from the top of my head but it is PORTBbits for sure (for example).

Almost all registers have the bits designation.

MPLab will help you with the completing the registers so if you type PORTBbits. (you need to type the period) , MPLab will popup all of the variables inside PORTBbits.

P.S. I have heard it said that you should not set TRIS bits using this method but I have never had an issue.
 

Thread Starter

be80be

Joined Jul 5, 2008
2,394
This is what I hate about xc8 it's so dang hard to figure port bit names out.
undefined identifier "LATB_LATB0"

This is where im at.

Code:
#include "NeoCol.h"
#include <stdlib.h>
#include <xc.h>

unsigned uint8_t ,NeoGreen [NeoNum];
unsigned uint8_t, NeoBlue [NeoNum];
unsigned uint8_t ,NeoRed [NeoNum];

void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATB_LATB0 =1 (NeoPin); _delay (6); LATB_LATB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1'
   else
   { LATB_LATB0 =1 (NeoPin); _delay (3);LATB_LATB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0'
}
void NeoInit (void)
{
   unsigned char NeoPixel;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
   {
      if (NeoPixel < 10)
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 10) & (NeoPixel < 20))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 20) & (NeoPixel < 30))
         { NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 30) & (NeoPixel < 40))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 0; }
      else if ((NeoPixel >= 40) & (NeoPixel < 50))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
      else if ((NeoPixel >= 50) & (NeoPixel < NeoNum))
         { NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }   
   }
}
void NeoDraw (void)
{
   unsigned char NeoPixel;
   signed char BitCount;
   for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
   { 
      for (BitCount = 7; BitCount >= 0; BitCount--)   
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));   
      for (BitCount = 7; BitCount >= 0; BitCount--)        
         NeoBit(bit_test(NeoRed[NeoPixel], BitCount));         
      for (BitCount = 7; BitCount >= 0; BitCount--)   
         NeoBit(bit_test(NeoBlue[NeoPixel], BitCount));   
   }
   LATB0 =0 (NeoPin);
}
void NeoRotate (void)
{
   unsigned uint8_t NeoPixel;
   for (NeoPixel = 0; NeoPixel < NeoNum - 1; NeoPixel++)
   {        
      NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1];
      NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1];
      NeoRed[NeoPixel] = NeoRed[NeoPixel + 1];
   }
   NeoGreen[NeoNum - 1] = NeoGreen[0];
   NeoBlue[NeoNum - 1] = NeoBlue[0];
   NeoRed[NeoNum - 1] = NeoRed[0];
}
void main()
{
   NeoInit ();
   while(1)
   {    
      NeoDraw ();
      NeoRotate ();
      __delay_ms (25);
   }
}
I just use unsigned char
@spinnaker Thanks I just found that too in the 500 plus pages of xc8 lol
 
Top