Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to define an array of binary 8 bit numbers in keil?

Status
Not open for further replies.

Tanmay_Karmakar

New Member
I've tried putting suffix 'y' followed by binary numbers within an array in header file but "syntax error near 'y', expected '}' " appear. Kindly ignore the first array of the attachment.
Code:
extern unsigned int A[8]={
00111100y,
01100110y,
01100110y,
01111110y,
01100110y,
01100110y,
01100110y};
 

Attachments

  • Untitled-2 copy_1.jpg
    Untitled-2 copy_1.jpg
    166.2 KB · Views: 663
Last edited:
The highlighted line in the attachment has an extra comma.

Mike.
BTW, code tags are [code] and [/code]
 
I just gave one in the description. Kindly look at the attachment carefully. You will see corresponding to which lines the errors are being generated.
 
Shouldn't variables declared as extern be define elsewhere, externally even.

Mike.
Btw, should you be using unsigned char for 8 bit numbers?
 
Yes, of course, it's a header file, it's not the main program. It's just for definition of some bit mapped array variables. And yes I've tried unsigned char data type also. If you have keil installed perhaps you can try and solve it with just one array in the header file and a main c program file to call it.
 
I don't have Keil installed but extern means it defined in another C file. Get rid of the extern and move it into the main C file and it should compile.

Mike.
 
Thank you all for taking your time.. but all the fixes you have mentioned are known to me and aren't the issues, works fine with decimal numbers. My concern is to write array of binary numbers like
Code:
 unsigned char A[]={ 01101100, 00110110}
. In keil binay specifier is 'y' as suffix and '0' as prefix is octal specifier. So if I write
Code:
 01101100y
there's a conflict for compiler whether the number is binary or octal. So I can't find other ways to specify binary numbers followed by zero. That's what I want a solution to...
 
From the a post on the Keil site:
ANSI C does not have any syntax for specifying binary integer literals. Decimal, octal, hex; no binary.

The Keil compiler is based on ANSI C, which has no way of accepting binary values.

Some compiler makers add their own non-standard ways but Keil have not.

You must use hex instead.
 
Use hex... All compilers use 0x00 format.. its the best binary shorthand...
unsigned char A[]={ 01101100, 00110110}
becomes
unsigned char A[]={ 0x6C, 0x36}... ie 0110 (6) and 1100 (C)... I rarely use binary I'm far more comfortable with hex...
 
After lots of google work.. uVision is based on the GNU complier.. Mike is indeed correct.. This is from the GNU manual
gnu said:
i = 42;
i = 0x2a;
i = 052;
i = 0b101010;

These are the same.
 
Use hex... All compilers use 0x00 format.. its the best binary shorthand...

becomes
unsigned char A[]={ 0x6C, 0x36}... ie 0110 (6) and 1100 (C)... I rarely use binary I'm far more comfortable with hex...
In my case using hex is better than using decimal but then again for my project I need binary map of 8by8 matrix. And I tried using '0b' prefix, didn't work.
 
In my case using hex is better than using decimal but then again for my project I need binary map of 8by8 matrix. And I tried using '0b' prefix, didn't work.

the 0 (zero) prefix is only an octal indicator if no suffix is present. If a Y suffix is present, it is binary.
Also, try with no leading zeros in your binary if it is not working with leading zero. If neither work, then you have some issue with other code.
 
Here's what I do...

unsigned char matrix[] = {
0xE9, // 11101001
0xA9, // 101010001
0x55, // 01010101
0x46, // 01000110
0x77 // 01110111
};

Thererin you can still see the map..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top