C Question in AVR GCC and codevision
2007-06-17 by kernels_nz
Hi guys,
I played with AVR GCC over the weekend a bit to try and optimize some
code I had written in Codevision that wasnt executing fast enough to
my liking. As a matter of interest, with just very minor but clearly
important optimizations, I took code that took 57us to execute @ 10MHz
down to 24us in codevision, and then by porting it to AVR GCC I got it
down to approx. 11us, awesome !
But . . . Is there a easy way in AVR GCC to turn a port pin on / off
based on the value of a variable.
Example:
CODEVISION:
unsigned char random_value;
while(1){
random_value = Get_Random_Value(); //returns 1 or 0 "randomly"
PORTA.1 = random_value;
}
that compliles and works fine in codevision, but in AVR GCC ive had to
do the following:
unsigned char random_value;
while(1){
random_value = Get_Random_Value();
if (random_value) sbi(PORTA, PA1);
else cbi(PORTA, PA1);
}
was just wondering if there is a cleaner way to accomplish this
without using a if.
Thanks
Hein B
Auckland, New Zealand.