Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] code help an error coming

Status
Not open for further replies.

Aayush Awasthi

Junior Member level 2
Joined
Nov 18, 2013
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
128
there is a program of TSOP but an error has come that is ../newknp.c:119: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
and a warning c:/winavr-20080610/lib/gcc/../../avr/include/util/delay.h:85:3: warning: #warning "F_CPU not defined for <util/delay.h>"
pls give some help i want ....
Code:
#include<avr/io.h>
#include<util/delay.h>
//#include<avr/interrupt.h>
#include<stdio.h>

#define TIM1_CAPT 6
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTC
#define F_CPU 1000000UL

void lcd_config();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
int lcd_num(int);
// Timer 1 input capture interrupt service routine
interrupt [TIM1_CAPT] void timer1_capt_isr(void);



int main(void)
{
	DDRC=0xFF;
	DDRD=0x00;
	//DDRB=0xFF;
/*	sei();
	MCUCR=0b00000010;
	GICR=0b010000000;	
	lcd_config();
*/	while(1)
	{

	}
}

/*
	ISR(INT0_vect)
	{
	int x;
	PORTB=0xFF;
	lcd_config();
	lcd_cmd(0x01);
	_delay_ms(100);
	lcd_cmd(0x80);
	x=PIND;
	lcd_num(x);
	_delay_ms(1000);
	}
*/





	int lcd_num(int n)
	{
	int r,s=0;
	lcd_cmd(0x04);
	while(n>0)
	{
	r=n%10;
	n=n/10;
	s=(s*10)+r;
	lcd_data(s+48);
	_delay_ms(100);
	}
	lcd_cmd(0x06);
	return 0;
	}


void lcd_config()
{
lcd_cmd(0x02);
lcd_cmd(0x28);
lcd_cmd(0x0C);
lcd_cmd(0x06);
}


void lcd_cmd(unsigned char x)
{
	LCD=x&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN); 
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(x<<4)&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}
void lcd_data(unsigned char y)
{
	LCD=y&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(y<<4)&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}
// Timer 1 input capture interrupt service routine
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
{
unsigned char uc_string[10];
unsigned char uc_i;
unsigned int ui_value=0;
uc_i=TCCR1B;

if((uc_i&0b01000000)==0)                  // ICP Sensing is at falling edge
    {
    ui_timer=ICR1L;                           //ICR1 must be readed sequently
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_value=ui_timer-ui_oldtimer;


	lcd_config();
	lcd_cmd(0x01);
	_delay_ms(100);
	lcd_cmd(0x88);
	lcd_num(ui_value);
	_delay_ms(1000);	

    //The actual high measurement is in the ui_value variable in micro seconds.  Here you have to set your own code
    
    TCCR1B|=0b01000000;        //Set ICP Sensing at falling edge
    }

else                                      // ICP Sensing is at rising edge

    {
    TCCR1B&=0b10111111;
    ui_timer=ICR1L;
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_oldtimer=ui_timer;


	
	lcd_config();
	lcd_cmd(0x01);
	_delay_ms(100);
	lcd_cmd(0x88);
	lcd_num(ui_value);
	_delay_ms(1000);	

//The actual low measurement is in the ui_value variable in micro seconds. Here you have to set your own code   
}
}
 
Last edited by a moderator:

Re: code help an error coming pls solve

You are mixing avrgcc and codevision syntax.

Code:
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
That is not how you declare an interrupt in avrgcc, the correct syntax is
Code:
ISR(TIM1_CAPT_vect)


You should also include
Code:
#include<avr/interrupt.h>


As for the F_CPU not defined error you should define the F_CPU before the inclusion of delay.h so move it at the top
 
Re: code help an error coming pls solve

You are mixing avrgcc and codevision syntax.

Code:
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
That is not how you declare an interrupt in avrgcc, the correct syntax is
Code:
ISR(TIM1_CAPT_vect)


You should also include
Code:
#include<avr/interrupt.h>


As for the F_CPU not defined error you should define the F_CPU before the inclusion of delay.h so move it at the top



thank you sir but still prob is there is i have to call this directly in main or define in main function
 

Re: code help an error coming pls solve

What is the point of calling a timer interrupt manually?
 

Re: code help an error coming pls solve

i m using IR TSOP1738 Ic for reciving singal of TV remote thats why i m using timer but i m unable to find ans till now how to recive data of this IR sensor
 

Re: code help an error coming pls solve

avr studio 4 and compiler gcc i m using
 

Re: code help an error coming pls solve

Try this:

Code:
#include<avr/io.h>
[COLOR="#FF0000"]#define F_CPU 1000000UL[/COLOR]
#include<util/delay.h>
#include<stdio.h>

#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTC

void lcd_config();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
int lcd_num(int);

int main(void)
{
	DDRC=0xFF;
	DDRD=0x00;

        [COLOR="#FF0000"]// initialization of the timer?[/COLOR]

	[COLOR="#FF0000"]sei();[/COLOR]     [COLOR="#FF0000"]// You have to set global interrupt enable bit[/COLOR]
/*	MCUCR=0b00000010;
	GICR=0b010000000;	
	lcd_config();
*/	
        while(1)
	{

	}

        [COLOR="#FF0000"]return 0;[/COLOR]
}

	int lcd_num(int n)
	{
	int r,s=0;
	lcd_cmd(0x04);
	while(n>0)
	{
	r=n%10;
	n=n/10;
	s=(s*10)+r;
	lcd_data(s+48);
	_delay_ms(100);
	}
	lcd_cmd(0x06);
	return 0;
	}


void lcd_config()
{
lcd_cmd(0x02);
lcd_cmd(0x28);
lcd_cmd(0x0C);
lcd_cmd(0x06);
}


void lcd_cmd(unsigned char x)
{
	LCD=x&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN); 
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(x<<4)&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}
void lcd_data(unsigned char y)
{
	LCD=y&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(y<<4)&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}

[COLOR="#FF0000"]// TIM1_CAPT_vect only if you have ATtiny24,44,84 device... if you have another one, please check:
// http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html[/COLOR]
ISR(TIM1_CAPT_vect)
{
unsigned char uc_string[10];
unsigned char uc_i;
unsigned int ui_value=0;
uc_i=TCCR1B;

if((uc_i&0b01000000)==0)                  // ICP Sensing is at falling edge
    {
    ui_timer=ICR1L;                           //ICR1 must be readed sequently
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_value=ui_timer-ui_oldtimer;


	lcd_config();
	lcd_cmd(0x01);
	[COLOR="#FF0000"]//_delay_ms(100);[/COLOR]    [COLOR="#FF0000"] // You dont have to wait in interrupts routines, just make some code and go away[/COLOR]
	lcd_cmd(0x88);
	lcd_num(ui_value);
	[COLOR="#FF0000"]//_delay_ms(1000);[/COLOR]	

    //The actual high measurement is in the ui_value variable in micro seconds.  Here you have to set your own code
    
    TCCR1B|=0b01000000;        //Set ICP Sensing at falling edge
    }

else                                      // ICP Sensing is at rising edge

    {
    TCCR1B&=0b10111111;
    ui_timer=ICR1L;
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_oldtimer=ui_timer;


	
	lcd_config();
	lcd_cmd(0x01);
	[COLOR="#FF0000"]//_delay_ms(100);[/COLOR]
	lcd_cmd(0x88);
	lcd_num(ui_value);
        [COLOR="#FF0000"]	//_delay_ms(1000);	[/COLOR]
}
}
 
Last edited:

Re: code help an error coming pls solve

still not working and i also want to know that to which pin in atmega16 timer1 is internally connected
 

Re: code help an error coming pls solve

I edited my last post. If you have ATmega16, so you have a bad interrupt vector. Try this:

TIMER1_CAPT_vect

because the vector what you have right now is for ATtiny devices.
 

Re: code help an error coming pls solve

i have done all of ur correction but still code is not working can u pls help me by seeing my code that why this code is not working its urgent...................



Code:
#include<avr/io.h>
#define F_CPU 1000000UL
#include<util/delay.h>
#include<stdio.h>
#include<avr/interrupt.h>

#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTC

void lcd_config();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
int lcd_num(int);

int main(void)
{
	DDRC=0xFF;
	DDRD=0x00;

    TCCR0=0x69;
	TCCR1A=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM10);
	TCCR1B=(1<<WGM12)|(1<<CS00);    // initialization of timer?

	sei();     // You have to set global interrupt enable bit
/*	MCUCR=0b00000010;
	GICR=0b010000000;	
	lcd_config();
*/	
        while(1)
	{
		
		ISR(TIM1_CAPT_vect);
		_delay_ms(100);	
	}

        return 0;
}

	int lcd_num(int n)
	{
	int r,s=0;
	lcd_cmd(0x04);
	while(n>0)
	{
	r=n%10;
	n=n/10;
	s=(s*10)+r;
	lcd_data(s+48);
	_delay_ms(100);
	}
	lcd_cmd(0x06);
	return 0;
	}


void lcd_config()
{
lcd_cmd(0x02);
lcd_cmd(0x28);
lcd_cmd(0x0C);
lcd_cmd(0x06);
}


void lcd_cmd(unsigned char x)
{
	LCD=x&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN); 
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(x<<4)&0xF0;
	LCD&=~(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}
void lcd_data(unsigned char y)
{
	LCD=y&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);



	LCD=(y<<4)&0xF0;
	LCD|=(1<<LCD_RS);
	LCD&=~(1<<LCD_RW);
	LCD|=(1<<LCD_EN);
	_delay_ms(1);
	LCD&=~(1<<LCD_EN);
}

// Timer 1 input capture interrupt service routine
ISR(TIM1_CAPT_vect)
{
unsigned char uc_string[10];
unsigned char uc_i;
unsigned int ui_value=0;
unsigned int ui_timer=0;
unsigned int ui_oldtimer=0;
uc_i=TCCR1B;

if((uc_i&0b01000000)==0)                  // ICP Sensing is at falling edge
    {
    ui_timer=ICR1L;                           //ICR1 must be readed sequently
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_value=ui_timer-ui_oldtimer;


	lcd_config();
	lcd_cmd(0x01);
	//_delay_ms(100);  // You dont have to wait in interrupts routines, just make some code and go away
	lcd_cmd(0x88);
	lcd_num(ui_value);
	//_delay_ms(1000);	

    //The actual high measurement is in the ui_value variable in micro seconds.  Here you have to set your own code
    
    TCCR1B|=0b01000000;        //Set ICP Sensing at falling edge
    }

else                                      // ICP Sensing is at rising edge

    {
    TCCR1B&=0b10111111;
    ui_timer=ICR1L;
    ui_value=ICR1H;
    ui_value=ui_value<<8;
    ui_timer+=ui_value;
    ui_oldtimer=ui_timer;


	
	lcd_config();
	lcd_cmd(0x01);
	//_delay_ms(100);
	lcd_cmd(0x88);
	lcd_num(ui_value);
        	//_delay_ms(1000);	
}
}
 
Last edited by a moderator:

Re: code help an error coming pls solve

Look at my last post:

I edited my last post. If you have ATmega16, so you have a bad interrupt vector. Try this:

TIMER1_CAPT_vect

because the vector what you have right now is for ATtiny devices.


And you cannot call ISR routine in a while(1){} routine. It's not make sense
 

Re: code help an error coming pls solve

ok i done but still not working will you pls tell me the connection of TSOP1738 with atmega16

- - - Updated - - -

so what to do in while(1) function and i have posted my code so pls edited it what ever you are saying
 

Re: code help an error coming pls solve

ok i done but still not working will you pls tell me the connection of TSOP1738 with atmega16

wait a moment...step by step. Do you able now to compile your source code or not?

so what to do in while(1) function and i have posted my code so pls edited it what ever you are saying

nothing... in this situation is while(1) {} only neverending loop, where program is waiting for some interrupt from the Timer1...when the interrupt occurs, program automatically jumps into interrupt routine and makes some code there.
 
Last edited:

Re: code help an error coming pls solve

ok
yes now code is able to compile but when i do burning in micro-controller then no output is come on LCD thats why i ask you where timer1 is connect with microcontroller..
 

Re: code help an error coming pls solve

T1 (PB1) pin if you are using a counter and OC1A and OC1B if you are using a timer
 

Re: code help an error coming pls solve

sir i connect the my ic at PB1 but no result coming still
And i am using TIMER1
 

Re: code help an error coming pls solve


Code C - [expand]
1
lcd_config()

is only called once in

Code C - [expand]
1
main()

before

Code C - [expand]
1
while(1)

and after PORT initialization. Remove all LCD code from ISR.
 

Re: code help an error coming pls solve

and of course you have to wait for 200ms after startup before you call lcd_config(). And I have an experience that it is good to send 3x lcd_cmd(0x03); at first. This is my LCD routine:

Code:
void LCD_init( void)
{
	 // set LCD port
	 LCDPORTI_C |= 0xfc;
 	LCDPORTD = 0;

        _delay_ms(200);
        LCD_half_byte(0x03);	        // it is needed for 4bit communication
        LCD_half_byte(0x03);
        LCD_half_byte(0x03);
        LCD_half_byte(0x02);
        LCD_inst(0x2c);			// Function set
        LCD_inst(0x0c);			// Zapnutie displeja
        LCD_inst(0x01);			// Zmazanie displeja		
        LCD_inst(0x06);     		// Entry mode set


       _delay_ms(10);			// zmazanie displeja pre uplnu istotu
       LCD_inst(0x01);
       _delay_ms(10);

}

void LCD_half_byte (unsigned char data)
{	
      LCDPORTD = 0;

      clrbit (LCDPORTI,RS);
      setbit(LCDPORTI,EN); 
      LCDPORTD |= ( (data & 0x0f)<<4 ); 
      clrbit(LCDPORTI,EN);
      setbit (LCDPORTI,RS);

      _delay_ms(10);	
}

// Print char
void LCD_char ( unsigned char znak )
{

	setbit (LCDPORTI,RS);

	LCDPORTD = 0;                          // !!!
	setbit(LCDPORTI,EN );
	LCDPORTD |= ( znak & 0xf0 );      // horne 4 bity 
	clrbit(LCDPORTI,EN );


	LCDPORTD = 0;
	setbit (LCDPORTI,RS);

	setbit(LCDPORTI,EN);
	LCDPORTD |= ( (znak & 0x0f)<<4 ); // dolne 4 bity
	clrbit(LCDPORTI,EN);
	_delay_us(200);	

}

some comments are in slovak language, but it is not important for you right now. But if you have a question about it, I'll translate it to you
 

Re: code help an error coming pls solve

I see you are only using Timer1 interrupt. It is used to detect bit 0 or bit 1 of IR. You need to use external interrupt like INT0_vect for detecting the demodulated IR data from TSOPxxxx. You might also need to toggle the edge detection on every interrupt. Post the link from where you got the code.

https://www.dharmanitech.com/2009/01/ir-remote-controlled-car-pwm-motor.html

https://extremeelectronics.co.in/code-libraries/using-ir-remote-with-avr-mcus/

https://extremeelectronics.co.in/code-libraries/using-ir-remote-with-avr-mcus-part-ii/#comment-55361
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top