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:
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.