|
|
View previous topic :: View next topic |
Author |
Message |
johenrod
Joined: 05 Oct 2020 Posts: 8
|
Error when compiling to a port from a function |
Posted: Sat Apr 13, 2024 8:33 pm |
|
|
Cordial saludo, se que les puede parecer muy basico pero no encuentro la solucion.
he creado una funcion en una libreria .h y al compilar me muestra erores, dejo el codigo.(ccs)
Gracias de antemano.
Best regards, I know it may seem very basic to you but I can't find the solution.
I have created a function in a .h library and when compiling it shows me errors, I leave the code. (ccs)
Thanks in advance.
Code: | #include <16F628A.h>
//#device ADC=16
//#FUSES NOWDT //No Watch Dog Timer
//#FUSES NOBROWNOUT //No brownout reset
//#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
//#use delay(internal=4000000)
//#define LED PIN_A0
// #include <funciones.c>
#include <funci.h>
//#include <16F628a.h>
#FUSES NOWDT
#FUSES NOMCLR
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES PROTECT
#use delay(internal=4MHz)
//#use RS232 (baud = 9600, bits = 8, parity = N, xmit = pin_a0, rcv = pin_a1)
//#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,stream=RF1,errors)
#define NO_ANALOGS 0 // None
#define BDIR PIN_A7
#define BC1 PIN_A6
void sonido(unsigned char registro,unsigned char valor);
#byte porta= 0x05
#byte portb= 0x06
#byte trisa= 0x85
#byte trisb= 0x86
//declaracion ariables globales
unsigned CHAR value=0;
unsigned char x=0;
// const unsigned char tone[] = {0x13, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00};
// void sound_play_song(unsigned char length, unsigned char song[]);
// void sound_register(unsigned char regnum, unsigned char value[]);
// protipos funciones
void set_mode_inactive();
void set_mode_latch();
void set_mode_write();
void set_mode_write();
void write_register(char reg, char value);
void main()
{
SET_TRIS_A(0B00100000);
SET_TRIS_B(0B00000000);
porta=0x00;
portb=0x00;
// set_mode_inactive();
while(TRUE)
{
write_register(0, 223);
write_register(1, 1);
delay_ms(500);
}
} |
Code: | //funciones
void set_mode_inactive()
{
output_low(BC1);
output_low(BDIR);
}
void set_mode_latch()
{
output_high(BC1);
output_high(BDIR);
}
void set_mode_write()
{
output_low(BC1);
output_high(BDIR);
}
void write_register(char reg, char value)
{
set_mode_latch();
PORTB = reg;
set_mode_inactive();
set_mode_write();
PORTB = value;
set_mode_inactive();
} |
[/list]Compiling C:\Users\zolution\Desktop\code4\code3 on 13-abr-24 at 20:12
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 6(26,29): Undefined identifier BC1
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 7(26,30): Undefined identifier BDIR
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 12(27,30): Undefined identifier BC1
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 13(27,31): Undefined identifier BDIR
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 18(26,29): Undefined identifier BC1
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 19(27,31): Undefined identifier BDIR
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 25(15,20): Undefined identifier PORTB
*** Error 12 "C:\Users\zolution\Desktop\code4\funci.h" Line 28(15,20): Undefined identifier PORTB
8 Errors, 0 Warnings.
Build Failed. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Sat Apr 13, 2024 11:50 pm |
|
|
Very simple. Order.....
The compiler reads things in the order they are declared. Now, look
where you load 'funci.h'. Then look where you declare BDIR and BC1.
So these definitions _have not yet been read_, when you load funci.h.
Result the errors (and the same for the port definitions.
Develop an order to your code:
Chip include
Fuses
Clock settings
Global defines & declarations.
Function includes or prototypes.
Main code.
Now you will note I say 'or prototypes'. In C, you can include a
prototype definition for a function, and then only include the actual
code later. Key thing is though that in every case, the declarations of
things must always be _before_ they are actually used. |
|
|
johenrod
Joined: 05 Oct 2020 Posts: 8
|
|
Posted: Thu Apr 18, 2024 8:25 am |
|
|
Tiene sentido, reordene el codigo y compilo.
Muchas gracias.
It makes sense, reorder the code and compile.
Thank you so much. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|