Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Sponsor

controlSUITE™ software
Comprehensive.
Intuitive.
Optimized.

Real-world software for real-time control. Details Here!

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Comp.Arch.Embedded | Bitwise Operations

There are 5 messages in this thread.

You are currently looking at messages 0 to 5.

Bitwise Operations - drkidd22 - 2009-11-13 06:59:00

Hello All,

I have a question about a function I have made. LATA is 8-bits long and all
bits are set ok as in the code below, but what I want the code to do is
leave the previous bit set as well and not turn it off so that at the end
of the loop all bits are set.

[code]
void LED_test (void)
{

{
int i;
LATA = 0b00000001;
for (i = 0; i < 7; i++)
{
Delay_Us( Delay_750mS_Cnt );
LATA = LATA << 1;
}
}
[/code]

	   
					
---------------------------------------		
This message was sent using the comp.arch.embedded web interface on
http://www.EmbeddedRelated.com



Re: Bitwise Operations - Arlet - 2009-11-13 07:04:00

On Fri, 13 Nov 2009 05:59:28 -0600, drkidd22 wrote:

> I have a question about a function I have made. LATA is 8-bits long and all
> bits are set ok as in the code below, but what I want the code to do is
> leave the previous bit set as well and not turn it off so that at the end
> of the loop all bits are set.
> 
> [code]
> void LED_test (void)
> {
> 
> {
> int i;
> LATA = 0b00000001;
> for (i = 0; i < 7; i++)
> {
> Delay_Us( Delay_750mS_Cnt );
> LATA = LATA << 1;

LATA |= LATA << 1;



Re: Bitwise Operations - Mark Borgerson - 2009-11-13 10:13:00

In article <p...@ladybug.xs4all.nl>, usenet+6
@ladybug.xs4all.nl says...
> On Fri, 13 Nov 2009 05:59:28 -0600, drkidd22 wrote:
> 
> > I have a question about a function I have made. LATA is 8-bits long and all
> > bits are set ok as in the code below, but what I want the code to do is
> > leave the previous bit set as well and not turn it off so that at the end
> > of the loop all bits are set.
> > 
> > [code]
> > void LED_test (void)
> > {
> > 
> > {
> > int i;
> > LATA = 0b00000001;
> > for (i = 0; i < 7; i++)
> > {
> > Delay_Us( Delay_750mS_Cnt );
> > LATA = LATA << 1;
> 
> LATA |= LATA << 1;
> 
> 
> 
or perhaps:   LATA = (LATA << 1) + 1;

No difference in the end result, but it can all
be done in one register, whereas the |= version
takes another storage location.  That's probably not
a big issue in an LED test routine with a long
delay!  ;-)


Mark Borgerson

Re: Bitwise Operations - D Yuniskis - 2009-11-13 12:16:00

drkidd22 wrote:
> Hello All,
> 
> I have a question about a function I have made. LATA is 8-bits long and all
> bits are set ok as in the code below, but what I want the code to do is
> leave the previous bit set as well and not turn it off so that at the end
> of the loop all bits are set.
> 
> void LED_test (void)
> {
> 
> {
> int i;
> LATA = 0b00000001;
> for (i = 0; i < 7; i++)
> {
> Delay_Us( Delay_750mS_Cnt );
> LATA = LATA << 1;
> }
> }

void
LED_test( void )
{
     for (unsigned int LATA = 1; LATA += LATA + 1; LATA < 0x100) {
         /* presumably use LATA for something here... */
         Delay_Us( Delay_750mS_Cnt );
         /* ... or here? */
     }
}

Note that you could also run the algorithm backwards
(assuming that the other "something" you want to do is tolerant
of this change):

     for (unsigned int LATA = 0xFF; LATA = LATA >> 1; LATA > 0) {

Re: Bitwise Operations - drkidd22 - 2009-11-13 20:51:00

>drkidd22 wrote:
>> Hello All,
>> 
>> I have a question about a function I have made. LATA is 8-bits long and
all
>> bits are set ok as in the code below, but what I want the code to do is
>> leave the previous bit set as well and not turn it off so that at the
end
>> of the loop all bits are set.
>> 
>> void LED_test (void)
>> {
>> 
>> {
>> int i;
>> LATA = 0b00000001;
>> for (i = 0; i < 7; i++)
>> {
>> Delay_Us( Delay_750mS_Cnt );
>> LATA = LATA << 1;
>> }
>> }
>
>void
>LED_test( void )
>{
>     for (unsigned int LATA = 1; LATA += LATA + 1; LATA < 0x100) {
>         /* presumably use LATA for something here... */
>         Delay_Us( Delay_750mS_Cnt );
>         /* ... or here? */
>     }
>}
>
>Note that you could also run the algorithm backwards
>(assuming that the other "something" you want to do is tolerant
>of this change):
>
>     for (unsigned int LATA = 0xFF; LATA = LATA >> 1; LATA > 0) {
>

That works too. Now I have LEDs going back and forth, like a scanner.
Thanks guys.	   
					
---------------------------------------		
This message was sent using the comp.arch.embedded web interface on
http://www.EmbeddedRelated.com