[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] a communication prtocol...where is the error?
From: |
pulkitmidha |
Subject: |
[avr-chat] a communication prtocol...where is the error? |
Date: |
Sun, 18 Jun 2006 07:13:46 -0700 (PDT) |
//i am trying to make a routing protocol on atmega8..but my problem is
//very elementary..sum1 please tell me quickly what the error is?
//please see the main() i have described the error there
#include <avr/io.h>
#define F_CPU 1000000 //1Mhz
#define UART_BAUD_RATE 4800 //4800 baud
//#define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16)-1)
typedef unsigned char u08;
u08 byte0,byte1,byte2,byte3,byte4,d,addr='P',flag=0;
void uart_init(void)
{
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = ((1<<URSEL) | (3<<UCSZ0));// 8-data, 1 stop-bit, no parity
UBRRH=0;
//UBRRL=25;
UBRRL=12;//(u08)UART_BAUD_SELECT;
}
void USART_Transmitt( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
unsigned char USART_Receiver( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
void datt(void)
{
d=65;// acqdata();
USART_Transmitt('Z');
USART_Transmitt(d);
USART_Transmitt(addr);
USART_Transmitt(addr);
}
void polt(void)
{
USART_Transmitt('Z');
USART_Transmitt(byte2 & 0xff);
USART_Transmitt(byte2);
USART_Transmitt(0);
USART_Transmitt(addr);
}
void ackr(void)
{
USART_Transmitt('Z');
}
void datf(void)
{
USART_Transmitt('Z');
USART_Transmitt(0);
USART_Transmitt(byte2);
USART_Transmitt(byte3);
USART_Transmitt(addr);
}
void polr(void)
{
if(byte2==addr)
datt();
else
polt();
}
/*void datr(void)
{
datf();
}*/
void main(void)
{u08 byte0,byte1,byte2,byte3,byte4;
uart_init();
while(!flag)
{
byte0=USART_Receiver();
USART_Transmitt(byte0);
if( byte0 == 'Z' )//here is where the error is!control is not entering this
// segment even when i give a 'Z' on the hyperterminal..wats more,
//the code is not similating correctly on avr studio!
{
USART_Transmitt('Q');
byte1=USART_Receiver();
if(byte1==addr)
{
flag=1;
byte2=USART_Receiver();
byte3=USART_Receiver();
byte4=USART_Receiver();
}
}
}
if(byte3=='U')
ackr();
else
if(byte3=='V')
polr();
else datf();
}
//i shall be very grateful to anyone who URGENTLY replies..thanx..pulkit
--
View this message in context:
http://www.nabble.com/a-communication-prtocol...where-is-the-error--t1806786.html#a4923809
Sent from the AVR - General forum at Nabble.com.
- [avr-chat] a communication prtocol...where is the error?,
pulkitmidha <=