PDA

View Full Version : program help



snk_naveen
05-22-2009, 09:18 PM
hi,
i found this code for obstacle detection using IR ,i dont remember where? but there are no header files in it . i tried some headers but it failed . need help!!!!

// One IR bumper is used. IR LED is connected to PORTC3,
// output of TSOP is connected to PORTC4.
// visible wavelength LED is connected to PORTD0 to indicate
// obstacle detection
// global variables declaration
volatile static unsigned char flag=0b00000000 ; //semaphore variable
volatile unsigned char pulses=0; // variable to count pulses
// initial setup
DDRC=0b00001000; // configure outputs
DDRD=0b00000001;
// timer 2 is set up to generate 36 KHz square wave, output compare mode.
TCCR2=0b00001010;
OCR2=139;
TIMSK|= (1<<(OCIE2)); // timer 2 output compare interrupt enable
sei(); // global interrupt enable
// timer 2 interrupt routine
ISR(TIMER2_COMP_vect)
{PORTC=PORTC^(flag); // if bit 3 of “flag” is set, PORTC3
// will toggle. Otherwise, it will not.
pulses++; //increment variable to count sent pulses
};
// main program
int main (void) {
while(1){
// first, four “if” sentences are used to realize bursts 25 pulses each with time
// between bursts, equal to length of 60 pulses on PORTC2 and PORTC3.
if ((pulses>=25)&&(bit_is_set(flag,3))) {
pulses=0; //
flag=flag&0b11110111;} // start count from beginning
if ((pulses>=60)&&(bit_is_clear(flag,3))) {
pulses=0;
flag=flag|0b00001000;}; // start count from beginning
// Visual obstacle indication. Turn on green LED if TSOP received signal
if (bit_is_clear(PINC,4)) {PORTD=(PORTD|0b00000001);} // TSOP output
low means it receive modulation. Turn on indicator LED.
else {PORTD=(PORTD&0b11111110);}; // else turn off.
}; // end of “while” loop
}; // end of main loop

robonics
05-23-2009, 12:02 AM
Taking a a rough glance at your code .. I guess the includes will be the ones below ..

#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <util/delay.h>

snk_naveen
05-23-2009, 11:17 AM
hi Arun Vijay,
yesterday i came to your address posted in your website to buy some parts , i thought you had a shop but there was only appartments there do you own a shop??

snk_naveen
05-23-2009, 11:33 AM
still the problem persists . when i build it the following error comes


rm -rf irsensor.o irsensor.elf dep/* irsensor.hex irsensor.eep
Build succeeded with 0 Warnings...
avr-gcc.exe -mmcu=atmega8 -Wall -gdwarf-2 -DF_CPU=8000000UL -O0 -fsigned-char -MD -MP -MT irsensor.o -MF dep/irsensor.o.d -c ../irsensor.c
In file included from ../irsensor.c:12:
c:/winavr-20080610/lib/gcc/../../avr/include/util/delay.h:90:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
../irsensor.c:16: error: expected identifier or '(' before 'volatile'
../irsensor.c:16: error: expected ')' before '(' token
../irsensor.c:17: error: expected identifier or '(' before 'volatile'
../irsensor.c:17: error: expected ')' before '(' token
../irsensor.c:19: error: expected identifier or '(' before 'volatile'
../irsensor.c:19: error: expected ')' before '(' token
../irsensor.c:20: error: expected identifier or '(' before 'volatile'
../irsensor.c:20: error: expected ')' before '(' token
../irsensor.c:21: error: expected identifier or '(' before 'volatile'
../irsensor.c:21: error: expected ')' before '(' token
../irsensor.c:22: error: expected '(' before 'volatile'
../irsensor.c: In function 'main':
../irsensor.c:42: error: 'low' undeclared (first use in this function)
../irsensor.c:42: error: (Each undeclared identifier is reported only once
../irsensor.c:42: error: for each function it appears in.)
../irsensor.c:42: error: expected ';' before 'means'
make: *** [irsensor.o] Error 1
Build failed with 15 errors and 1 warnings...

robonics
05-23-2009, 12:08 PM
HI Naveen
We don't have a shop setup since we primarily sell online. If you want to buy directly please come directly or give me a call at 9600070828

My suggestion is please dump this code, and start writing from scratch. I see some '(' missing compilation error .Try writing some led_blinking program first and then slowly build on it.