What compiler are you using? This code is for MikroC. You may have to translate a few things. For instance, they may express things like "TMR1IF_bit" differently. These are PIC specific and not a part of standard ANSI C so each compiler developer is free to define them as they see fit. Allen > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of > Richard R. Pope > Sent: Saturday, July 19, 2014 11:25 AM > To: Microcontroller discussion list - Public. > Subject: Re: [Pic] Making a special timer! >=20 > Allen, > I try this and it won't compile. I have also tried it with > prototypes and I receive the same error messages. I fix one problem and > end up with more. Well I'm getting there. All of the help has been > greatly appreciated. > Thanks, rich! > Here are the error messages: >=20 > Error [195] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 54.12 > expression syntax > Error [195] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 57.12 > expression syntax > Error [195] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 62.16 > expression syntax > Error [194] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 63.21 ")" > expected > Error [285] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 68.1 no > identifier in declaration > Warning [374] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 68.1 missing > basic type; int assumed >=20 > Error [314] > R:\Programming\PicPrograms\Pic-Controller\NewControlCode.c; 68.1 ";" > expected > (908) exit status =3D 1 >=20 > I get these messages with the code from the timer calculator. Please > help me? > Thanks, > rich! >=20 > On 7/18/2014 9:40 AM, Allen Mulvey wrote: > > MikroElektronika has a free Timer Calculator that you can use to get th= e > > code to set up your timer. I don't understand why anyone would want to use a > > PWM when the timer is so easy and quite accurate. Check this out: > > http://www.libstock.com/projects/view/398/timer-calculator > > > > I use it all the time. For a PIC16 Timer1 you can get 100ms from this code: > > > > //Timer1 > > //Prescaler 1:8; TMR1 Preload =3D 3036; Actual Interrupt Time : 100 ms > > > > //Place/Copy this part in declaration section > > void InitTimer1(){ > > T1CON =3D 0x31; > > TMR1IF_bit =3D 0; > > TMR1H =3D 0x0B; > > TMR1L =3D 0xDC; > > TMR1IE_bit =3D 1; > > INTCON =3D 0xC0; > > } > > > > void Interrupt(){ > > if (TMR1IF_bit){ > > TMR1IF_bit =3D 0; > > TMR1H =3D 0x0B; > > TMR1L =3D 0xDC; > > //Enter your code here > > } > > } > > > > Enable the interrupt. Turn on your pin. Count 10 interrupts. Turn off pin. > > Turn off and reset timer. Start over when necessary. > > > > You may need to make minor adjustments (TMR1L) for the time to actually > turn > > the pin on and off. > > > > Allen > > > This is the complete code: >=20 > // Includes go here > #include >=20 > // Prototypes go here > void ourdelay(int time); > //void InitTimer1(); > //void Interrupt1(); >=20 > /*Richard R. pope > 07-19-14 > */ >=20 > #pragma config FOSC =3D XT, WDTE =3D OFF, PWRTE =3D ON, MCLRE =3D OFF \ > CP =3D OFF, CPD =3D OFF, BOREN =3D OFF, IESO =3D OFF, FCMEN =3D = OFF > main() > { >=20 > PORTA =3D 0; // Turn porta off > TRISA =3D 255; // Set Porta as all inputs > PORTC =3D 2; // Set RC1 to RC5 high > TRISC =3D 193; // Start with DP1 on, the rest of portc is > inputs > CMCON0 =3D 7; // Turn off Comparators > ANSEL =3D 16; // Set RC0/AN4 as analog >=20 > // Define commands > int Reset =3D 34; > int Gate =3D 18; >=20 > while (1 =3D=3D 1) // Loop forever > { > TRISC =3D Reset; // Clear the Display > TRISC =3D Gate; // Start counting > ourdelay(1); // Count the frequency for one second = =3D HZ > ourdelay(15); // Display the frequency for 15 seconds >=20 > } > } // End NewControlCode.c >=20 > void ourdelay(int time) > { > int x; > for(x=3D0; x <=3D time * 10; x++) > { > } > return; > } >=20 > //Timer1 > //Prescaler 1:8; TMR1 Preload =3D 3036; Actual Interrupt Time : 100 ms >=20 > //Place/Copy this part in declaration section > void InitTimer1(){ > T1CON =3D 0x31; > TMR1IF_bit =3D 0; > TMR1H =3D 0x0B; > TMR1L =3D 0xDC; > TMR1IE_bit =3D 1; > INTCON =3D 0xC0; > } >=20 > void Interrupt(){ > if (TMR1IF_bit){ > TMR1IF_bit =3D 0; > TMR1H =3D 0x0B; > TMR1L =3D 0xDC; > //Enter your code here > } > } >=20 > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .