hi all, iam a new to embedded programming and keil software. i am struck with a problem how to access a bit in a data buffer. the algo i need to implement is data_buf of 32 bits is stored in the micro controller. i need to send those bits bit by bit. ie. starting from bit 0 to bit 31. can anybody pls suggest me how to write a program in keil. thanks in advance uday
"Undoubtedly, some timing requirements must be added..." Indeed, and/or some clock signalling requirements.
Hi ALL, You can make use of mask to send bitwise onto a port. Take a look at this: sending LSB to MSB temp = 0x01; for(i=0;i<8;i++) { if(temp == (temp & byteTObeSent)) { DATAPIN = 1; } else DATAPIN = 0; temp <<=1; } Think logically and code logically. Ravi
The earlier post has function code to send 1 byte. Now include a for loop for number of bytes and send each byte to this function. Cheers, Ravi
Yes, indeed it requires timing.
hi all, thanks for the overwhelming response that i received for my question. i have written the code for sending bit by bit data on a single pin of port 0 with reference to a clock. i thank one and all for the response cheers, Uday
Seems over-complicated to me: Why not just shift the 32-bit number, mask the LSB, and send it direct?
for( i=0; i<32; i++ ) { DATAPIN = wordToSend & 1; wordToSend >>= 1; }
HI, ofcourse that works for 32 bits and will occupy less instructions. I was considering a generic function which can send a byte. Depending on his size he may call this function accordingly. Cheers, Ravi
"I was considering a generic function which can send a byte." Even more reason to keep it simple:
for( i=0; i<8; i++ ) { DATAPIN = byteToSend & 1; byteToSend >>= 1; }