Binary data type in C?

Basically, I took an introductory java class, and managed to google my way through writing most of this code. I started writing this in C because I thought it'd be just a quick and small code... nope. I don't feel like starting over and reading up on avr machine language so I'll just keep going with it and hopefully learn a bit more about C.

The main problem in my code is I don't know how to approach datatypes. What i want is 8 bit global binary values (like registers in machine language) that I can just give a hex value to and manipulate with bit-wise operators. Yet I get stuff like "invalid digit '8' in octal constant". I don't even know how there's an octal constant in my code. Can someone look at my code and fix the current problem? At least get me different kinds of errors, they're all pretty much data type errors. Almost as important, please explain what you did and why that works where what I wrote doesn't.

Also I declared/made a variable called 'x' and then there's a 'for' loop in the code that has something like '(x = 0; x == #; x++)'. Would this take the global variable in and use it in the loop, or would the loop create it's own version of x?

MDB_QUARTER_OUT.ino (8.72 KB)

unsigned char CHANGER_RESET = 08;
unsigned char CHANGER_SETUP = 09;
unsigned char CHANGER_TUBE_STATUS = 0a;
unsigned char CHANGER_POLL = 0b;
unsigned char CHANGER_COIN_TYPE = 0c;
unsigned char CHANGER_DISPENSE = 0d;
unsigned char CHANGER_EXPANSION = 0f;

Hex constants are preceded by "0x", eg.

unsigned char CHANGER_RESET = 0x08;
unsigned char CHANGER_SETUP = 0x09;
unsigned char CHANGER_TUBE_STATUS = 0x0a;
unsigned char CHANGER_POLL = 0x0b;
unsigned char CHANGER_COIN_TYPE = 0x0c;
unsigned char CHANGER_DISPENSE = 0x0d;
unsigned char CHANGER_EXPANSION = 0x0f;

Ditto for further down. I'm not going to change them all, fix that up and get back to us.

Also, if they are constants (as these appear to be) put "const" in front of them:

const unsigned char CHANGER_RESET = 0x08;
const unsigned char CHANGER_SETUP = 0x09;
const unsigned char CHANGER_TUBE_STATUS = 0x0a;
const unsigned char CHANGER_POLL = 0x0b;
const unsigned char CHANGER_COIN_TYPE = 0x0c;
const unsigned char CHANGER_DISPENSE = 0x0d;
const unsigned char CHANGER_EXPANSION = 0x0f;

As far as I can see, Java uses the 0x1234 notation too, so I don't know why are you are writing those hex values without the "0x".

I mean, something like this:

unsigned char foo = ab;

Looks like you are assigning the variable "ab" to foo. Obviously you can't just use hex constants without some sort of prefix.

  DATA_POINTER++;                        //Align counter to checksum byte.

As a style thing (not required by the compiler) only constants should be in all capitals. Variables are in lower or mixed case.

I don't even know how there's an octal constant in my code.

In C, numbers starting with a zero are octal constants.

eg.

int a = 123;  // decimal 123
int b = 0123;  // OCTAL 123

Also I declared/made a variable called 'x' and then there's a 'for' loop in the code that has something like '(x = 0; x == #; x++)'. Would this take the global variable in and use it in the loop, or would the loop create it's own version of x?

If you don't declare your own one (which this tiny snippet doesn't) it would take the global one (or an "x" from the enclosing block. But the question is better posed in actual C code not stuff like "x == #" which wouldn't even compile.

eg.

for (int x = 0; x < 10; x++)  // uses the x in the for loop, which then ceases to exist
int x;
for (x = 0; x < 10; x++)  // uses the x declared before the for loop

I don't even know how there's an octal constant in my code.

Again, I'm surprised you are surprised, because Java has the same notation.

You are passing too many arguments to MDB_Transmit()

hifatpeople:
I get that, I meant the character '1' or 'a' is equivalent to hex '1' or 'a' because the char ascii value is '0001' or '1010'.

Wrong.