![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 | |
| |
| | #2 | ||
| Quote:
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);
}
// ...
Quote:
To generate precise delays you should check the assembly code generated by your compiler and do simulations with breakpoints. | |||
| |
| | #3 |
|
are you mean write delay _us(335); | |
| |
| | #4 |
| 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. | |
| |
| | #5 |
|
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; } | |
| |
|
| 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 |