Little problem with this code xc8

Thread Starter

be80be

Joined Jul 5, 2008
2,395
@AlbertHall thanks

This one dang block of code.

Code:
void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATBbits.RB0 =1 (NeoPin); _delay (6); LATBbits.RB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1'
   else
   { LATBbits.RB0 =1 (NeoPin); _delay (3);LATBbits.RB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0'
}
It don't like LATBbits.RB0 =1
 

AlbertHall

Joined Jun 4, 2014
12,640
NeoPin is defined as PIN_E0 in the header file. If that means pin 0 of port E then you could define it as RE0 then you can use:
LATBbits.NeoPin = 1;
 

Thread Starter

be80be

Joined Jul 5, 2008
2,395
Code:
#define NeoPin RB0
#define NeoNum 4
#define RAND_MAX 8
#define ALL_OUT 0x00
#define ALL_IN  0xFF
//#byte PORTA = 0xF80
LATBbits.NeoPin =1 fixed that thanks
 

spinnaker

Joined Oct 29, 2009
7,830
@AlbertHall thanks

This one dang block of code.

Code:
void NeoBit (int  Bit)
{
   if (Bit == 1)
   { LATBbits.RB0 =1 (NeoPin); _delay (6); LATBbits.RB0 =0 (NeoPin); } // delay_cycles (3); // Bit '1'
   else
   { LATBbits.RB0 =1 (NeoPin); _delay (3);LATBbits.RB0 =0 (NeoPin); } // delay_cycles (6); // Bit '0'
}
It don't like LATBbits.RB0 =1

Are you sure your chip has an B0 latch? Mine does not.

Did you include xc8.h?

Did you make sure your project properties is pointing to your header file?
 

spinnaker

Joined Oct 29, 2009
7,830
As I said above if you type

LATBbits.

You should see your options popup. Microsoft calls this Intellisense. Not sure what it is called in mplabx (actually eclipse if I recall)
 

Thread Starter

be80be

Joined Jul 5, 2008
2,395
Are you sure your chip has an B0 latch? Mine does not.

Did you include xc8.h?

Did you make sure your project properties is pointing to your header file?
All of that is good
it's RB0 not BO

I'm down to one problem
Code:
for (BitCount = 7; BitCount >= 0; BitCount--)     
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));
I have no idea what bit_test should be or how that block works.
 

AlbertHall

Joined Jun 4, 2014
12,640
I'm down to one problem
Code:
for (BitCount = 7; BitCount >= 0; BitCount--)    
         NeoBit(bit_test(NeoGreen[NeoPixel], BitCount));
I have no idea what bit_test should be or how that block works.
As a wild guess bit_test is returning the value of bit number BitCount of the NeoPixel element of the NeoGreen array.
Perhaps like this:
NeoBit((NeoGreen[NeoPixel] >> BitCount) & 0x01)
 

Thread Starter

be80be

Joined Jul 5, 2008
2,395
This is where I'm 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)
   {
       LATBbits.NeoPin = 1
         _delay(6)
         LATBbits.NeoPin = 0
   } 
   else
   {
       LATBbits.NeoPin = 1
          _delay(3)
       LATBbits.NeoPin = 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;
   int bit_test =0;
   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));    
   }
   LATBbits.NeoPin =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);
   }
}
Code:
// PIC18F2550 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

// CONFIG1H
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting 2.05V)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = ON         // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTPS = 128      // Watchdog Timer Postscale Select bits (1:128)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <pic18f2550.h>
#include <xc.h>
#define _XTAL_FREQ  40000000

#define NeoPin RB0
#define NeoNum 4
#define ALL_OUT 0x00
#define ALL_IN  0xFF
 

Thread Starter

be80be

Joined Jul 5, 2008
2,395
If I don't fix it soon Im going to try to write the whole thing myself I just not that good with xc8
on a lot of of things lol.
 

nsaspook

Joined Aug 27, 2009
16,438
That will return 1, 2, 4, 8, etc not 0 or 1 which the calling function expects.
That's also the Boolean equivalent of true (>0 || !0)/false(0)
That code he working with is a mess, his calling function is testing a integer value instead of a true or false.
C:
if (Bit == 1) // integer compare
if (Bit)  // bool true/false test 'compare'
 

AlbertHall

Joined Jun 4, 2014
12,640
That's also the Boolean equivalent of true (>0 || !0)/false(0)
That code he working with is a mess, his calling function is testing a integer value instead of a true or false.
C:
if (Bit == 1) // integer compare
if (Bit)  // bool true/false test 'compare'
Yes, I know, but it's what we got.
 

Thread Starter

be80be

Joined Jul 5, 2008
2,395
So what do i need to do
void NeoBit (Bit) doesn't work

Ok xc8 don't like Bit but bit works fine
next problem is the if else statement.
Code:
void NeoBit (bit)
{
   if (bit == 1)
   {
       LATBbits.NeoPin = 1
         _delay(6)
         LATBbits.NeoPin = 0
   }  // Its saying i don't need this
   else
   {
       LATBbits.NeoPin = 1
          _delay(3)
       LATBbits.NeoPin = 0
   }  // Its saying i don't need this
}
It's saying there is something wrong
I commented where in code
 
Last edited:
Top