Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic programming by micro C

Status
Not open for further replies.

girgis adly

New Member
Dear all iam girgis adly in 4th year electrical faculty of engineer I try to write a program for pic18f452 firing the mosfets of the multilevel inverter at a certain time by a certain sequence and the frequency of the output equal 50 HZ I write the program using (microC) language
void main()
{
TRISB=0;
LOOP:
PORTB=0;
delay_ms(.3355);
PORTB=0B00100110;
delay_ms(2.717);
PORTB=0B00100101;
delay_ms(3.889);
PORTB=0B00100110;
delay_ms(2.667);
PORTB=0;
delay_ms(0.777);
PORTB=0B00011010;
delay_ms(2.667);
PORTB=0B00011001;
delay_ms(3.889);
PORTB=0B00011010;
delay_ms(2.667);
PORTB=0;
delay_ms(0.388);
goto loop;
}

but the compiler found this errors

Internal error line 8
';'expected but delay_ms is found line7
Integral constant expected line6
Syntax error :expected ')'but found ';' line7

I don’t know how to re write the program without errors and without changing the time it will be grateful if any one help me

thanks
 
Dear all iam girgis adly in 4th year electrical faculty of engineer I try to write a program for pic18f452 firing the mosfets of the multilevel inverter at a certain time by a certain sequence and the frequency of the output equal 50 HZ I write the program using (microC) language
void main()
{
TRISB=0;
LOOP:
PORTB=0;
delay_ms(.3355);
PORTB=0B00100110;
delay_ms(2.717);
PORTB=0B00100101;
delay_ms(3.889);
PORTB=0B00100110;
delay_ms(2.667);
PORTB=0;
delay_ms(0.777);
PORTB=0B00011010;
delay_ms(2.667);
PORTB=0B00011001;
delay_ms(3.889);
PORTB=0B00011010;
delay_ms(2.667);
PORTB=0;
delay_ms(0.388);
goto loop;
}

but the compiler found this errors

Internal error line 8
';'expected but delay_ms is found line7
Integral constant expected line6
Syntax error :expected ')'but found ';' line7

I don’t know how to re write the program without errors and without changing the time it will be grateful if any one help me

thanks


Use a while instruction to generate an end-less loop in C:

Code:
void main()
{
  TRISB=0;
 
  while(1){
 
    // code inside this while loop repeats indefinitely
 
    PORTB=0;
    delay_ms(.3355);
    PORTB=0B00100110;
    delay_ms(2.717);
    PORTB=0B00100101;
    delay_ms(3.889);
    PORTB=0B00100110;
    delay_ms(2.667);
    PORTB=0;
    delay_ms(0.777);
    PORTB=0B00011010;
    delay_ms(2.667);
    PORTB=0B00011001;
    delay_ms(3.889);
    PORTB=0B00011010;
   delay_ms(2.667);
   PORTB=0;
   delay_ms(0.388);
   }
 
// ...

However, I think you have to pass an integer to the mikroC function 'delay_mS'. If you need to wait for fractions of a ms, you could use the function 'delay_us'.

delay_ms(.3355);
Delaying fractions of a us can be done including NOP's, if the PIC is running at high frequency (f>4 MHz) but the delay must be an integer multiple of 4/f.
To generate precise delays you should check the assembly code generated by your compiler and do simulations with breakpoints.
 
are you mean write
delay _us(335);

Yes, this call to delay_us() will delay for 335 us.

delay_us(3889) will delay for 3.889 ms and so on.

As I said, you should check the asm code generated by the compiler and do simulations to verify that the delay will be exactly what you expect.
 
thanks this is write

thanks eng1 i try this and this is the right code
void main()
{
TRISB=0;
LOOP:
PORTB=0;
Delay_us(337);
PORTB=0B00100110;
Delay_us(2717);
PORTB=0B00100101;
delay_us(3889);
PORTB=0B00100110;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00011010;
delay_us(2667);
PORTB=0B00011001;
delay_us(3889);
PORTB=0B00011010;
delay_us(2667);
PORTB=0;
delay_us(388);
goto loop;
}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top