How can I check the value of the pins of one of the atmega16a ports?
i know how to check a value of one pin only by : Address & (1<<pin) ....
i'm using avr studio
thanks
Hi,
Would you please explain what you want to do?
I don't have your compiler and don't know its syntax but in PIC for example if you want to check whether the B PORT is equal to 8 ,you can simply use and if instruction.
sorry for dis explain ....
first i'm using atmega16a and i'm using avr studio as a compiler.
second i'm programming in C language.
third i want (for example): if pins 0,1,2 are high and the others are low (3--7) then do something......
i tried to put IF(PINC==0b00000111){do something} but it didn't work
Basicly, AVR studio is only for assembly language, but it's can be combined with c (avrgcc or others).
From my last post, you can learn it's algorithm and convert to c language.
unsigned char a; //for avrgcc uint8 a;
DDRC=0x00; //Port C as input
PORTC=0x00; //disable pull-up or you can change it with PORTC=0xFF (enable pull-up)
a=PINC; //store conditions of pins, so we only have to read it once.
if (a==0x03)
{
.....
.....
.....
}
else
{
if (a==...)
{
.....
.....
.....
}
else
{
PC4 to PC7 are JTAG pins by default, have you disabled the JTAG fuse (JTAGEN)?
You have to disable the fuse in order for the pins to operate as normal I/O.
u meant uint8_t because uint8 didn't work by the compiler...
but even this code didn't work
alexan_e:
i'm exactly working on portD and on pins from 0 to 3 i'm connecting to them a dtmf receiver so i want to make every button on the telephone has a meaning .....
the code u wrote didn't work i tried it.
The code is fine , if for some reason the value is not the one you expect this is not a problem of the above code.
Maybe your device is giving a different signal of maybe you need to enable the internal pull up resistors.
Also make sure that the pins are set as inputs.
What do you mean when you say that it is not working, can you be more specific?
Concerning the comment of the previous post you can use unsigned char or signed char or uint8_t etc , as long as you use in the condition a binary or hex value the comparison result is exactly the same, there is only a difference if you want to use a decimal format number >127 .
i'm using this schematic but the addition is that i'm connecting it to atmega16a to portD0-3 and i'm connecting all portC to leds
and the code is:
#include <avr/io.h>
#include <util/delay.h>
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
int main(void)
{
uint8_t z;
DDRC=0xFF;
PORTC=0x00;
DDRD=0x00;
while(1)
{
z=PIND;
_delay_ms(50);
if(z==0x04)
{
SETBIT(PORTC,1);
}
else {}
_delay_ms(1000);
PORTC=0x00;
}
return 0;
}
so if i pressed 2 the led on portC1 should blink while nothing is happening...
if you want to mask the first 4 bits then you can use if((z & 0x0F) == (0x04)) so that you set them to 0 and then the code checks is the last four are 1000