Hi I'm working on watchdog but I'm bit confused It show me some errors. I'm using AVR(AVR128DB48).
Errors:
WDTO_4S' undeclared (first use in this function)
recipe for target 'main.o' failed
code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
int main(void)
{
wdt_enable(WDTO_4S);
while(1)
{
wdt_reset();
}
return(0);
}
Never used this part, but I can do a quick Google search. From the inline documentation the header itself:
#define WDTO_4S 8
Note: This is only available on the ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88.
See Here
Related
So I'm making a function called reboot, but when I define it the compiler gives an error like the function is already defined.
Here is bios.c:
#include "bios.h"
#include <stdint.h>
#include <libasm/asm.h>
void reboot()
{
uint8_t good = 0x02;
while (good & 0x02)
good = EmeraldASM_inb(0x64);
EmeraldASM_outb(0x64, 0xFE);
asm volatile("hlt");
}
here is bios.h :
#ifndef BIOSPOWER_H
#define BIOSPOWER_H
#pragma once
void reboot();
extern void shutdown();
#endif
here is the compiler error: /home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: multiple definition of `reboot'; src/firmware/bios.o:/home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: first defined here
Here is my Makefile:
https://pastebin.com/xCcQEtx3
The problem was that my assembly file had the name bios.asm, so it created two bios.o that was what caused the error (thanks to Eric Postpischil)
I am working on STM32F1 on IAR, I write a weak function using
__attribute__((weak))
main.c
#include "tmp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int testfunc1(int a)
{
return true;
}
int main(void)
{
while (1)
{
}
}
tmp.h
#include <stdio.h>
#include <stdlib.h>
int testfunc1(int a);
tmp.c
#include "tmp.h"
__attribute__((weak)) int testfunc1(int a)
{
}
It compiles with errors:
Error[Pe079]: expected a type specifier
Warning[Pe606]: this pragma must immediately precede a declaration
Error[Pe260]: explicit type is missing ("int" assumed)
Error[Pe141]: unnamed prototyped parameters not allowed when body is present
Error[Pe130]: expected a "{"
Error while running C/C++ Compiler
However, if I use __weak instead of attribute((weak)), it works normally as expected.
tmp.c
#include "tmp.h"
__weak int testfunc1(int a)
{
}
.
Warning[Pe940]: missing return statement at end of non-void function "testfunc1"
Done. 0 error(s), 1 warning(s)
So, why is attribute((weak)) not working?
IAR compiler has its own extensions to archive it:
#pragma
__weak
I strongly suggest to put some effort and read the compiler documentation before posting questions here.
why __attribute__((weak)) in IAR can't compile?
why is attribute((weak)) not working?
Because it's not supported by the version of IAR compiler you are using.
I believe most "why" questions are bad question. An answer to "why" something happens is either too broad (requires to explain everything) or too vague (because this is how it is). In this case your compiler just doesn't support that specific syntax. To further investigate "why" exactly the IAR Systems company decided not to implement support for that particular syntax for that IAR compiler version, ask that company.
Does the header file couldn't include another header file in C?
I download the code from Nuvoton website, for Keil C51 project, use the UART sample code, just add the file "EasyTransfer.h" and include "Typedef.h", the result shows lots of error message below.
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(1): error C231: 'BIT': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(2): error C231: 'UINT8': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(3): error C231: 'UINT16': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(4): error C141: syntax error near 'UINT32'
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(6): error C231: 'uint8_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(7): error C231: 'uint16_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(8): error C141: syntax error near 'uint32_t'
The "EasyTransfer.h" is simple, just few of lines
#ifndef EasyTransfer_h
#define EasyTransfer_h
#include "Typedef.h"
uint8_t * address; //address of struct
#endif
The following is the main code and source link, I think it could be helpful to understand my question.
#define Uart_Port_Sel 0x00
#include <stdio.h>
#include "N79E85x.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "Version.h"
#include "EasyTransfer.h"
UINT8 u8Uart_Data;
//-----------------------------------------------------------------------------------------------------------
void main (void)
{
AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
InitialUART0_Timer1(9600); // 9600 Baud Rate # 11.0592MHz
Show_Version_Number_To_PC();
ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
while(1); // Endless
}
//-----------------------------------------------------------------------------------------------------------
void UART_ISR(void) interrupt 4
{
if (RI == 1)
{ // If reception occur
RI = 1; // Clear reception flag for next reception
u8Uart_Data = SBUF; // Read receive data
SBUF = u8Uart_Data; // Send back same data on UART
}
else TI = 0; // If emission occur
// Clear emission flag for next emission
}
You should not include Typedef.h multiple times since there is no header include guard in Typedef.h.
Your main source includes Typedef.h and EasyTransfer.h at the same time, this causes redefinition errors because EasyTransfer.h includes Typedef.h too. Just like your main source includes Typedef.h twice, and WITHOUT header include guard!
I suggest you just remove the #include "Typedef.h" line from your main source file. Or add header include guard in Typedef.h if you can.
Im sure Im missing something simple, and obvious, but I am tired of searching for the answer. Im using a PIC16F688 and XC8 compiler.
The compiler user manual says that there is a delay function __delay_ms(). It says that _XTAL_FREQ must be defined.
Here is my code, but it does not accept the command. What is wrong?
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 20000000
#include<xc.h>
int main(int argc, char** argv) {
_delay_ms(4);
return (EXIT_SUCCESS);
They are right, the problem was experienced by older versions of the IDE's. I have found it helpful to use:
while(1){
//Invert LED state
LED = !LED;
//Delay ~1 second (4MHz Internal Clock)
_delay(1000000); //specify clock cycles directly
}
To solve the problem.
Please include "htc.h"
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <htc.h>
#define _XTAL_FREQ 20000000
int main(int argc, char** argv) {
_delay_ms(4);
return (EXIT_SUCCESS);
}
What does it mean "it does not accept the command"? Compiler cannot find function _delay_ms()? Maybe you should use proper name with two underscores __delay_ms()?
Moreover, why you do not close main function with }? It is only a typo in your post or in your real code?
May be you have to include or enable pic Controller library file in your compiler.
In some compiler meed to give controller info like controller series and clock frequency using ect.,
It seems problem with compiler setting.
I discovered that the IDE wasnt correctly reading the include file xc.h, so it was red lining a line that was actually correct. It wasnt compiling due to another issue earlier in the program.
Thank you for the responses.
It seems like you used only ONE UNDERSCORE for the function. Use 2 underscore, __delay_ms(1000);
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#define _XTAL_FREQ 20000000
int main(int argc, char** argv) {
__delay_ms(4);
return (EXIT_SUCCESS);
}
I hope that the following link will help you to learn MPLAB XC8.
PIC Microcontroller Tutorials using MPLAB XC8
maybe try this directly
//Delay Definitions
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
I have second level include that is giving me grief:
Undefined first referenced
symbol in file
function2 /var/tmp//ccAPaWbT.o
ld: fatal: symbol referencing errors. No output written to run
collect2: ld returned 1 exit status
Main file:
#include "functions02.c"
int main(){
int x = funcion2();
}
functions02.c file:
#ifndef FUNCTIONS02_C
#define FUNCTIONS02_C
int funcion2();
#if __INCLUDE_LEVEL__ == 0
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include "functions01.c"
int main() {
return function2();
}
#endif
int function2()
return function1();
}
#endif
functions01.c file:
#ifndef FUNCTIONS01_C
#define FUNCTIONS01_C
int funcion1();
#if __INCLUDE_LEVEL__ == 0
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main() {
return function1();
}
#endif
int function1()
return 10;
}
#endif
I am assuming that this can be fixed manipulated using __INCLUDE_LEVEL__ or manipulating linking on gcc compiling but I can't find forking variant.
First of all is it possible to achieve what I am looking for without putting functions in external header files?
Second what would be the correct way of doing it?
EDIT:
I realized that I had forgotten to add function dependencies to them. That is the includes which are used by functions can not be excluded by adding them just next to main function warped in exclusion if close.
Yes, it is possible to include / exclude any part of the code using compile time flags (and in the code using #if's) as you are trying to do.
In your case, I assume you have not defined __INCLUDE_LEVEL__ flag, hence the linker is not able to find funciton2, so the error.
If you define it, you will have three "main()" :-), it will fail again. So, you need to rework your code a bit.
Also, #include'ing a "C" file is not advisable and not used in practice. I assume you are just trying to experiment & learn, which is fine.