drbizzarow
Advanced Member level 1
hi guys !!!
i have written a code in which for atmega162...... every time its receive a byte my controller hangs..... can any body tell me what i am missing ???
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
/* CPU frequency */
#define F_CPU 16000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU) / (USART_BAUDRATE * 16UL)) - 1)
#define HIGH 1
#define LOW 0
#define LEFT 'L'
#define RIGHT 'R'
#define FRONT 'F'
#define BACK 'B'
#define KNEE 'K'
//#define STOP 'S'
//#define All 'A'
//#define VOID_SPACE 'V'
#define SERIAL_PACKET_SIZE 10
#define DISTANCE_THRESHOLD 50
#define BUZZER_ON PORTB |= 0x01; //Buzzer 0N
#define BUZZER_OFF PORTB &= 0xFE; //Buzzer OFF
#define SCAN_MTR_LEFT PORTC = PORTC |= 0x03; PORTC &= 0xFD;
#define SCAN_MTR_RIGHT PORTC = PORTC |= 0x03; PORTC &= 0xFE;
#define SCAN_MTR_STOP PORTC = PORTC |= 0x03;
#define LEFT_MOTOR_OFF PORTC |= 0x08;
#define LEFT_MOTOR_ON PORTC &= 0xF7;
#define FRONT_MOTOR_OFF PORTC |= 0x04;
#define FRONT_MOTOR_ON PORTC &= 0xFB;
#define RIGHT_MOTOR_OFF PORTC |= 0x20;
#define RIGHT_MOTOR_ON PORTC &= 0xDF;
#define BACK_MOTOR_OFF PORTC |= 0x10;
#define BACK_MOTOR_ON PORTC &= 0xEF;
#define KNEE_MOTOR_OFF PORTC |= 0x40;
#define KNEE_MOTOR_ON PORTC &= 0xBF;
#define AUDIO_FOR_FRONT PORTB = 0xFF;
#define AUDIO_FOR_BACK PORTB = 0xFF
#define AUDIO_FOR_LEFT PORTB = 0xFF
#define AUDIO_FOR_RIGHT PORTB = 0xFF
#define AUDIO_FOR_KNEE PORTB = 0xFF
#define PLAY_AUDIO PORTB = 0xFE; _delay_ms(50); PORTB = 0xFF
#define NO_AUDIO PORTB = 0xFF
unsigned char SerialBuffIndex = 0;
unsigned char SerialBuff[SERIAL_PACKET_SIZE];
unsigned char CurDistance;
unsigned char CurDirection;
unsigned char SmtrDir;
unsigned char Tbyte;
unsigned char ObsDetect;
void ldelay(int time)
{
while(time--)
_delay_ms(10000);
}
ISR(USART0_RXC_vect)
{
unsigned char SerialCmd;
SerialCmd = UDR0;
}
int main(void)
{
DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFE;
DDRE = 0xFF;
PORTA = 0xFF;
PORTB = 0xFE;
PORTC = 0xFF;
PORTD = 0xFF;
PORTE = 0xFF;
DDRA = 0x00;
DDRE = 0x00;
UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry
UCSR0C |= (1 << UCSZ00) | (1 << UCSZ01);// Use 8-bit character sizes
UBRR0L = 50;//BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRR0H = 0;//(BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UCSR0B |= (1 << RXCIE0); // Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed
while(1)
{
UDR0 = 'H'; _delay_ms(100);
UDR0 = 'p'; _delay_ms(100);
UDR0 = 'V'; _delay_ms(100);
UDR0 = 'i'; _delay_ms(100);
UDR0 = 's'; _delay_ms(100);
}
BUZZER_OFF;
//All MOTORS OFF
SCAN_MTR_STOP
while(1)
{
}
return 0;
}
i have written a code in which for atmega162...... every time its receive a byte my controller hangs..... can any body tell me what i am missing ???
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
/* CPU frequency */
#define F_CPU 16000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU) / (USART_BAUDRATE * 16UL)) - 1)
#define HIGH 1
#define LOW 0
#define LEFT 'L'
#define RIGHT 'R'
#define FRONT 'F'
#define BACK 'B'
#define KNEE 'K'
//#define STOP 'S'
//#define All 'A'
//#define VOID_SPACE 'V'
#define SERIAL_PACKET_SIZE 10
#define DISTANCE_THRESHOLD 50
#define BUZZER_ON PORTB |= 0x01; //Buzzer 0N
#define BUZZER_OFF PORTB &= 0xFE; //Buzzer OFF
#define SCAN_MTR_LEFT PORTC = PORTC |= 0x03; PORTC &= 0xFD;
#define SCAN_MTR_RIGHT PORTC = PORTC |= 0x03; PORTC &= 0xFE;
#define SCAN_MTR_STOP PORTC = PORTC |= 0x03;
#define LEFT_MOTOR_OFF PORTC |= 0x08;
#define LEFT_MOTOR_ON PORTC &= 0xF7;
#define FRONT_MOTOR_OFF PORTC |= 0x04;
#define FRONT_MOTOR_ON PORTC &= 0xFB;
#define RIGHT_MOTOR_OFF PORTC |= 0x20;
#define RIGHT_MOTOR_ON PORTC &= 0xDF;
#define BACK_MOTOR_OFF PORTC |= 0x10;
#define BACK_MOTOR_ON PORTC &= 0xEF;
#define KNEE_MOTOR_OFF PORTC |= 0x40;
#define KNEE_MOTOR_ON PORTC &= 0xBF;
#define AUDIO_FOR_FRONT PORTB = 0xFF;
#define AUDIO_FOR_BACK PORTB = 0xFF
#define AUDIO_FOR_LEFT PORTB = 0xFF
#define AUDIO_FOR_RIGHT PORTB = 0xFF
#define AUDIO_FOR_KNEE PORTB = 0xFF
#define PLAY_AUDIO PORTB = 0xFE; _delay_ms(50); PORTB = 0xFF
#define NO_AUDIO PORTB = 0xFF
unsigned char SerialBuffIndex = 0;
unsigned char SerialBuff[SERIAL_PACKET_SIZE];
unsigned char CurDistance;
unsigned char CurDirection;
unsigned char SmtrDir;
unsigned char Tbyte;
unsigned char ObsDetect;
void ldelay(int time)
{
while(time--)
_delay_ms(10000);
}
ISR(USART0_RXC_vect)
{
unsigned char SerialCmd;
SerialCmd = UDR0;
}
int main(void)
{
DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFE;
DDRE = 0xFF;
PORTA = 0xFF;
PORTB = 0xFE;
PORTC = 0xFF;
PORTD = 0xFF;
PORTE = 0xFF;
DDRA = 0x00;
DDRE = 0x00;
UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry
UCSR0C |= (1 << UCSZ00) | (1 << UCSZ01);// Use 8-bit character sizes
UBRR0L = 50;//BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRR0H = 0;//(BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UCSR0B |= (1 << RXCIE0); // Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed
while(1)
{
UDR0 = 'H'; _delay_ms(100);
UDR0 = 'p'; _delay_ms(100);
UDR0 = 'V'; _delay_ms(100);
UDR0 = 'i'; _delay_ms(100);
UDR0 = 's'; _delay_ms(100);
}
BUZZER_OFF;
//All MOTORS OFF
SCAN_MTR_STOP
while(1)
{
}
return 0;
}