hi all Help me out

hi everybody.. I am new in the Embedded programming .. i am writting the keyboard driver for microprocessor.. the status of UART tells me if any data (from keyboard) received or not from the flag register the flag register is of 32 bit ...

1) How can i check the pericular bit in this register set or not? 2) the receiver buffer is of 32 bit but data from keyboard comes in 8bit format.. How can i seperate the 8bit from 32 bit receiver buffer?

plz help me out...

Thanks

Reply to
rahul
Loading thread data ...

Good thing there is only one type of embedded processor. Wait there are 100's What CPU, what language?

Checking bits in usually done by masking. logical ANDs and ORs

Seperating byte C asm ? Shift and mask, pointers, arrays, unions.

Reply to
Neil

Can you see what the following code does?

...

unsigned int a = 0x10000B00; unsigned int mask = 0x00000001; unsigned char bit_check = 8;

if (a & (mask hi everybody..

--
----------------------------------------
 Himanshu Chauhan
 MCA (Final Year)
 I.G. National Open University
 Jaipur (India)

 Mobile:(+91)-(98292)-(92757)
 Web: http://members.lycos.co.uk/hschauhan
 Email: hs.chauhan@gmail.com

 "Education is what remains after one
  has forgotten everything he learned
  in school." -- A. Einstein.
----------------------------------------
Reply to
Himanshu Chauhan

well the processor is ARM 7 core based processor. i am using c for coding. well i want to connect the processor with the keyboard using the RS232 protocol. as the keyboard i am using is not a normal key board it is pocket keyboard CE-KB1 (usually used with Zaurus pocket (MI-110M)) after the receiving of data(i.e keycode) the flag bits in the UART get changed i used the "Shift and mask" technique as per your advice its working Thanks for ur help..

Tahnk you very much

Neil wrote:

Reply to
rahul

I normally use a bit mask such as if you want to look at bit 2 (0100b or 4h) then bitwise AND the flag register with the bit's number - i.e if (FlagRegister & 0x04) {. Since you are working with a UART remember that doing this on the data register counts as a read and will (normally) pop the value off the top of a FIFO, if you are using one.

Which microcontroller is this specifically - you mentioned it was ARM7? I think you'll probably find that only the lower eight bits of the 32bit word contain recieved data. If the UART is anything like the Sharp one I've worked with (and some others) then bits 8, 9, 10 and 11 will contain error flags too.

So, to (possibly) answer both your questions I would try something like:

unsigned char RxCharacter; unsigned int DataWord;

// Pointers to UART registers - likely to be different on your system. unsigned int *DataReg = 0xFFFC0000; //Pointer to data register. unsigned int *FlagRegister = 0xFFFC0018; // pointer to flag register

while ((*FlagRegister & 0x10)); // loop until bit 4 of the flag register gets cleared. // On my uart this means something has been received. Potentially infinite loops // are BAD though so find a better way - this is just an example.

DataWord = *DataReg; // Read the data register (may pop a FIFO)

if (DataWord & 0x0F00) { // check if any of the error bits are set - if the UART supports this return ERROR; // quit if they are } else { // otherwise store the data RxCharacter = (unsigned char)DataWord; // use a cast to strip off the top 24 bits. }

This will work on a Sharp 79524 ARM7 but your device may be similar.

Reply to
Tom Lucas

I am not understanding the source of your confusion. The above code fragment does exactly what it says - it checks to see if the n'th bit as specified in the bit_check variable (where the LSB would be labelled as bit 0) is set or clear.

Or are you been confused by the "(mask

Reply to
Simon Clubley

And I can't understand who didn't understand the code... The original author of this thread has understood the thing I wanted to say.

My sole purpose was to show a real code segment that uses ANDing and ORing for checking the bit status and I think I succeeded in that.

--Himanshu

Sim> >> Can you see what the following code does?

Reply to
Himanshu Chauhan

Sorry, I misunderstood your reason behind posting - I thought that _you_ were asking how the code fragment worked. :-)

Simon.

--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
If Google's motto is "don't be evil", then how did we get Google Groups 2 ?
Reply to
Simon Clubley

Ha! I was also confused to know why I am confused for the confusing code that I wrote to confuse others... PJ? I know...

--Himanshu

Sim> >> And I can't understand who didn't understand the code...

--
----------------------------------------
 Himanshu Chauhan
 MCA (Final Year)
 I.G. National Open University
 Jaipur (India)

 Mobile:(+91)-(98292)-(92757)
 Web: http://members.lycos.co.uk/hschauhan
 Email: hs.chauhan@gmail.com

 "Education is what remains after one
  has forgotten everything he learned
  in school." -- A. Einstein.
----------------------------------------
Reply to
Himanshu Chauhan

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.