Dosyć podstawowa funkcja c, jak dodawanie własnych modułów trochę mi nie trybi. Wydłubałem z głównego pliku funkcje odpowiadające za bardziej uniwersalne funkcje układu. Oto jak includuję:
zawartość os.h:
Następnie w os.c:
No i problem podczas kompilacji:
Oraz dla każdej użytej funkcji z mojego modułu. Innych błędów nie ma. Co więc robię źle?
#include "..\os\os.h"
int main()
{
USART_init(baud(9600));
[....]
return 666;
}
zawartość os.h:
#ifndef __OS__
#define __OS__
#include <avr/io.h>
#include <stdint.h>
#include <util/delay.h>
#define baud(x) (F_CPU/(16UL*(x)))-1
#define true -1
#define false 0
void USART_init(int baudrate);
unsigned char USART_receive();
void USART_transmit(unsigned char chr);
static void w84data(const char* cmpwith);
static void senddata(const char* tosend);
#endif
Następnie w os.c:
#include "os.h"
void USART_init(int baudrate)
{
UBRRH = (unsigned char)(baudrate>>8);
UBRRL = (unsigned char)baudrate;
UCSRB = (1 << RXEN) | (1 << TXEN);
UCSRC = (3 << UCSZ0) | (1 << USBS);
}
unsigned char USART_receive()
{
while (!(UCSRA & (1 << RXC)));
return UDR;
}
void USART_transmit(unsigned char chr)
{
while(!(UCSRA & (1 << UDRE)));
UDR=chr;
}
static void w84data(const char* cmpwith)
{
const char* sptr = cmpwith;
while(*sptr)
if(*sptr++ != USART_receive())
sptr = cmpwith;
}
static void senddata(const char* tosend)
{
while(*tosend)
USART_transmit(*tosend++);
}
No i problem podczas kompilacji:
Kompilator wrote:station_tester.c.text+0x4): undefined reference to `USART_init'
Oraz dla każdej użytej funkcji z mojego modułu. Innych błędów nie ma. Co więc robię źle?