Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 25th April 2009, 01:20 PM   #1
Default pic programming by micro C

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
girgis adly is offline  
Old 25th April 2009, 01:45 PM   #2
Default

Quote:
Originally Posted by girgis adly View Post
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'.

Quote:
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.
eng1 is offline  
Old 26th April 2009, 01:23 PM   #3
Default

are you mean write
delay _us(335);
girgis adly is offline  
Old 26th April 2009, 03:00 PM   #4
Default

Quote:
Originally Posted by girgis adly View Post
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.
eng1 is offline  
Old 28th April 2009, 02:37 PM   #5
Default 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;
}
girgis adly is offline  
Reply

Tags
micro, pic, programming

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
pic micro programming in C fusian Micro Controllers 8 18th February 2008 06:11 PM
micro or plc mr.engineering Micro Controllers 10 26th December 2006 03:58 PM
need micro-pro navveed Micro Controllers 2 7th February 2006 09:46 AM
programming of AT89c51 micro-controller nivvy Micro Controllers 7 4th December 2005 05:57 AM
MICRO herbymcduff Datasheet/Parts Requests 3 20th December 2002 05:16 PM



All times are GMT. The time now is 09:34 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker