We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear all, I want to access some continus bit,let me can modify the value,such as, for(i = 0 ; i < 10 ; i++) { bit[i] = ?; } but you know,the bit var cann't build as a array in keil c51,but build some boolean var with byte will speed down the MCU and more code,Who can give me a good advice and a way,Thanks in advance.
Paddy, your idea is fine, in principle, but unfortunately doesn't correspond to the reality of the 8051 processor family. You seem to be assuming that Keil wilfully withheld a useful feature of the CPU from being used by your C code. But they didn't --- it at all, it's IBM who did that, back when they designed the original 8051. There simply is no opcode in the 8051 machine language to indirectly access a bit, i.e. you can't compute the address of any bit and use the result of that computation to access it. This almost completely rules out array-of-bit as a C datatype. It still could be done, but only by use of methods that are practically guranteed to be even less efficient than the shift+mask technique which you so much would like to avoid. E.g. you could use self-modifying code, or a jump table to select one of a lot of hardwired "read bit #i" functions.
"IBM ... designed the original 8051" Eh??????????????????????????????????????????
OK, alright, so you caught me. 'Twas Intel, not IBM, of course.
What has been said about Keil C51 and the 8051 processor in other posts above is correct. Keil have, quite rightly, tried to stick as closely as possible to the C ANSI standard, but have provided just a few extra features to allow C programmers access to operations that the 8051 does particularly well – e.g. by adding the bit storage type. While weak in other areas, the one thing that the 8051 does do well is bit twiddling. So it is a pity that Keil did not take their extensions a little bit further and allow the implementation of an array of bits. While it is always possible to write your own code to access an array of bits with a fixed or variable index, the compiler will always be in a position to handle it better than hand-crafted code. The key difference is that with C source code accessing an individual bit the result is likely to be treated like a Boolean: occupying a whole byte and having either a zero or non-zero value. Consequently, the object code does not make as great a use of bit manipulation opcodes as one might hope. Something similar happens when declaring a structure that has fields defined as being one bit in size. It is very useful to define a word as a structure with some fields just one bit wide – do describe an I/O port for example. But, the compiler does not handle this situation efficiently. I assume nothing has changed since this thread (see end): http://www.keil.com/forum/docs/thread1291.asp Or this (see end): http://www.keil.com/forum/docs/thread1530.asp
Thansk all friend very much,Now I see,Though the bitaddress var is a good way to save the code area and speed up the MCU perfomance,but because the 8051's limit,The bitaddress var have no index register like the byteaddress var,So the pointer cann't assign to bit address var,and struct and union is also,the byte transfer is the only select,and I had test,Keil had trans the byte mode only 2 instruction (0) or 3instruction(1). Last word,Sorry my poor english.