Vou usar como exemplo a biblioteca da serial do C18.
Bem, para que eu use a função getsUSART no meu programa, basta que eu inclua no cabeçalho o arquivo usart.h.
Abrindo o usart.h , como ele é um arquivo hearder, vou encontrar apenas a declaração da função, está lá:
void getsUSART ( char *buffer, unsigned char len);
Não existe nele nada sobre como a função é implementada.
Procurando dentro do diretório do compilador C18, encontrei um arquivo chamado ugets que contém a implementação da função getsUSART, segue o arquivo:
- Código: Selecionar todos
#include <p18cxxx.h>
#include <usart.h>
/********************************************************************
* Function Name: getsUSART *
* Return Value: void *
* Parameters: buffer: pointer to string *
* len: length of characters to receive *
* Description: This routine receives a string of characters *
* from the USART of length specified by len. *
********************************************************************/
#if defined (AUSART_V1) || defined (EAUSART_V3) || defined (EAUSART_V4) || defined (EAUSART_V5)
void getsUSART(char *buffer, unsigned char len)
{
char i; // Length counter
unsigned char data;
for(i=0;i<len;i++) // Only retrieve len characters
{
while(!DataRdyUSART());// Wait for data to be received
data = getcUSART(); // Get a character from the USART
// and save in the string
*buffer = data;
buffer++; // Increment the string pointer
}
}
#endif
A pergunta é: Em usart.h não existe ou pelo menos não encontrei nenhuma menção ao arquivo ugets, como a função é então encontrada pelo compilador?