Hi everyone,
Im trying to get an LED to light on when i press a switch but im having trouble with it to make it turn off when i press the switch again. I got the LED works when i press the sw but i want to turn it off but pressing that switch again
Could some one help me with this code to get it working please. My C programming is pretty bad so im abit strugling to get it going. So please tell me where i have done wrong and correct me .
Here are the codes i've done:
/* Pressing the sw will toggle led on and off. That is:
i, press once- led on
ii, press again- led off
iii, press again- led on(and so on)
*/
#define F_CPU 16E6 //16mhz
#include <avr/io.h>
void main(void)
{
DDRA = 0x00;//port a :i/p
DDRC = 0xFF ;// port c as output
PORTC = 0xff ;//port c set to high state
for (;
if ((PINA & 0x02 )==0x02) // INPUT if switch2 is press led on
{ PORTC ^= 0x08 ; }//bit 3 change to low state, led2 light on
//else //led2 extinguish
// { PORTC |= 0x00; }//led2 off
return 0;
}
Im trying to get an LED to light on when i press a switch but im having trouble with it to make it turn off when i press the switch again. I got the LED works when i press the sw but i want to turn it off but pressing that switch again
Could some one help me with this code to get it working please. My C programming is pretty bad so im abit strugling to get it going. So please tell me where i have done wrong and correct me .
Here are the codes i've done:
/* Pressing the sw will toggle led on and off. That is:
i, press once- led on
ii, press again- led off
iii, press again- led on(and so on)
*/
#define F_CPU 16E6 //16mhz
#include <avr/io.h>
void main(void)
{
DDRA = 0x00;//port a :i/p
DDRC = 0xFF ;// port c as output
PORTC = 0xff ;//port c set to high state
for (;
if ((PINA & 0x02 )==0x02) // INPUT if switch2 is press led on
{ PORTC ^= 0x08 ; }//bit 3 change to low state, led2 light on
//else //led2 extinguish
// { PORTC |= 0x00; }//led2 off
return 0;
}