Thread: codevisionavr errors

  1. #1
    Registered User
    Join Date
    Jun 2016
    Posts
    6

    codevisionavr errors

    hello everyone,I have these codes for running hc05 bluetooth module,the codes should be run in codevisionavr but I see some error,also the project name is hc11.c and it has 2 header files hc05.h and usart.h please help me!!!:
    hc11.c
    Code:
    #include<io.h>
    /*Includes io.h header file where all the Input/Output Registers and its Bits are defined for all AVR microcontrollers*/
    
    
    #define    F_CPU    8000000
    /*Defines a macro for the delay.h header file. F_CPU is the microcontroller frequency value for the delay.h header file. Default value of F_CPU in delay.h header file is 1000000(1MHz)*/
    
    
    #include<delay.h>
    /*Includes delay.h header file which defines two functions, _delay_ms (millisecond delay) and _delay_us (microsecond delay)*/
    
    
    #include<hc05.h>
    /*Includes hc05.h header file which defines different functions for HC-05 Bluetooth Module. HC-05 header file version is 1.1*/
    
    
    
    
    void main(void)
    {
        delay_ms(500);
        delay_ms(500);
        /*Delay of 1s*/
        
        usart_init();
        /*USART initialization*/
        
        hc_05_bluetooth_transmit_string("ABLab Solutions");
        /*Transmits a string to Bluetooth Module*/
    
    
        hc_05_bluetooth_transmit_byte(0x0d);
        /*Transmits Carriage return to Bluetooth Module*/
        
        hc_05_bluetooth_transmit_byte(0x0a);
        /*Transmits New Line to Bluetooth Module for new line*/
    
    
        hc_05_bluetooth_transmit_string("www.ablab.in");
        /*Transmits a string to Bluetooth Module*/
    
    
        hc_05_bluetooth_transmit_byte(0x0d);
        /*Transmits Carriage return to Bluetooth Module*/
        
        hc_05_bluetooth_transmit_byte(0x0a);
        /*Transmits New Line to Bluetooth Module for new line*/
    }
    /*End of program*/








    hc05.h

    Code:
    #ifndef _HC05_H_
    #define _HC05_H_ ..1
    
    
    
    
    
    
    
    
    #include<io.h>
    #include<delay.h>
    #include<usart.h>
    #include<string.h>
    
    
    
    
    char hc_05_buffer1[25], hc_05_buffer2[50];
    char temp;
    unsigned char i;
    void hc_05_bluetooth_transmit_byte(char data_byte);
    char hc_05_bluetooth_receive_byte(void);
    void hc_05_bluetooth_transmit_string(char *transmit_string);
    void hc_05_bluetooth_transmit_command(char *transmit_string);
    char *hc_05_bluetooth_receive_string(char *receive_string, unsigned char terminating_character);
    unsigned char hc_05_bluetooth_at_command_mode_test(void);
    unsigned char hc_05_bluetooth_device_name_change(char *device_name);
    unsigned char hc_05_bluetooth_get_version(void);
    unsigned ..char hc_05_bluetooth_change_baud_rate(long int baud_rate);
    unsigned ..char hc_05_bluetooth_pin_change(char *new_pin);
    
    
    
    
    
    
    
    
    void hc_05_bluetooth_transmit_byte(char data_byte)
    {
    usart_data_transmit(data_byte);
    }
    char hc_05_bluetooth_receive_byte(void)
    {
    return usart_data_receive();
    }
    void hc_05_bluetooth_transmit_string(char *transmit_string)
    {
    usart_string_transmit(transmit_string);
    }
    char *hc_05_bluetooth_receive_string(char *receive_string, unsigned char terminating_character)
    {
    unsigned char temp=0x00;..
    ..// .. unsigned char i;
    for(unsigned char i=0;;i++)
    {
    *(receive_string+i)=usart_data_receive();
    if(*(receive_string+i)==terminating_character)
    break;
    else
    temp++;
    }
    *(receive_string+temp)='\0';
    return receive_string;
    }
    unsigned char hc_05_bluetooth_at_command_mode_test(void)
    {
    UBRRL=12;
    delay_ms(500);
    usart_string_transmit("AT");
    usart_data_transmit(0x0d);
    usart_data_transmit(0x0a);
    usart_string_receive(hc_05_buffer1,0x0d);
    temp=usart_data_receive();
    if(!(strcmp(hc_05_buffer1,"OK")))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    
    
    
    
    unsigned ..char hc_05_bluetooth_change_baud_rate(long int baud_rate)
    {
    UBRRL=12;
    delay_ms(500);
    if(baud_rate==4800)
    {
    usart_string_transmit("AT+UART=4800,0,0");
    }
    else if(baud_rate==9600)
    {
    usart_string_transmit("AT+UART=9600,0,0");
    }
    else if(baud_rate==19200)
    {
    usart_string_transmit("AT+UART=19200,0,0");
    }
    else if(baud_rate==38400)
    {
    usart_string_transmit("AT+UART=38400,0,0");
    }
    else if(baud_rate==57600)
    {
    usart_string_transmit("AT+UART=57600,0,0");
    }
    else if(baud_rate==115200)
    {
    usart_string_transmit("AT+UART=115200,0,0");
    }
    else if(baud_rate==230400)
    {
    usart_string_transmit("AT+UART=230400,0,0");
    }
    else if(baud_rate==460800)
    {
    usart_string_transmit("AT+UART=460800,0,0");
    }
    else if(baud_rate==921600)
    {
    usart_string_transmit("AT+UART=921600,0,0");
    }
    else if(baud_rate==1382400)
    {
    usart_string_transmit("AT+UART=1382400,0,0");
    }
    else
    {
    ;
    }
    usart_data_transmit(0x0d);
    usart_data_transmit(0x0a);
    usart_string_receive(hc_05_buffer1,13);
    temp=usart_data_receive();
    if(!(strcmp(hc_05_buffer1,"OK")))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    
    
    
    
    unsigned char hc_05_bluetooth_device_name_change(char *device_name)
    {
    UBRRL=12;
    delay_ms(500);
    usart_string_transmit("AT+NAME=");
    usart_string_transmit(device_name);
    usart_data_transmit(0x0d);
    usart_data_transmit(0x0a);
    usart_string_receive(hc_05_buffer1,13);
    temp=usart_data_receive();
    if(!(strcmp(hc_05_buffer1,"OK")))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    // unsigned char i=9,j=0;
    
    
    
    
    unsigned char hc_05_bluetooth_get_version(void)
    {
    ..// unsigned char i=9,j=0;
    
    
    
    
    UBRRL=12;
    delay_ms(500);
    unsigned char i=9,j=0;
    usart_string_transmit("AT+VERSION?");
    usart_data_transmit(0x0d);
    usart_data_transmit(0x0a);
    usart_string_receive(hc_05_buffer2,13);
    temp=usart_data_receive();
    usart_string_receive(hc_05_buffer1,13);
    temp=usart_data_receive();
    for(i=9;hc_05_buffer2[i]!=0;i++)
    {
    hc_05_buffer2[j]=hc_05_buffer2[i];
    j++;
    }
    hc_05_buffer2[j]=0;
    if(!(strcmp(hc_05_buffer1,"OK")))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    
    
    
    
    unsigned ..char hc_05_bluetooth_pin_change(char *new_pin)
    {
    UBRRL=12;
    delay_ms(500);
    usart_string_transmit("AT+PSWD=");
    usart_string_transmit(new_pin);
    usart_data_transmit(0x0d);
    usart_data_transmit(0x0a);
    usart_string_receive(hc_05_buffer1,13);
    temp=usart_data_receive();
    if(!(strcmp(hc_05_buffer1,"OK")))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    
    
    
    
    #endif





    usart.h
    Code:
    #ifndef _USART_H_
    #define _USART_H_  1
    
    
    
    #include<io.h>
    #include<delay.h>
    #include<string.h>
    
     unsigned char i;
    /*The function is declared to initialize the USART with following cinfiguration:-
    USART mode - Asynchronous
    Baud rate - 9600
    Data bits - 8
    Stop bit - 1
    Parity - No parity.*/
    
    void usart_init();
    
    
    
    
    /*The function is declared to transmit data.*/
    
    void usart_data_transmit(unsigned char data );
    
    
    
    
    /*The function is declared to receive data.*/
    
    unsigned char usart_data_receive( void );
    
    
    
    
    /*The function is declared to transmit string.*/
    
    void usart_string_transmit(char *string);
    
    
    
    
    /*The function is declared to receive string.*/
    
    char *usart_string_receive(char *receive_string,unsigned char terminating_character);
    
    
    
    /*Function defination*/
    
    void usart_init()
    {
    UBRRH = 0;
    UBRRL =51;
    UCSRB|= (1<<RXEN)|(1<<TXEN);
    UCSRC |= (1 << URSEL)|(3<<UCSZ0);
    }
    
    
    void usart_data_transmit(unsigned char data )
    {
    while ( !( UCSRA & (1<<UDRE)) )
    ;
    UDR = data;
    }
    
    unsigned char usart_data_receive( void )
    {
    while ( !(UCSRA & (1<<RXC)) )
    ;
    return UDR;
    }
    
    void usart_string_transmit(char *string)
    {
    while(*string)
    {
    usart_data_transmit(*string++);
    }
    }
     // unsigned char i;
     unsigned char i;char *usart_string_receive(char *receive_string,unsigned char terminating_character)
    {
    unsigned char temp=0x00;
     //   unsigned char i;
    for(unsigned char i=0;;i++)
    {
    *(receive_string+i)=usart_data_receive();
    if(*(receive_string+i)==terminating_character)
    break;
    else
    temp++;
    }
    *(receive_string+temp)='\0';
    return receive_string;
    }
    #endif




    but errors:


    Error: C:\cvavreval\inc\usart.h(115), #include-d from: hc05.h: undefined symbol 'unsigned'
    Error: C:\cvavreval\inc\usart.h(115), #include-d from: hc05.h: ';' expected, but ')' found
    Error: C:\cvavreval\inc\usart.h(119), #include-d from: hc05.h: out of context
    Error: C:\cvavreval\inc\hc05.h(68), #include-d from: hc11.c: undefined symbol 'unsigned'
    Error: C:\cvavreval\inc\hc05.h(68), #include-d from: hc11.c: ';' expected, but ')' found
    Error: C:\cvavreval\inc\hc05.h(72), #include-d from: hc11.c: out of context
    Error: C:\cvavreval\inc\hc05.h(193), #include-d from: hc11.c: must declare first in block

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Do you have a C99 compiler?

    Do you have a compiler with a C99 mode, which you need to enable.

    The are a couple of code constructs which don't work in original C.

    For example

    1. Declarations inside for loops.
    for(unsigned char i=0;;i++)

    2. Mixed declarations and statements
    UBRRL=12;
    delay_ms(500);
    unsigned char i=9,j=0;


    More general points.
    1. Your indentation sucks - > Indent style - Wikipedia, the free encyclopedia
    2. You have a global variables called 'i' and 'temp', which are sometimes (always?) overridden by local variable declarations in functions. This will give you hard to find bugs!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2016
    Posts
    6

    Exclamation just one other error by codevisionavr

    I activated gcc mode by this code:

    Code:
    #include 
    
    int main(void) {
      set_sleep_mode(SLEEP_MODE_IDLE);
      sei();
      sleep_mode();
    and I saw just this error :

    Error: C:\cvavreval\inc\usart.h(40), included from: hc05.h: invalid #include directive

    line 40 is:int main(void) {

    and i changed the line into :
    Code:
     void main(void){
    or even
    Code:
    void main(){
    ang again i saw the same error
    please tell me what to do ?
    Last edited by micro_like; 07-01-2016 at 02:40 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Error: C:\cvavreval\inc\usart.h(40), included from: hc05.h: invalid #include directive
    Well look at it.

    #include

    You can't have a bare #include without a filename.

    And yes, int main() is the correct way to declare main, unless you KNOW for sure that you're programming in a free standing environment, and your compiler supports void main.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    @OP: It doesn't look like you have much C experience, maybe you should try to walk before running...

  6. #6
    Registered User
    Join Date
    Jun 2016
    Posts
    6
    may you tell me how could i activate gcc mode in codevision avr,till i do not see any other error, please?

    i agree with you when you say:
    " int main() is the correct way to declare main, unless you KNOW for sure that you're programming in a free standing environment, and your compiler supports void main."

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    At the moment, you have two choices.

    1. Convert your existing code to C89. This is an easy thing to do, if somewhat laborious.

    2. Find/download/integrate the GCC cross-compiler for your particular device. This presumes that the "codevision avr" understands how to use an external toolchain. I browsed the manual for a couple of things, but didn't find anything easy. To be honest, this option is really a support question on the vendor forum, not here.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jun 2016
    Posts
    6

    Arrow just one error

    i corrected my codes and i when i compiled it i saw just this error:Error: C:\cvavreval\inc\usart.h(185), included from: hc05.h: invalid #include directive



    line 185 of usart.h:
    void usart_init();


    then when i check syntax error i saw this error:
    Error: C:\cvavreval\inc\usart.h(272): no matching #endif



    line 272 of usart.h is:
    #endif


    please learn me how change my code.


  9. #9
    Registered User
    Join Date
    Dec 2011
    Location
    Namib desert
    Posts
    94
    You might need to learn the difference between declaration and definition of variables and/or functions. In other words; which code do you put in a .h file and which in a .c file. Also the use of the keyword extern in a .h file.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Does usart.h look like it did in post #1?

    Does it begin with
    Code:
    #ifndef _USART_H_
    #define _USART_H_  1
    It seems to me you managed to trash your usart.h file, by removing the first few lines, and making at least one of the #include lines invalid.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Jun 2016
    Posts
    6
    no i did not remove:
    Code:
    #ifndef	_USART_H_
    #define	_USART_H_ 	1
    but i changed the usart.h to:
    Code:
    //Micricontroller		:All 8-bit AVR Micricontrollers with Similar Register Configuration with ATmega16
    //System Clock			:8 MHz
    //Header File Version 		:1.1
    //Author			:Arun Kumar Garg 
    //				:ABLab Solutions
    //				:www.ablab.in
    //				:[email protected]
    //Date				:1st August 2011
    
    
    /*Copyright (c) 2011 ABLab Solutions All rights reserved.
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    
    
       * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
       * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the 	following disclaimer in the documentation 
         and/or other materials provided with the distribution.
       * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without 
         specific prior written permission.
    
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
    
    
    
    
    /*The functions and macros defined in this header file are for USART of all 8-bit AVR Micricontrollers with Similar Register Configuration 
    with ATmega 16*/
    
    
    #ifndef	_USART_H_
    #define	_USART_H_ 	1
    
    
    
    
    #ifndef COMPILER_H
    #define COMPILER_H
    
    
    /* Since most Avrfreaks users tend to use avr-gcc,  this file should cope with 
     * most compiler differences.
     *
     * Certain avr-gcc "features" need to be handled by macros:
     * e.g.  replace all specific __attribute__() occurrences with CAPITAL() macros
     * auto variables must be declared at the start of a code-block
     * un-named fields in bit structures need naming.
     *
     * All inline assembly and other abortions need to be REMOVED
     * singular assembly ops like nop() or sei() use equivalent NOP() and SEI()
     *
     * CodeVision users must access all flash and eeprom with the gcc macros
     * the sfr.# syntax must be replaced by real C
     * the interrupt service routines should be written as ISR(ISR_vect)
     * with appropriate #defines e.g. #define INT0_vect EXT_INT0
     * I am inclined to add sfr bit-names in module specific files
     * 
     * the obvious solution is to have "project.h" containing "compiler.h" and "bit_names.h"
     *
     * ImageCraft and IAR should be able to adapt quite easily to this format
     *
     * ImageCraft produces a regular COFF file for Studio to debug
     *
     * IAR (KickStart) use DEBUG .d90 for C-SPY ( .dbg for Studio4 )
     */
    
    
    /*#if   defined(__GNUC__)
    #define _mcpu(x) __AVR_ATmega##x##__  // __GNUC__
    
    
    #define SYSCLK            F_CPU
    #include 
    #include 
    #include 
    #include 
    #include 
    #define NOP()            asm volatile("nop\n")
    #define SEI()            asm volatile("sei\n")
    
    
    #elif defined(__CODEVISIONAVR__)
    #define _mcpu(x) 0        // _CHIP_ATMEGA##x##_  no value __CODEVISIONAVR__
    #define F_CPU            _MCU_CLOCK_FREQUENCY_
    #include 
    #include 
    #include 
    #define _BV(x)            (1<<(x))
    #define PGM_P              char flash *
    #define PROGMEM            flash
    #define PSTR(x)            x
    #define pgm_read_byte(x)    (*((uint8_t flash *)(x)))
    #define pgm_read_word(x)    (*((uint16_t flash *)(x)))
    #define EEMEM            eeprom
    #define eeprom_read_byte(ads)    (*((uint8_t eeprom *)(ads)))
    #define eeprom_write_byte(ads,x) (*((uint8_t eeprom *)(ads))) = x
    #define eeprom_write_word(ads,x) (*((uint16_t eeprom *)(ads))) = x
    #define NOP()            #asm("nop")
    #define SEI()            #asm("sei")
    #define _delay_ms        delay_ms
    #define ISR(vec)        interrupt [vec] void isr##vec(void)
    
    
    #elif defined(__IAR_SYSTEMS_ICC__)
    #define _mcpu(x) __ATmega##x##__   	  // __IAR_SYSTEMS_ICC__
    #define ENABLE_BIT_DEFINITIONS
    #include 
    #include 
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PROGMEM 	 	__flash
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t __flash *)(x)))
    #define pgm_read_word(x)	(*((uint16_t __flash *)(x)))
    #define NOP()			__no_operation()
    #define SEI()			__enable_interrupt()
    #define PRAGMA(x)		_Pragma( #x ) 
    #define ISR(num) PRAGMA(vector = num) __interrupt void isr_##num(void)
    
    
    #elif defined(__IMAGECRAFT__)
    #define _mcpu(x) 0			 // ATmega##x // no value
    #include 
    
    
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PROGMEM      		__flash
    #define PSTR(x)			x	   // char __flash *)(x)
    #define pgm_read_byte(x)	(*((uint8_t __flash *)(x)))
    #define pgm_read_word(x)	(*((uint16_t __flash *)(x)))
    #define NOP()			asm("nop")
    #define SEI()			asm("sei")
    #define PRAGMA(x)		_Pragma( #x ) 
    #define ISR(num) PRAGMA(interrupt_handler isr_##num:num) void isr_##num(void)
    
    
    #elif defined(SDCC)
    #define F_CPU			SYSCLK
    #include 
    #include "qsleep.h"
    #define PGM_P  			char code *
    #define PROGMEM			code
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t code *)(x)))
    #define NOP()			_nop_()
    #define _delay_ms		msleep
    
    
    #elif defined(_FEDPICC)
    #define F_CPU			SYSCLK
    #include "qsleep.h"
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PGM_P  			char const *
    #define PROGMEM			const
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t const *)(x)))
    #define NOP()			_nop_()
    #define _delay_ms		msleep
    #else
    #error Compiler not supported
    #endif
    
    
    #endif   */
    
    
    
    
    
    
    #include<io.h>
    #include<delay.h>
    //#include<string.h>
    
    
    /*#include 
    
    
    void main(int) {
      set_sleep_mode(SLEEP_MODE_IDLE);
      sei();
      sleep_mode();}  
      //gcc -std=gnu99 usart.c 
      
    // unsigned char i;  */
    /*The function is declared to initialize the USART with following cinfiguration:-
    USART mode - Asynchronous
    Baud rate - 9600
    Data bits - 8
    Stop bit - 1
    Parity - No parity.*/
    
    
    void usart_init();
    
    
    
    
    
    
    
    
    /*The function is declared to transmit data.*/
    
    
    void usart_data_transmit(unsigned char data );
    
    
    
    
    
    
    
    
    /*The function is declared to receive data.*/
    
    
    unsigned char usart_data_receive( void );
    
    
    
    
    
    
    
    
    /*The function is declared to transmit string.*/
    
    
    void usart_string_transmit(char *string);
    
    
    
    
    
    
    
    
    /*The function is declared to receive string.*/
    
    
    char *usart_string_receive(char *receive_string,unsigned char terminating_character);
    
    
    void main(void){
    while(1){
    }
    }
      
    /*Function defination*/
    
    
    void usart_init()
    {
    UBRRH = 0;
    UBRRL =51;
    UCSRB|= (1<<RXEN)|(1<<TXEN);
    UCSRC|= (1 << URSEL)|(3<<UCSZ0);
    }
    
    
    
    
    void usart_data_transmit(unsigned char data)
    {
    
    
    while ( !( UCSRA & (1<<UDRE)) )
       ;
    UDR = data;
    }
    
    
    unsigned char usart_data_receive()
    {
    while ( !(UCSRA & (1<<RXC)) )
    ;
    return UDR;
    }
    
    
    void usart_string_transmit(char *string)
    {
    while(*string)
    {
    usart_data_transmit(*string++);
    }
    }
     char *usart_string_receive(char *receive_string,unsigned char 
    terminating_character)
    {
    unsigned char temp=0x00;
    unsigned char i;
    
    
    for(i=0;;i++)
    {
    		*(receive_string+i)=usart_data_receive();
    		if(*(receive_string+i)==terminating_character)
    			break;
    		else
    		temp++;
    	}
    	*(receive_string+temp)='\0';
    	return receive_string;
    }
    
    
    #endif
    #endif
    hc05.h to:
    Code:
    //Micricontroller		:All 8-bit AVR Micricontrollers with Similar Register Configuration with ATmega16
    //System Clock			:8 MHz
    //Header File Version 		:1.1
    //Author			:Arun Kumar Garg 
    //				:ABLab Solutions
    //				:www.ablab.in
    //				:[email protected]
    //Date				:1st June 2015
    
    
    /*Copyright (c) 2011 ABLab Solutions All rights reserved.
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    
    
       * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
       * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the 	following disclaimer in the documentation 
         and/or other materials provided with the distribution.
       * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without 
         specific prior written permission.
    
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
    
    
    
    
    /*The functions and macros defined in this header file are for HC-05 Bluetooth Module*/
    
    
    #ifndef	_HC05_H_
    //#if 	HC05_H_
    //#define _HC05_H_
    #define	_HC05_H_ 	1
    
    
    #ifndef COMPILER_H
    #define COMPILER_H
    
    
    /* Since most Avrfreaks users tend to use avr-gcc,  this file should cope with 
     * most compiler differences.
     *
     * Certain avr-gcc "features" need to be handled by macros:
     * e.g.  replace all specific __attribute__() occurrences with CAPITAL() macros
     * auto variables must be declared at the start of a code-block
     * un-named fields in bit structures need naming.
     *
     * All inline assembly and other abortions need to be REMOVED
     * singular assembly ops like nop() or sei() use equivalent NOP() and SEI()
     *
     * CodeVision users must access all flash and eeprom with the gcc macros
     * the sfr.# syntax must be replaced by real C
     * the interrupt service routines should be written as ISR(ISR_vect)
     * with appropriate #defines e.g. #define INT0_vect EXT_INT0
     * I am inclined to add sfr bit-names in module specific files
     * 
     * the obvious solution is to have "project.h" containing "compiler.h" and "bit_names.h"
     *
     * ImageCraft and IAR should be able to adapt quite easily to this format
     *
     * ImageCraft produces a regular COFF file for Studio to debug
     *
     * IAR (KickStart) use DEBUG .d90 for C-SPY ( .dbg for Studio4 )
     */
    
    
    #if   defined(__GNUC__)
    #define _mcpu(x) __AVR_ATmega##x##__  // __GNUC__
    
    
    #define SYSCLK            F_CPU
    #include 
    #include 
    #include 
    #include 
    #include 
    #define NOP()            asm volatile("nop\n")
    #define SEI()            asm volatile("sei\n")
    
    
    #elif defined(__CODEVISIONAVR__)
    #define _mcpu(x) 0        // _CHIP_ATMEGA##x##_  no value __CODEVISIONAVR__
    //#define F_CPU            _MCU_CLOCK_FREQUENCY_
    #include 
    #include 
    #include 
    #define _BV(x)            (1<<(x))
    #define PGM_P              char flash *
    #define PROGMEM            flash
    #define PSTR(x)            x
    #define pgm_read_byte(x)    (*((uint8_t flash *)(x)))
    #define pgm_read_word(x)    (*((uint16_t flash *)(x)))
    #define EEMEM            eeprom
    #define eeprom_read_byte(ads)    (*((uint8_t eeprom *)(ads)))
    #define eeprom_write_byte(ads,x) (*((uint8_t eeprom *)(ads))) = x
    #define eeprom_write_word(ads,x) (*((uint16_t eeprom *)(ads))) = x
    #define NOP()            #asm("nop")
    #define SEI()            #asm("sei")
    #define delay_ms        delay_ms
    #define ISR(vec)        interrupt [vec] void isr##vec(void)
    
    
    #elif defined(__IAR_SYSTEMS_ICC__)
    #define _mcpu(x) __ATmega##x##__   	  // __IAR_SYSTEMS_ICC__
    #define ENABLE_BIT_DEFINITIONS
    #include 
    #include 
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PROGMEM 	 	__flash
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t __flash *)(x)))
    #define pgm_read_word(x)	(*((uint16_t __flash *)(x)))
    #define NOP()			__no_operation()
    #define SEI()			__enable_interrupt()
    #define PRAGMA(x)		_Pragma( #x ) 
    #define ISR(num) PRAGMA(vector = num) __interrupt void isr_##num(void)
    
    
    #elif defined(__IMAGECRAFT__)
    #define _mcpu(x) 0			 // ATmega##x // no value
    #include 
    
    
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PROGMEM      		__flash
    #define PSTR(x)			x	   // char __flash *)(x)
    #define pgm_read_byte(x)	(*((uint8_t __flash *)(x)))
    #define pgm_read_word(x)	(*((uint16_t __flash *)(x)))
    #define NOP()			asm("nop")
    #define SEI()			asm("sei")
    #define PRAGMA(x)		_Pragma( #x ) 
    #define ISR(num) PRAGMA(interrupt_handler isr_##num:num) void isr_##num(void)
    
    
    #elif defined(SDCC)
    #define F_CPU			SYSCLK
    #include 
    #include "qsleep.h"
    #define PGM_P  			char code *
    #define PROGMEM			code
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t code *)(x)))
    #define NOP()			_nop_()
    #define _delay_ms		msleep
    
    
    #elif defined(_FEDPICC)
    #define F_CPU			SYSCLK
    #include "qsleep.h"
    typedef unsigned char uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned long uint32_t;
    typedef signed char int8_t;
    typedef signed short int16_t;
    #define PGM_P  			char const *
    #define PROGMEM			const
    #define PSTR(x)			x
    #define pgm_read_byte(x)	(*((uint8_t const *)(x)))
    #define NOP()			_nop_()
    #define _delay_ms		msleep
    #else
    #error Compiler not supported
    #endif
    
    
    #endif
    
    
    
    
    
    
    #include<io.h>
    #include<delay.h>
    #include<usart.h>
    //#include<string.h>
    
    
    
    
    char hc_05_buffer1[25], hc_05_buffer2[50];
    char temp;
    //unsigned char i;
    void hc_05_bluetooth_transmit_byte(char data_byte);
    char hc_05_bluetooth_receive_byte(void);
    void hc_05_bluetooth_transmit_string(char *transmit_string);
    void hc_05_bluetooth_transmit_command(char *transmit_string);
    char *hc_05_bluetooth_receive_string(char *receive_string, unsigned char terminating_character);
    unsigned char hc_05_bluetooth_at_command_mode_test(void);
    unsigned char hc_05_bluetooth_device_name_change(char *device_name);
    unsigned char hc_05_bluetooth_get_version(void);
    unsigned  char hc_05_bluetooth_change_baud_rate(long int baud_rate);
    unsigned  char hc_05_bluetooth_pin_change(char *new_pin);
    
    
    
    
    void hc_05_bluetooth_transmit_byte(char data_byte)
    {
    	usart_data_transmit(data_byte);
    }
    char hc_05_bluetooth_receive_byte(void)
    {
    	return usart_data_receive();
    }
    void hc_05_bluetooth_transmit_string(char *transmit_string)
    {
    	usart_string_transmit(transmit_string);
    }
    char *hc_05_bluetooth_receive_string(char *receive_string, unsigned char terminating_character)
    {
    	unsigned char temp=0x00; 
        unsigned char i;
    	for( i=0;;i++)
    	{
    		*(receive_string+i)=usart_data_receive();
    		if(*(receive_string+i)==terminating_character)
    			break;
    		else
    			temp++;
    	}
    	*(receive_string+temp)='\0';
    	return receive_string;
    }
    unsigned char hc_05_bluetooth_at_command_mode_test(void)
    {
    	UBRRL=12;
    	delay_ms(500);
    	usart_string_transmit("AT");
    	usart_data_transmit(0x0d);
    	usart_data_transmit(0x0a);
    	usart_string_receive(hc_05_buffer1,0x0d);
    	temp=usart_data_receive();
    	if(!(strcmp(hc_05_buffer1,"OK")))
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    
    
    unsigned  char hc_05_bluetooth_change_baud_rate(long int baud_rate)
    {
    	UBRRL=12;
    	delay_ms(500);
    	
    	if(baud_rate==4800)
    	{
    		usart_string_transmit("AT+UART=4800,0,0");
    	}
    	else if(baud_rate==9600)
    	{
    		usart_string_transmit("AT+UART=9600,0,0");
    	}
    	else if(baud_rate==19200)
    	{
    		usart_string_transmit("AT+UART=19200,0,0");
    	}
    	else if(baud_rate==38400)
    	{
    		usart_string_transmit("AT+UART=38400,0,0");
    	}
    	else if(baud_rate==57600)
    	{
    		usart_string_transmit("AT+UART=57600,0,0");
    	}
    	else if(baud_rate==115200)
    	{
    		usart_string_transmit("AT+UART=115200,0,0");
    	}
    	else if(baud_rate==230400)
    	{
    		usart_string_transmit("AT+UART=230400,0,0");
    	}
    	else if(baud_rate==460800)
    	{
    		usart_string_transmit("AT+UART=460800,0,0");
    	}
    	else if(baud_rate==921600)
    	{
    		usart_string_transmit("AT+UART=921600,0,0");
    	}
    	else if(baud_rate==1382400)
    	{
    		usart_string_transmit("AT+UART=1382400,0,0");
    	}
    	else
    	{
    		;
    	}
    	usart_data_transmit(0x0d);
    	usart_data_transmit(0x0a);
    	usart_string_receive(hc_05_buffer1,13);
    	temp=usart_data_receive();
    	
    	if(!(strcmp(hc_05_buffer1,"OK")))
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    
    
    unsigned char hc_05_bluetooth_device_name_change(char *device_name)
    {
    	UBRRL=12;
    	delay_ms(500);
    	
    	usart_string_transmit("AT+NAME=");
    	usart_string_transmit(device_name);
    	usart_data_transmit(0x0d);
    	usart_data_transmit(0x0a);
    	
    	usart_string_receive(hc_05_buffer1,13);
    	temp=usart_data_receive();
    	
    	if(!(strcmp(hc_05_buffer1,"OK")))
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    	
    
    
    unsigned char hc_05_bluetooth_get_version(void)
    {
    unsigned char i=9,j=0;
    
    
    UBRRL=12;
    delay_ms(500);
    	usart_string_transmit("AT+VERSION?");
    	usart_data_transmit(0x0d);
    	usart_data_transmit(0x0a);
    	
    	usart_string_receive(hc_05_buffer2,13);
    	temp=usart_data_receive();
    	
    	usart_string_receive(hc_05_buffer1,13);
    	temp=usart_data_receive();
    		
    	for(i=9;hc_05_buffer2[i]!=0;i++)
    	{
    		hc_05_buffer2[j]=hc_05_buffer2[i];
    		j++;
    	}
    	hc_05_buffer2[j]=0;
    	
    	if(!(strcmp(hc_05_buffer1,"OK")))
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    
    
    unsigned  char hc_05_bluetooth_pin_change(char *new_pin)
    {
    	UBRRL=12;
    	delay_ms(500);
    	
    	usart_string_transmit("AT+PSWD=");
    	usart_string_transmit(new_pin);
    	usart_data_transmit(0x0d);
    	usart_data_transmit(0x0a);
    	
    	usart_string_receive(hc_05_buffer1,13);
    	temp=usart_data_receive();
    	
    	if(!(strcmp(hc_05_buffer1,"OK")))
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    
    
    
    
    #endif
    so when i compile it i see this error:
    Error: C:\cvavreval\inc\usart.h(185), included from: hc05.h: invalid #include directive
    the line 185 of usart.h is:
    Code:
    void usart_init();
    and when i select check syntax i see nothing,please learn me what to do and how change my codes till i do not see any other error.





  12. #12
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Quote Originally Posted by micro_like View Post
    so when i compile it i see this error:
    Code:
    Error: C:\cvavreval\inc\usart.h(185), included from: hc05.h: invalid #include directive
    the line 185 of usart.h is:
    Code:
    void usart_init();
    and when i select check syntax i see nothing,please learn me what to do and how change my codes till i do not see any other error.
    It looks like the compiler mean the file hc05.h, because the line 185 (in your quotes it is 187) in that file is:
    Code:
    #include <usart.h>
    I think the compiler can't find the file, because the include uses angle brackets.
    Angle brackets will be used for header files that are in the library path. But usart.h is not a standard header file.
    If this file is in the same directory as hc05.h, you should use:
    Code:
    #include "usart.h"
    Check this please.

    Another point that me confusing is that you have functions definitions in a header file.
    Line 209 in usart.h is a function declaration.
    Code:
    void usart_init();
    Line 268 - 274 in usart.h is a function definition! This should go into a c-file.
    Code:
    void usart_init()
    {
        UBRRH = 0;
        UBRRL = 51;
        UCSRB |= (1 << RXEN) | (1 << TXEN);
        UCSRC |= (1 << URSEL) | (3 << UCSZ0);
    }
    And last, can you explain this lines? (260 - 263 in usart.h)
    Code:
    void main(void){
    while(1){
    }
    }
    Anyway, I don't look further. I don't know if there are other problems.
    Other have classes, we are class

  13. #13
    Registered User
    Join Date
    Jun 2016
    Posts
    6
    i really appreciate you i changed my codes by your explanations and error disappeared.In fact i made separate c files of usart and hc05 and i add it to my main project and i removed
    Code:
    void main(void){
    while(1){
    }
    }
    
    from usart.h

    and also i changed:
    Code:
    #include<hc05.h>
    to:
    Code:
    #include"hc05.h"
    i mean line13 of hc11.c
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't see errors, can you?
    By stustu92 in forum C Programming
    Replies: 4
    Last Post: 02-01-2006, 06:11 AM
  2. win errors
    By rajesh23 in forum Tech Board
    Replies: 1
    Last Post: 10-10-2003, 04:35 AM
  3. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM
  4. help with errors...
    By Gamma in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2002, 07:11 PM
  5. Why so many errors??
    By shawhiz in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2002, 06:06 PM