I want to use pwm in pic16f877a
when I wrote this code :
unsigned short i;
void main() {
PORTC = 00; // Set PORTC to $FF
TRISC = 0; // PORTC is output
Pwm_Init(5000); // Initialize PWM module
Pwm_Start(); // Start PWM
while (1) { // Endless loop
for(i=0;i<=255;i++)
{ Pwm1_Change_Duty(i);
delay_ms(10); }
} }
there are some errors which tells that the compiler could not identify the expressions
the messages are:
Undeclared identifier 'Pwm_Init' in expression pwm.c
Undeclared identifier 'Pwm_Start' in expression pwm.c
Undeclared identifier 'Pwm1_Change_Duty' in expression pwm.c
Finished (with errors): 01 Jan 2010, 04:43:12 pwm.mcppi
Those 3 things are functions, and the compiler can not find them.
The simplest way is to put those functions above main (before main) in the C code.
Also, please make your { brackets neater and use indenting. To display your code properly on this forum you use "code tags" like this;
(code)
your code goes here
(/code)
and you must use SQUARE brackets for the code tags.
there are some errors which tells that the compiler could not identify the expressions
the messages are:
Undeclared identifier 'Pwm_Init' in expression pwm.c
Undeclared identifier 'Pwm_Start' in expression pwm.c
Undeclared identifier 'Pwm1_Change_Duty' in expression pwm.c
Finished (with errors): 01 Jan 2010, 04:43:12 pwm.mcppi
Thanks for the correction 3v0. That was my mistake I don't use the compilers inbuilt PWM library functions, it's easy enough and faster to do that manually on PICs.
MikroC PRO requires the compiler libraries to be manually ticked in the libraries window, I mainly use the older MikroC which detects which libraries you are using automatically.
u r right 3v0 the first problem was that the compiler did not know it should be using the PWM lib.
I followed the steps u had adviced me but the error messages did not differ and that make me thinking that it was not the right way to solve the solution
now every thing goes without problem
thanks to all.
MR RB
what is the use of these instructions in mikroc :
{ANSEL = 0; },{ANSELH = 0;}
and why the compiler cannot identify them
I tried them with different pics with no use .
microchip use them in the example codes in it's manual for pwm explanation
Some pics don't have ANSEL registers... The pic16f877a adc's are selected in the ADCON0... The ANSEL are used when there are oodles of channels to select from.
The compiler uses the specific header file for that chip... that's why its undefined
I used the pic refered by microchip
and also I have tried this for many more advanced pics like 18 family and the compiler also did not recognize then
what pic do u think that it have ansel register ?
Check the PIC datasheet, it's a good idea when writing code to also have the datahseet (Adobe) open in another window. Then you can flip back and forth between the code compiler and the datasheet to check things. This is especially important if you don't know that PIC real well, or you are struggling with simple things like ANSEL etc.
ANSEL and ANSELH are not in every PIC but when they are used they are explained in the ADC "analogue to digital converter" chapter.
It sounds like you are learning that PIC and also learning with the compiler, so it helps to work slowly and read up on the PIC hardware in the datasheet as you work.
You are doing good with a difficult challenge, keep it up!