Hello Mr. Aswinth Raj,
As a total beginner I tried to compile the source code to your above mentioned PIC project, in MPLAB X vers.5.10 and the compiler Free XC 8 vers 2.00, which I did not succeed. I did not change anything about the code. I have attached a screenshot of the errors here. What am I doing wrong.
Yours sincerely
Herbert Wichmann
In reply to Generation of PWM signals on GPIO pins of the PIC microcontrolle by Herbert Wichmann
Permalink
The error message is
main.c:50:6: error: variable has incomplete type 'void'
did you make any changes to the code?
Hello Mr. Aswinh,
Thank you for your feedback and help.
No, I have not changed the code, I lack the experience. I have marked the main.c and lcd.h code on your page and copied both in Nodpat + and then the two code in MPLAB X. I have here both code as I have inserted them in MPLAB X Inserted.
I would be glad to receive further help from you.
Yours sincerely
Herbert Wichmann
/*
* Program to Control Robotic Arm through POT
* 5 Servo controlled with Timer Register PWM
* Dated: 15-1-2019
* Web: www.circuitdigest.com
* Author: B.Asiwnth Raj
*/
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define _XTAL_FREQ 20000000 //Crystak Freq is 20MHz
#define PWM_Frequency 0.05 // in KHz (50Hz)
//Define LCD pins
#define RS RB1
#define EN RB2
#define D4 RB3
#define D5 RB4
#define D6 RB5
#define D7 RB6
#include <xc.h>
#include "lcd.h" //Header for using LCD module
int POT_val; //variable to store value from ADC
int count; //timer variable
//int T_TOTAL = (1/PWM_Frequency); //calculate Total Time from frequency (in milli sec)) //20msec
int Duty_cycle; //Duty cycle value
int T_ON[4];
char servo;
void ADC_Initialize() //Prepare the ADC module
{
ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
ADCON1 = 0b11000000; // Internal reference voltage is selected
}
unsigned int ADC_Read(unsigned char channel) //Read from ADC
{
ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered due to timer overflow -> set to overflow for every 0.05ms
{
TMR0 = 248; //Load the timer Value
TMR0IF=0; // Clear timer interrupt flag
count++; //Count increments by 1 for every 0.05ms
}
int servo_code[] = {0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000100 };
if (count >= 20*20)
count=0;
if (count <= (T_ON[servo]) )
PORTD = PORTD | servo_code[servo];
else
PORTD = PORTD & ~(servo_code[servo]);
}
void main()
{
/*****Port Configuration for Timer ******/
OPTION_REG = 0b00000100; // Timer0 with external freq and 32 as prescalar // Also Enables PULL UPs
TMR0=248; // Load the time value for 0.0001s; delayValue can be between 0-256 only
TMR0IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
/***********______***********/
/*****Port Configuration for I/O ******/
TRISB = 0x00; //PORT B is output since LCd is connected
PORTB=0x00; //Initialize all pins to 0
TRISD = 0x00; //PORT D is output since servo is connected
PORTD=0x00; //Initialize all pins to 0
/***********______***********/
Lcd_Start(); //Initialize LCD module
ADC_Initialize(); //Initialize ADC module
// Lcd_Clear();
// Lcd_Set_Cursor(1,1);
//Lcd_Print_String("Circuit Digest");
//Lcd_Set_Cursor(2,1);
//Lcd_Print_String("WORKING!!");
//__delay_ms(500);
while(1)
{
for (int pot_num=0; pot_num<=3; pot_num++)
{
int Pev_val = T_ON[pot_num];
POT_val = (ADC_Read(pot_num)); //Read the value of POT using ADC
Duty_cycle = (POT_val * 0.0976); //Map 0 to 1024 to 0 to 100
T_ON[pot_num] = Duty_cycle* 0.4;//((Duty_cycle * T_TOTAL) / 1000)*10; //Calculate On Time from 0ms to 2ms for 0-100 Duty Cycle //*10 is multiplication factor
if (T_ON[pot_num] != Pev_val)
{
Lcd_Clear();
servo = pot_num;
Lcd_Set_Cursor(2,11); Lcd_Print_String("S:");Lcd_Print_Char(servo+'0');
if (pot_num==0)
{Lcd_Set_Cursor(1,1); Lcd_Print_String("A:");}
else if (pot_num==1)
{Lcd_Set_Cursor(1,6); Lcd_Print_String("B:");}
else if (pot_num==2)
{Lcd_Set_Cursor(1,11); Lcd_Print_String("C:");}
else if (pot_num==3)
{Lcd_Set_Cursor(2,1); Lcd_Print_String("D:");}
else if (pot_num==4)
{Lcd_Set_Cursor(2,6); Lcd_Print_String("E:");}
char d2 = (Duty_cycle) %10;
char d1 = (Duty_cycle/10) %10;
Lcd_Print_Char(d1+'0');Lcd_Print_Char(d2+'0');
}
}
}
}
/*
* File: Header file to interface LCD with PIC16F877A
* Author: B.Aswinth Raj
* More details on: https://circuitdigest.com/microcontroller-projects/16x2-lcd-interfacing…
* Created on 5 May, 2018, 6:43 PM
*/
/*SAMPLE CODE
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Print_String("Circuit Digest");
Lcd_Set_Cursor(2,1);
Lcd_Print_Char(temp+'0');
/END OF SAMPL*/
void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines
{
if(data_bit& 1)
D4 = 1;
else
D4 = 0;
if(data_bit& 2)
D5 = 1;
else
D5 = 0;
if(data_bit& 4)
D6 = 1;
else
D6 = 0;
if(data_bit& 8)
D7 = 1;
else
D7 = 0;
}
void Lcd_Cmd(char a)
{
RS = 0;
Lcd_SetBit(a); //Incoming Hex value
EN = 1;
__delay_ms(4);
EN = 0;
}
Lcd_Clear()
{
Lcd_Cmd(0); //Clear the LCD
Lcd_Cmd(1); //Move the curser to first position
}
void Lcd_Set_Cursor(char a, char b)
{
char temp,z,y;
if(a== 1)
{
temp = 0x80 + b - 1; //80H is used to move the curser
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
}
else if(a== 2)
{
temp = 0xC0 + b - 1;
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
}
}
void Lcd_Start()
{
Lcd_SetBit(0x00);
for(int i=1065244; i<=0; i--) NOP();
Lcd_Cmd(0x03);
__delay_ms(5);
Lcd_Cmd(0x03);
__delay_ms(11);
Lcd_Cmd(0x03);
Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
Lcd_Cmd(0x08); //Select Row 1
Lcd_Cmd(0x00); //Clear Row 1 Display
Lcd_Cmd(0x0C); //Select Row 2
Lcd_Cmd(0x00); //Clear Row 2 Display
Lcd_Cmd(0x06);
}
void Lcd_Print_Char(char data) //Send 8-bits through 4-bit mode
{
char Lower_Nibble,Upper_Nibble;
Lower_Nibble = data&0x0F;
Upper_Nibble = data&0xF0;
RS = 1; // => RS = 1
Lcd_SetBit(Upper_Nibble>>4); //Send upper half by shifting by 4
EN = 1;
__delay_us(40);//for(int i=2130483; i<=0; i--) NOP();
EN = 0;
Lcd_SetBit(Lower_Nibble); //Send Lower half
EN = 1;
__delay_us(40);//for(int i=2130483; i<=0; i--) NOP();
EN = 0;
}
void Lcd_Print_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd_Print_Char(a[i]); //Split the string using pointers and call the Char function
}
Hello Mr. Aswinth,
sorry I have the wrong code Beigegestellt, here is the code main.c to the problem.
Many Thanks
Herbert Wichmann
/*
* File: PIC_GPIO_PWM.c
* Author: Aswinth
*
* Created on 17 October, 2018, 11:59 AM
*/
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#define _XTAL_FREQ 20000000
#define PWM_Frequency 0.05 // in KHz (50Hz)
//TIMER0 8-bit with 64-bit Prescalar
//$$RegValue = 256-((Delay * Fosc)/(Prescalar*4)) delay in sec and Fosc in hz ->Substitute value of Delay for calculating RegValue
int POT_val; //variable to store value from ADC
int count; //timer variable
int T_TOTAL = (1/PWM_Frequency)/10; //calculate Total Time from frequency (in milli sec)) //2msec
int T_ON=0; //value of on time
int Duty_cycle; //Duty cycle value
void ADC_Initialize() //Prepare the ADC module
{
ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
ADCON1 = 0b11000000; // Internal reference voltage is selected
}
unsigned int ADC_Read(unsigned char channel) //Read from ADC
{
ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered due to timer overflow -> set to overflow for every 0.1ms
{
TMR0 = 248; //Load the timer Value
TMR0IF=0; // Clear timer interrupt flag
count++; //Count increments for every 0.1ms -> count/10 will give value of count in ms
}
if (count <= (T_ON) )
RD1=1;
else
RD1=0;
if (count >= (T_TOTAL*10) )
count=0;
}
void main()
{
/*****Port Configuration for Timer ******/
OPTION_REG = 0b00000101; // Timer0 with external freq and 64 as prescalar // Also Enables PULL UPs
TMR0=248; // Load the time value for 0.0001s; delayValue can be between 0-256 only
TMR0IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
/***********______***********/
/*****Port Configuration for I/O ******/
TRISD = 0x00; //Instruct the MCU that all pins on PORT D are output
PORTD=0x00; //Initialize all pins to 0
/***********______***********/
ADC_Initialize();
while(1)
{
POT_val = (ADC_Read(0)); //Read the value of POT using ADC
Duty_cycle = (POT_val * 0.0976); //Map 0 to 1024 to 0 to 100
T_ON = ((Duty_cycle * T_TOTAL)*10 / 100); //Calculate On Time using formulae unit in milli seconds
__delay_ms(100);
}
}
Hi Mike,
it's about the main code of Mr. Aswinth Raj
which can not be compiled as previously described by me.
Greeting Herbert Wichmann
Hello everyone,
can not anyone help me with my problem?
See my post about it. I get the program Just not compiled.
I still have almost no idea about the PIC in C programming, but I would like to get that program started. I know that I still have a lot of learning and thanks to this forum will also learn. Mr. Aswinth writes "
The error message is
main.c: 50: 6: error: variable has incomplete type 'void'
Did you change the code?
No I did not change the code what does the error message mean? Where can I search and fix the error.
Many Thanks
Greeting Herbert
In reply to Generation of PWM signals on GPIO pins of the PIC microcontrolle by Herbert Wichmann
Permalink
variable has incomplete type 'void'
The error is because of a half written code. Most likely when you copied the code from the website and pasted in MPLAB you missed out few lines. It should be a semi-colon or something which did not terminate a funtion or variable declaration.
It might sound rude but I should say this, never ever copy a code without understanding it. No code runs without error on first compilation and you will not be able to debug a program unless you understand how it works.
Also when asking questions on forums, use the complete code or the segment of the code in which you are getting error. In MPLABX the console will show you in whichline you are getting the error
Hello Mr. Jayant,
thanks for your feedback,
No that is not rude of you, if you tell me as a total beginners how I should proceed or should proceed.
Now for the code, he has provided Aswinth Raj with hardware and description for learning purposes for beginners in the Totural. Mr. Aswinth has put a lot and understandable good in the tutorial for PIC Prgrammierung in C for beginners. I would really like to find the bug in spite of my little knowledge in the code, especially since I also built up the hardware on a breadboard. For me as a beginner it helps a lot if I try out ready cods with the hardware and expire. So I'm going to add the original Full Code again, and the errors Meldund after compile here with.
Maybe a specialist knows quickly where and what the fault is.
Thank you for your understanding and help
Yours sincerely
Herbert Wichmann
/*
* File: PIC_GPIO_PWM.c
* Author: Aswinth
*
* Created on 17 October, 2018, 11:59 AM
*/
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#define _XTAL_FREQ 20000000
#define PWM_Frequency 0.05 // in KHz (50Hz)
//TIMER0 8-bit with 64-bit Prescalar
//$$RegValue = 256-((Delay * Fosc)/(Prescalar*4)) delay in sec and Fosc in hz ->Substitute value of Delay for calculating RegValue
int POT_val; //variable to store value from ADC
int count; //timer variable
int T_TOTAL = (1/PWM_Frequency)/10; //calculate Total Time from frequency (in milli sec)) //2msec
int T_ON=0; //value of on time
int Duty_cycle; //Duty cycle value
void ADC_Initialize() //Prepare the ADC module
{
ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
ADCON1 = 0b11000000; // Internal reference voltage is selected
}
unsigned int ADC_Read(unsigned char channel) //Read from ADC
{
ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered due to timer overflow -> set to overflow for every 0.1ms
{
TMR0 = 248; //Load the timer Value
TMR0IF=0; // Clear timer interrupt flag
count++; //Count increments for every 0.1ms -> count/10 will give value of count in ms
}
if (count <= (T_ON) )
RD1=1;
else
RD1=0;
if (count >= (T_TOTAL*10) )
count=0;
}
void main()
{
/*****Port Configuration for Timer ******/
OPTION_REG = 0b00000101; // Timer0 with external freq and 64 as prescalar // Also Enables PULL UPs
TMR0=248; // Load the time value for 0.0001s; delayValue can be between 0-256 only
TMR0IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
/***********______***********/
/*****Port Configuration for I/O ******/
TRISD = 0x00; //Instruct the MCU that all pins on PORT D are output
PORTD=0x00; //Initialize all pins to 0
/***********______***********/
ADC_Initialize();
while(1)
{
POT_val = (ADC_Read(0)); //Read the value of POT using ADC
Duty_cycle = (POT_val * 0.0976); //Map 0 to 1024 to 0 to 100
T_ON = ((Duty_cycle * T_TOTAL)*10 / 100); //Calculate On Time using formulae unit in milli seconds
__delay_ms(100);
}
}
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Pauline/MPLABXProjects/Test f�r R�ckantwort PWM Servo am 28.3.19.X'
make -f nbproject/Makefile-default.mk dist/default/production/Test_f_r_R_ckantwort_PWM_Servo_am_28.3.19.X.production.hex
make[2]: Entering directory 'C:/Users/Pauline/MPLABXProjects/Test f�r R�ckantwort PWM Servo am 28.3.19.X'
"C:\Program Files\Microchip\xc8\v2.05\bin\xc8-cc.exe" -mcpu=16F877A -c -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/newmain.p1 newmain.c
::: advisory: (2049) C99 compliant libraries are currently not available for baseline or mid-range devices, or for enhanced mid-range devices using a reentrant stack; using C90 libraries
newmain.c:52:6: error: variable has incomplete type 'void'
void interrupt timer_isr()
^
newmain.c:52:15: error: expected ';' after top level declarator
void interrupt timer_isr()
^
;
2 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/newmain.p1' failed
make[2]: Leaving directory 'C:/Users/Pauline/MPLABXProjects/Test f�r R�ckantwort PWM Servo am 28.3.19.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Pauline/MPLABXProjects/Test f�r R�ckantwort PWM Servo am 28.3.19.X'
make[2]: *** [build/default/production/newmain.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
In reply to variable has incomplete type Generation of PWM signals on GPIO by Herbert Wichmann
Permalink
As you can see there are two errors and the following lines gives us the information about the error
newmain.c:52:6: error: variable has incomplete type 'void'
void interrupt timer_isr()
^
newmain.c:52:15: error: expected ';' after top level declarator
void interrupt timer_isr()
The problem is with the void interrupt timer_isr() function. But the code you have given looks good. I am not sure why exactly you are getting this error. One thing I would ask you to try is use the code after the while loop.
That is cut the entire void interrupt timer_isr() function and paste it and the end of the program and compile it
Hello Mr. Hiro Hamada,
Thank you for helping me. Since I'm only at the beginning of programming, and much still do not understand, I ask you if I can the entire "void interrupt timer_isr ()" function that I cut out to mark and where exactly in the program I should then paste them.
What do you mean I should use the code after the while loop. Which code is it (please mark) and what should I do with the code after the while loop, where paste etc?
Thanks a lot to all the forum people for the help
With kind regards
Herbert Wichmann
I am not sure why you are getting the error. I will try compiling the code myself and test it agin. Meanwhile try this code and below and tell me if you are getting the same error. Also make sure you have include the LCD librarey for this one as well
/*
* Program to Control Robotic Arm through POT
* 5 Servo controlled with Timer Register PWM
* Dated: 15-1-2019
* Web: www.circuitdigest.com
* Author: B.Asiwnth Raj
*/#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)#define _XTAL_FREQ 20000000 //Crystak Freq is 20MHz
#define PWM_Frequency 0.05 // in KHz (50Hz)//Define LCD pins
#define RS RB1
#define EN RB2
#define D4 RB3
#define D5 RB4
#define D6 RB5
#define D7 RB6#include <xc.h>
#include "lcd.h" //Header for using LCD moduleint POT_val; //variable to store value from ADC
int count; //timer variable
//int T_TOTAL = (1/PWM_Frequency); //calculate Total Time from frequency (in milli sec)) //20msec
int Duty_cycle; //Duty cycle value
int T_ON[4];char servo;
void ADC_Initialize() //Prepare the ADC module
{
ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
ADCON1 = 0b11000000; // Internal reference voltage is selected
}unsigned int ADC_Read(unsigned char channel) //Read from ADC
{
ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
/*****Port Configuration for Timer ******/
OPTION_REG = 0b00000100; // Timer0 with external freq and 32 as prescalar // Also Enables PULL UPs
TMR0=248; // Load the time value for 0.0001s; delayValue can be between 0-256 only
TMR0IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
/***********______***********/
/*****Port Configuration for I/O ******/
TRISB = 0x00; //PORT B is output since LCd is connected
PORTB=0x00; //Initialize all pins to 0
TRISD = 0x00; //PORT D is output since servo is connected
PORTD=0x00; //Initialize all pins to 0
/***********______***********/
Lcd_Start(); //Initialize LCD module
ADC_Initialize(); //Initialize ADC module
// Lcd_Clear();
// Lcd_Set_Cursor(1,1);
//Lcd_Print_String("Circuit Digest");
//Lcd_Set_Cursor(2,1);
//Lcd_Print_String("WORKING!!");
//__delay_ms(500);
while(1)
{
for (int pot_num=0; pot_num<=3; pot_num++)
{
int Pev_val = T_ON[pot_num];
POT_val = (ADC_Read(pot_num)); //Read the value of POT using ADC
Duty_cycle = (POT_val * 0.0976); //Map 0 to 1024 to 0 to 100
T_ON[pot_num] = Duty_cycle* 0.4;//((Duty_cycle * T_TOTAL) / 1000)*10; //Calculate On Time from 0ms to 2ms for 0-100 Duty Cycle //*10 is multiplication factor
if (T_ON[pot_num] != Pev_val)
{
Lcd_Clear();
servo = pot_num;
Lcd_Set_Cursor(2,11); Lcd_Print_String("S:");Lcd_Print_Char(servo+'0');
if (pot_num==0)
{Lcd_Set_Cursor(1,1); Lcd_Print_String("A:");}
else if (pot_num==1)
{Lcd_Set_Cursor(1,6); Lcd_Print_String("B:");}
else if (pot_num==2)
{Lcd_Set_Cursor(1,11); Lcd_Print_String("C:");}
else if (pot_num==3)
{Lcd_Set_Cursor(2,1); Lcd_Print_String("D:");}
else if (pot_num==4)
{Lcd_Set_Cursor(2,6); Lcd_Print_String("E:");}
char d2 = (Duty_cycle) %10;
char d1 = (Duty_cycle/10) %10;
Lcd_Print_Char(d1+'0');Lcd_Print_Char(d2+'0');
}
}
}
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered due to timer overflow -> set to overflow for every 0.05ms
{
TMR0 = 248; //Load the timer Value
TMR0IF=0; // Clear timer interrupt flag
count++; //Count increments by 1 for every 0.05ms
}
int servo_code[] = {0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000100 };
if (count >= 20*20)
count=0;
if (count <= (T_ON[servo]) )
PORTD = PORTD | servo_code[servo];
else
PORTD = PORTD & ~(servo_code[servo]);
}
Hello Mr. Aswinth,
Thank you for your help and your efforts to help beginners and to communicate their knowledge.
I have the last code from you and the lcd.h with embedded, but unfortunately no success I can not compile the code, I have pasted the last code and the lcd.h here again to the controller with.
Also the error report of the compiling is displayed I have here also with inserted.
Maybe even helps following the error on the track. I have the timer u. PWM Singnale On GPIO Pins: controlling the servomotor "Program of you from the tutoral tries to compile but I do not succeed the compiler always points to errors in the line with void interrupt timer_isr () why always me?
Thank you again for your great and understandable exercise and learning programs in the tutors.
Thank you for everything.
Herbert Wichmann
Compiler Error:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Paul/MPLABXProjects/Test 4.4. 19 5 Potis Aswinth �nderung .X'
make -f nbproject/Makefile-default.mk dist/default/production/Test_4.4._19__5_Potis_Aswinth__nderung_.X.production.hex
make[2]: Entering directory 'C:/Users/Paul/MPLABXProjects/Test 4.4. 19 5 Potis Aswinth �nderung .X'
"C:\Program Files\Microchip\xc8\v2.00\bin\xc8-cc.exe" -mcpu=16F877A -c -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/newmain.p1 newmain.c
::: advisory: (2049) C99 compliant libraries are currently not available for baseline or mid-range devices, or for enhanced mid-range devices using a reentrant stack; using C90 libraries
[Logging clang options] "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\bin\\clang.exe" "-cc1" "-triple" "pic" "-E" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "newmain.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-no-integrated-as" "-mconstructor-aliases" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\bin\\..\\lib\\clang\\4.0.1" "-dependency-file" "build/default/production\\newmain.d" "-MT" "build/default/production\\newmain.i" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include\\c90" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include\\legacy" "-include" "language_support.h" "-U" "__GNUC__" "-D" "__CLANG__" "-D" "__PICC__" "-D" "__PICCPRO__" "-D" "XPRJ_default=default" "-D" "_OMNI_CODE_" "-D" "__STACK_COMPILED=1" "-D" "__STACK_HYBRID=2" "-D" "__STACK_REENTRANT=4" "-D" "__STACK=__STACK_COMPILED" "-D" "__ADDRQUAL_IGNORE=1" "-D" "__ADDRQUAL_REQUEST=2" "-D" "__ADDRQUAL_REQUIRE=4" "-D" "__ADDRQUAL_REJECT=8" "-D" "__ADDRQUAL=__ADDRQUAL_IGNORE" "-D" "__XC" "-D" "__XC8" "-D" "__XC__" "-D" "__XC8__" "-D" "__XC8_VERSION=2000" "-D" "HI_TECH_C" "-D" "_XC8_MODE_=0" "-D" "__OPTIMIZE_SIZE__" "-D" "__OPTIMIZE_SPACE__" "-D" "__OPTIM_FLAGS=0x2" "-D" "__OPTIM_NONE=0x0" "-D" "__OPTIM_ASM=0x1" "-D" "__OPTIM_ASMFILE=0x2" "-D" "__OPTIM_SPEED=0x20000" "-D" "__OPTIM_SPACE=0x40000" "-D" "__OPTIM_SIZE=0x40000" "-D" "__OPTIM_DEBUG=0x80000" "-D" "__OPTIM_LOCAL=0x200000" "-D" "_CLIB_VERSION=1990" "-D" "_16F877A" "-D" "__16F877A" "-D" "__16F877A__" "-D" "_MPC_" "-D" "__XC" "-D" "__XC8" "-D" "_HAS_INT24" "-D" "_PIC14" "-U" "__SIZEOF_CHAR__" "-U" "__SIZEOF_SHORT__" "-U" "__SIZEOF_INT__" "-U" "__SIZEOF_SHORT_LONG__" "-U" "__SIZEOF__INT24__" "-U" "__SIZEOF___INT24__" "-U" "__SIZEOF_LONG__" "-U" "__SIZEOF_LONG_LONG__" "-U" "__SIZEOF_FLOAT__" "-U" "__SIZEOF_DOUBLE__" "-U" "__SIZEOF_LONG_DOUBLE__" "-D" "__SIZEOF_CHAR__=1" "-D" "__SIZEOF_SHORT__=2" "-D" "__SIZEOF_INT__=2" "-D" "__SIZEOF_SHORT_LONG__=3" "-D" "__SIZEOF_INT24__=3" "-D" "__SIZEOF___INT24__=3" "-D" "__SIZEOF_LONG__=4" "-D" "__SIZEOF_LONG_LONG__=4" "-D" "__SIZEOF_FLOAT__=4" "-D" "__SIZEOF_DOUBLE__=4" "-D" "__SIZEOF_LONG_DOUBLE__=4" "-D" "_COMMON_=1" "-D" "_COMMON_ADDR_=112" "-D" "_COMMON_SIZE_=16" "-D" "_BANKCOUNT_=4" "-D" "_BANKBITS_=2" "-D" "_GPRCOUNT_=4" "-D" "_GPRBITS_=2" "-D" "__DATABANK=2" "-D" "__FLASHTYPE=2" "-D" "_ROMSIZE=8192" "-D" "_EEPROMSIZE=256" "-D" "EEPROM_SIZE=256" "-D" "_NVMREG_INT=2" "-D" "_EEREG_INT=1" "-D" "_NOREG_INT=0" "-D" "_EEPROM_INT=1" "-D" "_FLASH_ERASE_SIZE=8" "-D" "_FLASH_WRITE_SIZE=8" "-std=c99" "-fno-dwarf-directory-asm" "-fdebug-compilation-dir" "C:\\Users\\Paul\\MPLABXProjects\\Test 4.4. 19 5 Potis Aswinth änderung .X" "-ferror-limit" "19" "-fmessage-length" "0" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-o" "build/default/production\\newmain.i" "-x" "c" "newmain.c"
[Logging clang options] "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\bin\\clang.exe" "-cc1" "-triple" "pic" "-S" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "newmain.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-no-integrated-as" "-mconstructor-aliases" "-dwarf-column-info" "-debugger-tuning=gdb" "-coverage-notes-file" "C:\\Users\\Paul\\MPLABXProjects\\Test 4.4. 19 5 Potis Aswinth änderung .X\\build/default/production\\newmain.gcno" "-resource-dir" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\bin\\..\\lib\\clang\\4.0.1" "-dependency-file" "build/default/production\\newmain.d" "-MT" "build/default/production\\newmain.p1" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include\\c90" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include" "-isystem" "C:\\Program Files\\Microchip\\xc8\\v2.00\\pic\\include\\legacy" "-include" "language_support.h" "-U" "__GNUC__" "-D" "__CLANG__" "-D" "__PICC__" "-D" "__PICCPRO__" "-D" "XPRJ_default=default" "-D" "_OMNI_CODE_" "-D" "__STACK_COMPILED=1" "-D" "__STACK_HYBRID=2" "-D" "__STACK_REENTRANT=4" "-D" "__STACK=__STACK_COMPILED" "-D" "__ADDRQUAL_IGNORE=1" "-D" "__ADDRQUAL_REQUEST=2" "-D" "__ADDRQUAL_REQUIRE=4" "-D" "__ADDRQUAL_REJECT=8" "-D" "__ADDRQUAL=__ADDRQUAL_IGNORE" "-D" "__XC" "-D" "__XC8" "-D" "__XC__" "-D" "__XC8__" "-D" "__XC8_VERSION=2000" "-D" "HI_TECH_C" "-D" "_XC8_MODE_=0" "-D" "__OPTIMIZE_SIZE__" "-D" "__OPTIMIZE_SPACE__" "-D" "__OPTIM_FLAGS=0x2" "-D" "__OPTIM_NONE=0x0" "-D" "__OPTIM_ASM=0x1" "-D" "__OPTIM_ASMFILE=0x2" "-D" "__OPTIM_SPEED=0x20000" "-D" "__OPTIM_SPACE=0x40000" "-D" "__OPTIM_SIZE=0x40000" "-D" "__OPTIM_DEBUG=0x80000" "-D" "__OPTIM_LOCAL=0x200000" "-D" "_CLIB_VERSION=1990" "-D" "_16F877A" "-D" "__16F877A" "-D" "__16F877A__" "-D" "_MPC_" "-D" "__XC" "-D" "__XC8" "-D" "_HAS_INT24" "-D" "_PIC14" "-U" "__SIZEOF_CHAR__" "-U" "__SIZEOF_SHORT__" "-U" "__SIZEOF_INT__" "-U" "__SIZEOF_SHORT_LONG__" "-U" "__SIZEOF__INT24__" "-U" "__SIZEOF___INT24__" "-U" "__SIZEOF_LONG__" "-U" "__SIZEOF_LONG_LONG__" "-U" "__SIZEOF_FLOAT__" "-U" "__SIZEOF_DOUBLE__" "-U" "__SIZEOF_LONG_DOUBLE__" "-D" "__SIZEOF_CHAR__=1" "-D" "__SIZEOF_SHORT__=2" "-D" "__SIZEOF_INT__=2" "-D" "__SIZEOF_SHORT_LONG__=3" "-D" "__SIZEOF_INT24__=3" "-D" "__SIZEOF___INT24__=3" "-D" "__SIZEOF_LONG__=4" "-D" "__SIZEOF_LONG_LONG__=4" "-D" "__SIZEOF_FLOAT__=4" "-D" "__SIZEOF_DOUBLE__=4" "-D" "__SIZEOF_LONG_DOUBLE__=4" "-D" "_COMMON_=1" "-D" "_COMMON_ADDR_=112" "-D" "_COMMON_SIZE_=16" "-D" "_BANKCOUNT_=4" "-D" "_BANKBITS_=2" "-D" "_GPRCOUNT_=4" "-D" "_GPRBITS_=2" "-D" "__DATABANK=2" "-D" "__FLASHTYPE=2" "-D" "_ROMSIZE=8192" "-D" "_EEPROMSIZE=256" "-D" "EEPROM_SIZE=256" "-D" "_NVMREG_INT=2" "-D" "_EEREG_INT=1" "-D" "_NOREG_INT=0" "-D" "_EEPROM_INT=1" "-D" "_FLASH_ERASE_SIZE=8" "-D" "_FLASH_WRITE_SIZE=8" "-std=c99" "-fno-dwarf-directory-asm" "-fdebug-compilation-dir" "C:\\Users\\Paul\\MPLABXProjects\\Test 4.4. 19 5 Potis Aswinth änderung .X" "-ferror-limit" "19" "-fmessage-length" "0" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-QF_,0,far" "-QN_,0,near" "-QI_,0,interrupt" "-QS_,0,persistent" "-QT_,0,inline" "-QQ,0,__pack" "-QJ_,0,nonreentrant" "-QJ_,0,compiled" "-QU,0,__discrete" "-QE_,0,eeprom" "-QL_,0,low_priority" "-QH_,0,high_priority" "-QAx,0,__minocg" "-Q00,1512,__invariant" "-Q00,1512,__stable" "-Q00,0,restrict" "-QP_s,0,bank0" "-QX_s,0,bank1" "-QY_s,0,bank2" "-QZ_s,0,bank3" "-QCu,0,const" "-QR_0,1463,reentrant" "-QBu,0,__rom" "-QMu,0,__ram" "-o" "build/default/production\\newmain.p1" "-x" "c" "newmain.c"
In file included from newmain.c:51:
./lcd.h:48:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
Lcd_Clear()
^
./lcd.h:52:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
./lcd.h:78:13: warning: implicit conversion from 'long' to 'int' changes value from 1065244 to 16668 [-Wconstant-conversion]
for(int i=1065244; i<=0; i--) NOP();
~ ^~~~~~~
newmain.c:235:7: error: variable has incomplete type 'void'
void interrupt timer_isr()
^
newmain.c:235:16: error: expected ';' after top level declarator
void interrupt timer_isr()
^
;
3 warnings and 2 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:105: recipe for target 'build/default/production/newmain.p1' failed
make[2]: Leaving directory 'C:/Users/Paul/MPLABXProjects/Test 4.4. 19 5 Potis Aswinth �nderung .X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Paul/MPLABXProjects/Test 4.4. 19 5 Potis Aswinth �nderung .X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/newmain.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
C- Code
/*
* Program to Control Robotic Arm through POT
* 5 Servo controlled with Timer Register PWM
* Dated: 15-1-2019
* Web: www.circuitdigest.com
* Author: B.Asiwnth Raj
*/
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define _XTAL_FREQ 20000000 //Crystak Freq is 20MHz
#define PWM_Frequency 0.05 // in KHz (50Hz)
//Define LCD pins
#define RS RB1
#define EN RB2
#define D4 RB3
#define D5 RB4
#define D6 RB5
#define D7 RB6
#include <xc.h>
#include "lcd.h" //Header for using LCD module
int POT_val; //variable to store value from ADC
int count; //timer variable
//int T_TOTAL = (1/PWM_Frequency); //calculate Total Time from frequency (in milli sec)) //20msec
int Duty_cycle; //Duty cycle value
int T_ON[4];
char servo;
void ADC_Initialize() //Prepare the ADC module
{
ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
ADCON1 = 0b11000000; // Internal reference voltage is selected
}
unsigned int ADC_Read(unsigned char channel) //Read from ADC
{
ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
/*****Port Configuration for Timer ******/
OPTION_REG = 0b00000100; // Timer0 with external freq and 32 as prescalar // Also Enables PULL UPs
TMR0=248; // Load the time value for 0.0001s; delayValue can be between 0-256 only
TMR0IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
/***********______***********/
/*****Port Configuration for I/O ******/
TRISB = 0x00; //PORT B is output since LCd is connected
PORTB=0x00; //Initialize all pins to 0
TRISD = 0x00; //PORT D is output since servo is connected
PORTD=0x00; //Initialize all pins to 0
/***********______***********/
Lcd_Start(); //Initialize LCD module
ADC_Initialize(); //Initialize ADC module
// Lcd_Clear();
// Lcd_Set_Cursor(1,1);
//Lcd_Print_String("Circuit Digest");
//Lcd_Set_Cursor(2,1);
//Lcd_Print_String("WORKING!!");
//__delay_ms(500);
while(1)
{
for (int pot_num=0; pot_num<=3; pot_num++)
{
int Pev_val = T_ON[pot_num];
POT_val = (ADC_Read(pot_num)); //Read the value of POT using ADC
Duty_cycle = (POT_val * 0.0976); //Map 0 to 1024 to 0 to 100
T_ON[pot_num] = Duty_cycle* 0.4;//((Duty_cycle * T_TOTAL) / 1000)*10; //Calculate On Time from 0ms to 2ms for 0-100 Duty Cycle //*10 is multiplication factor
if (T_ON[pot_num] != Pev_val)
{
Lcd_Clear();
servo = pot_num;
Lcd_Set_Cursor(2,11); Lcd_Print_String("S:");Lcd_Print_Char(servo+'0');
if (pot_num==0)
{Lcd_Set_Cursor(1,1); Lcd_Print_String("A:");}
else if (pot_num==1)
{Lcd_Set_Cursor(1,6); Lcd_Print_String("B:");}
else if (pot_num==2)
{Lcd_Set_Cursor(1,11); Lcd_Print_String("C:");}
else if (pot_num==3)
{Lcd_Set_Cursor(2,1); Lcd_Print_String("D:");}
else if (pot_num==4)
{Lcd_Set_Cursor(2,6); Lcd_Print_String("E:");}
char d2 = (Duty_cycle) %10;
char d1 = (Duty_cycle/10) %10;
Lcd_Print_Char(d1+'0');Lcd_Print_Char(d2+'0');
}
}
}
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered due to timer overflow -> set to overflow for every 0.05ms
{
TMR0 = 248; //Load the timer Value
TMR0IF=0; // Clear timer interrupt flag
count++; //Count increments by 1 for every 0.05ms
}
int servo_code[] = {0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000100 };
if (count >= 20*20)
count=0;
if (count <= (T_ON[servo]) )
PORTD = PORTD | servo_code[servo];
else
PORTD = PORTD & ~(servo_code[servo]);
}
lcd.h File
/*
* File: Header file to interface LCD with PIC16F877A
* Author: B.Aswinth Raj
* More details on: https://circuitdigest.com/microcontroller-projects/16x2-lcd-interfacing…
* Created on 5 May, 2018, 6:43 PM
*/
/*SAMPLE CODE
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Print_String("Circuit Digest");
Lcd_Set_Cursor(2,1);
Lcd_Print_Char(temp+'0');
/END OF SAMPL*/
void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines
{
if(data_bit& 1)
D4 = 1;
else
D4 = 0;
if(data_bit& 2)
D5 = 1;
else
D5 = 0;
if(data_bit& 4)
D6 = 1;
else
D6 = 0;
if(data_bit& 8)
D7 = 1;
else
D7 = 0;
}
void Lcd_Cmd(char a)
{
RS = 0;
Lcd_SetBit(a); //Incoming Hex value
EN = 1;
__delay_ms(4);
EN = 0;
}
Lcd_Clear()
{
Lcd_Cmd(0); //Clear the LCD
Lcd_Cmd(1); //Move the curser to first position
}
void Lcd_Set_Cursor(char a, char b)
{
char temp,z,y;
if(a== 1)
{
temp = 0x80 + b - 1; //80H is used to move the curser
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
}
else if(a== 2)
{
temp = 0xC0 + b - 1;
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
}
}
void Lcd_Start()
{
Lcd_SetBit(0x00);
for(int i=1065244; i<=0; i--) NOP();
Lcd_Cmd(0x03);
__delay_ms(5);
Lcd_Cmd(0x03);
__delay_ms(11);
Lcd_Cmd(0x03);
Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
Lcd_Cmd(0x08); //Select Row 1
Lcd_Cmd(0x00); //Clear Row 1 Display
Lcd_Cmd(0x0C); //Select Row 2
Lcd_Cmd(0x00); //Clear Row 2 Display
Lcd_Cmd(0x06);
}
void Lcd_Print_Char(char data) //Send 8-bits through 4-bit mode
{
char Lower_Nibble,Upper_Nibble;
Lower_Nibble = data&0x0F;
Upper_Nibble = data&0xF0;
RS = 1; // => RS = 1
Lcd_SetBit(Upper_Nibble>>4); //Send upper half by shifting by 4
EN = 1;
__delay_us(40);//for(int i=2130483; i<=0; i--) NOP();
EN = 0;
Lcd_SetBit(Lower_Nibble); //Send Lower half
EN = 1;
__delay_us(40);//for(int i=2130483; i<=0; i--) NOP();
EN = 0;
}
void Lcd_Print_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd_Print_Char(a[i]); //Split the string using pointers and call the Char function
}
Hi,
I tried compileing the same code and did not get any error. Since I am not able to re-create the error you have there is no way i can figure out a solution. The only reason i can think of is that you have made some mistake while creating your project. I am attaching my complete MPLABX file here. Try with this and let me know the result
https://drive.google.com/file/d/19ssP_50pSox4RKXn3GK2Xn-ay0f7JgjP/view?…
Hi,
I tried compileing the same code and did not get any error. Since I am not able to re-create the error you have there is no way i can figure out a solution. The only reason i can think of is that you have made some mistake while creating your project. I am attaching my complete MPLABX file here. Try with this and let me know the result
https://drive.google.com/file/d/19ssP_50pSox4RKXn3GK2Xn-ay0f7JgjP/view?…
Hello Mr. Aswinth, I have found the error on the Internet: From version 2.0, the XC 8 compiler in C99 mode wants this "__interrupt ()" notation instead of interrupt. Have I tested can now compile the code, will build the circuits on breadboard and then test whether the programs do as you imagine.
Thanks again for your help
up soon.
Herbert Wichmann
Herbert Wichmann
PermalinkHello Mr. Aswinth Raj, to my post from the 4th of March 2019 here is the text that the compiler issues. Would be glad if someone could help me.
Greeting Herbert Wichmann
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Pauline/MPLABXProjects/PWM Servo Aswinth mit 16F877A das im Brief.X'
make -f nbproject/Makefile-default.mk dist/default/production/PWM_Servo_Aswinth_mit_16F877A__das_im_Brief.X.production.hex
make[2]: Entering directory 'C:/Users/Pauline/MPLABXProjects/PWM Servo Aswinth mit 16F877A das im Brief.X'
"C:\Program Files\Microchip\xc8\v2.00\bin\xc8-cc.exe" -mcpu=16F877A -c -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/main.p1 main.c
::: advisory: (2049) C99 compliant libraries are currently not available for baseline or mid-range devices, or for enhanced mid-range devices using a reentrant stack; using C90 libraries
main.c:50:6: error: variable has incomplete type 'void'
make[2]: *** [build/default/production/main.p1] Error 1
void interrupt timer_isr()
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
^
main.c:50:15: error: expected ';' after top level declarator
void interrupt timer_isr()
^
;
2 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/main.p1' failed
make[2]: Leaving directory 'C:/Users/Pauline/MPLABXProjects/PWM Servo Aswinth mit 16F877A das im Brief.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Pauline/MPLABXProjects/PWM Servo Aswinth mit 16F877A das im Brief.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
- Log in or register to post comments
Joined March 02, 2019 23Saturday at 03:56 PM