konradIC13
Member
Hello,
Im having troubles with making this code work on ATmega8, i want to store switch value into variable and later use this variable.
Here is code:
I have switches connected to PC5 and PC4 and led connected to PC3. I want to store values of PC5 switch and PC4 switch in 'a' and 'b' variables and then make them turn led on only when both switches are on (high).
I have problem with storing those values into variable:
Not sure if its right
Also i dont know how to use those values in 'if' function,
Also later
Im having troubles with making this code work on ATmega8, i want to store switch value into variable and later use this variable.
Here is code:
Code:
/*
* Test.c
*
* Created: 2012-07-08 16:30:47
* Author: Konrad
*/
#define F_CPU 1000000L
#include <avr/io.h>
int main(void)
{
char a;
DDRC &=~ (1<<PC5); //PC5 as input
PORTC |= (1<<PC5); //pull up
DDRC &=~ (1<<PC4); //PC4 as input
PORTC |= (1<<PC4); //pull up
DDRC |= (1<<PC3); //output
PORTC |= (1<<PC3); //set as 1
while(1)
{
a = (PINC & (1<<PC5));
b = (PINC & (1<<PC4));
if(a&&b==1) //if both a and b =1
{
PORTC |= (1<<PC3); //set PC3 output as 1
}
else
{
PORTC &=~ (1<<PC3); //set PC3 output as 0
}
}
}
I have switches connected to PC5 and PC4 and led connected to PC3. I want to store values of PC5 switch and PC4 switch in 'a' and 'b' variables and then make them turn led on only when both switches are on (high).
I have problem with storing those values into variable:
Code:
a = (PINC & (1<<PC5));
b = (PINC & (1<<PC4));
Also i dont know how to use those values in 'if' function,
Also later
Last edited: