ismbn
Full Member level 3
- Joined
- Feb 11, 2012
- Messages
- 160
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,308
- Location
- Mumbai. india
- Activity points
- 2,444
#include <avr/io.h>
#include <util/delay.h>
#define RC_on sbit(PORTC,5);
#define RC_off clrbit(PORTC,5);
///////////////////////////////////// Variable declarection///////////////////////////
unsigned int x=0,y=0;
unsigned long z=0;
///////////////////////////////////// End Variable declarection///////////////////////////
unsigned char read( void )
{
/* Wait for incoming data */
while (!(UCSRA & (1<<RXC)));
/* Return the data */
return UDR;
}
void print( unsigned char data )
{
/* Wait for empty transmit buffer */
while (!(UCSRA & (1<<UDRE)));
/* Start transition */
UDR = data;
}
/* Transmit String Function */
void print_str( const char *str )
{
while (*str)
{
print(*str);
str++;
}
}
/////////////////////////////////// USART init //////////////////////////////////
void uart_init( unsigned int baud )
{
/* Set the baud rate */
UBRRH = (unsigned char) (baud>>8);
UBRRL = (unsigned char) baud;
/* Enable UART receiver and transmitter */
UCSRB = ( ( 1 << RXEN ) | ( 1 << TXEN ) );
/* Set frame format: 8 data 1stop */
UCSRC = (3<<UCSZ0);
}
///////////////////////////// End of USART init /////////////////////////////////
int main(void)
{
uart_init(103);
DDRA=00;
DDRB=0x00;
DDRC=0b11111111;
RC_on;
while(1)
{
_delay_ms(1);;
RC_off;
x=PINA;
y=PINB;
// print(x);
z=(y*255)+x; /// when i am using z=(y*255)+x; ≡≡ continuously
print(z); ///and when i am using z=(y*22)+x; III
RC_on;
}
}
int main(void)
{
uart_init(103);
DDRA=0x00;
DDRB=0x00;
DDRC=0b11111111;
RC_on;
while(1)
{
_delay_ms(10);
RC_off;
x=PINA;
print(x);
y=PINB;
// print(x);
z=(y*256)+x;
// print(z);
// z=z>>8;
// print(z);
RC_on;
}
}
z= (uint16_t(PINB & 0x0f)<<8) | PINA;
Are you sure that PA2 is constantly 0 while reading the input?
Have you tries with a direct connection to gnd?
in start i was connecting all the pins but it giving me fist 00 and then FF FF only thats way i am not connected it that time....Apply a known state to all pins, either 0 or 1 , you have several pins shown with gray color.
yes i have checked it in watch window in proteus ...did you check the values stores in x,y,z using a watch?
are they correct?
while(1)
{
[B][COLOR=#ff0000] RC_on;[/COLOR][/B]
[COLOR=#ff0000][B] _delay_us(1)[/B];[/COLOR]
x=PINA;
y=PINB;
z=(y*256)+x;
print(z);
[B][COLOR=#ff0000] RC_off;[/COLOR][/B]
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?