Because of Layout I had connected P1.0 to LCD.7, P1.1 to LCD.6 ... P1.7 to LCD.0! Now I have to convert the sending and incoming data. MSB has to become LSB. Is their a esay way to do this? Thanks a lot
Actually google can very useful in cases like this one: http://www.google.com/search?hl=en&ie=UTF-8&q=reverse+bits+byte&btnG=Google+Search Just one of the results: http://www.semiconductors.philips.com/acrobat/applicationnotes/AN709.pdf - mike
I would be tempted to try something like the following (I can't try it now because I am at a location without access to my Keil toolchain).
static unsigned char bdata src_byte; static unsigned char bdata dst_byte; static sbit src_bit0 = src_byte ^ 0; static sbit src_bit1 = src_byte ^ 1; static sbit src_bit2 = src_byte ^ 2; static sbit src_bit3 = src_byte ^ 3; static sbit src_bit4 = src_byte ^ 4; static sbit src_bit5 = src_byte ^ 5; static sbit src_bit6 = src_byte ^ 6; static sbit src_bit7 = src_byte ^ 7; static sbit dst_bit0 = dst_byte ^ 0; static sbit dst_bit1 = dst_byte ^ 1; static sbit dst_bit2 = dst_byte ^ 2; static sbit dst_bit3 = dst_byte ^ 3; static sbit dst_bit4 = dst_byte ^ 4; static sbit dst_bit5 = dst_byte ^ 5; static sbit dst_bit6 = dst_byte ^ 6; static sbit dst_bit7 = dst_byte ^ 7; unsigned char reverse_bits(unsigned char b) { src_byte = b; dst_bit0 = src_bit7; dst_bit1 = src_bit6; dst_bit2 = src_bit5; dst_bit3 = src_bit4; dst_bit4 = src_bit3; dst_bit5 = src_bit2; dst_bit6 = src_bit1; dst_bit7 = src_bit0; return dst_byte; }
MOV C,src_bit7 MOV dst_bit0,C ; ...
Thank you - the app note is very helpful
"...the app note..." Oops, sorry. I had taken your product selection of C51 to mean that you were targeting an 8051 and its instruction set, not an XA.
The bfastest, simplest, most elegant way is a lookup table unsigned char code{}={0, 0x08, 0x40.... Erik
I found a other simple way (17 Byte & 17 Cycle)
MOV C, ACC.1 ;1 76543210 RLC A ;7 65432101 MOV ACC.2, C ;7 65432701 MOV C, ACC.3 ;2 65432701 RLC A ;6 54327012 MOV ACC.4, C ;6 54367012 MOV C, ACC.5 ;3 54367012 RLC A ;5 43670123 MOV ACC.6, C ;5 45670123 SWAP A ;5 01234567
"I found a other simple way" Hey, no fair! You didn't say we could use assembly ;-)
Nobody said you couldn't...
Toolset = C51 Criterion = "esay" (easy, and the only criterion stated) Given all the posts asking about the SRC directive, assembly modules callable from C, C modules callable from assembly, etc., who would have though that: easy = assembly How silly of me!
Hmm... I suppose "easy" is somewhat subjective, really? l;-) "It takes a lot of effort to make something appear effortless"