EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

hi all Help me out

Started by rahul June 20, 2006
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

rahul wrote:
> 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 >
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.
Can you see what the following code does?

...

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

if (a & (mask << bit_check))
   printf("%dth bit set.\n", bit_check);
else
   printf("%dth bit not set.\n", bit_check);

...

may be tweaking with this code make your understanding more clear...
compile with -S option with gcc, and you can look at the ASM code as
well... Logical AND and OR are generally used in such kind of operations.


--Himanshu

rahul wrote:
> 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 >
-- ---------------------------------------- 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. ----------------------------------------
 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:
> rahul wrote: > > 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 > > > > 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.
"rahul" <chaudhari.rahul.r@gmail.com> wrote in message 
news:1150855041.213774.24310@b68g2000cwa.googlegroups.com...
> 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?
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.
> 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?
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.
In article <e7apdh$3uj$1@nntp.aioe.org>, Himanshu Chauhan <hs.chauhan@gmail.com> writes:
> Can you see what the following code does? > > ... > > unsigned int a = 0x10000B00; > unsigned int mask = 0x00000001; > unsigned char bit_check = 8; > > if (a & (mask << bit_check)) > printf("%dth bit set.\n", bit_check); > else > printf("%dth bit not set.\n", bit_check); > > ... > > may be tweaking with this code make your understanding more clear... > compile with -S option with gcc, and you can look at the ASM code as > well... Logical AND and OR are generally used in such kind of operations. >
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 << bit_check)" perhaps ? All this does is to rotate the mask left by the specified number of bits, (which if it helps you to understand, is the same as a multiply by two for each position the mask is rotated left, ie: rotate left by 2 positions is the same as multiplying the mask value by 4). HTH, 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 ?
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


Simon Clubley wrote:
> In article <e7apdh$3uj$1@nntp.aioe.org>, Himanshu Chauhan <hs.chauhan@gmail.com> writes: >> Can you see what the following code does? >> >> ... >> >> unsigned int a = 0x10000B00; >> unsigned int mask = 0x00000001; >> unsigned char bit_check = 8; >> >> if (a & (mask << bit_check)) >> printf("%dth bit set.\n", bit_check); >> else >> printf("%dth bit not set.\n", bit_check); >> >> ... >> >> may be tweaking with this code make your understanding more clear... >> compile with -S option with gcc, and you can look at the ASM code as >> well... Logical AND and OR are generally used in such kind of operations. >> > > 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 << bit_check)" perhaps ? > > All this does is to rotate the mask left by the specified number of bits, > (which if it helps you to understand, is the same as a multiply by two > for each position the mask is rotated left, ie: rotate left by 2 positions > is the same as multiplying the mask value by 4). > > HTH, > > Simon. >
-- ---------------------------------------- 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. ----------------------------------------
In article <e7be8l$97k$1@nntp.aioe.org>, Himanshu Chauhan <hs.chauhan@gmail.com> writes:
> 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. >
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 ?
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


Simon Clubley wrote:
> In article <e7be8l$97k$1@nntp.aioe.org>, Himanshu Chauhan <hs.chauhan@gmail.com> writes: >> 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. >> > > Sorry, I misunderstood your reason behind posting - I thought that _you_ > were asking how the code fragment worked. :-) > > Simon. >
-- ---------------------------------------- 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. ----------------------------------------

The 2024 Embedded Online Conference