There are 5 messages in this thread.
You are currently looking at messages 0 to 5.
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
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;
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
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) {
>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