Hello,
I'm new on Arduino.
can I write my own .c and .h files and use them with main.pde project?
Here is what I did:
1/ I wrote funcion void tonTimer(T_TMR *t) and store it to file FC060.c
2/ I wrote line extern void tonTimer(T_TMR t); and store it to file FC060.h
3/ I included #include "FC060.h" in file main.pde and
I called this function tonTimer(&tmr1); but I got compiling error
undefined reference to 'tonTimer(T_TMR)'
What's wrong ? Files FC060.c, FC060.h, main.pde are compiled OK when I delete line tonTimer(&tmr1);
/*
file: FC060.c
project:
device:
date:
desc.: software timer
*/
#include "FC060.h"
#include <avr/io.h>
T_TMR tmr1;
T_TMR tmr2;
void tonTimer(T_TMR *t)
{
unsigned char sb ;
unsigned char value;
unsigned char preset;
sb = t-> sb;
value = t-> value;
preset = t-> preset;
if (sb==_BV(EN)){
sb = (_BV(EN) || BV(RUN));
value = preset;
}
if (bit_is_set(sb,RUN)){
if (TMR_BIT){
value--;
if (value==0){
sb = _BV(CPL);
}
}
}
t-> sb = sb;
t-> value = value;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*
file: FC060.h
project:
device:
date:
desc.: header file for software timer
*/
#ifndef _FC060_H
#define _FC060_H
#include <avr/io.h>
#define EN (0)
#define RUN (1)
#define CPL (2)
#define TMR_BIT (bit_is_set(ip,0))
// uint8_t ip is defined in main skatch
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// software timer data
typedef struct {
unsigned char sb ; // holds flags
unsigned char value; // is value
unsigned char preset; // init value
} T_TMR;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
extern T_TMR tmr1;
extern T_TMR tmr2;
extern uint8_t ip ;
extern void tonTimer(T_TMR *t);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#endif _FC060_H
// file main.pde
//
#include <avr/io.h>
#include "FC060.h"
uint8_t ip= 0;
// void setup()
//
//
void setup()
{
tmr1.sb = _BV(EN);
tmr1.preset = 20;
}
void loop()
{
tonTimer( &tmr1);
}