I am writing a program to control three DC motor levels and display speed (RPM) on a 7-segment LED display using an 8051. I use an external interrupt to read pulse from encoder. When compiling, the program reports an error:
C141: syntax error near '=', expected ';'.
Error at row: led1 = on; P0 = so[thousand]; delay_ms(100); led1 = off;
Only when I delete all the statements in the for loop void hienthi, the program does not report an error.
Here is the code:
#include <reg51.h> #include <stdio.h> #define led1 P2^0 #define led2 P2^1 #define led3 P2^2 #define led4 P2^3 #define on 0 #define off 1 sbit pwm_out = P3^2; sbit low = P1^0; sbit medium = P1^1; sbit high = P1^2; sbit stop = P1^3; unsigned int count = 0, f, t = 0; char so[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90}; // for number 0->9 void init() { TMOD = 0x10; pwm_out = 1; EX0 = 1; ET1 = 1; IT0 = 1; TR1 = 1; EA = 1; } /*increments counter whenever falling edge is detected*/ void demxung() interrupt 0 { count++; } void time() interrupt 3 { t++; TH1 = 0xfc; TL1 = 0x18; TR1 = 1; if (t >= 1000) { f = count; count = 0; t = 0; } } void hienthi (unsigned int dem) { unsigned char thousand, hundred, tens, unit; int i; thousand = dem/1000; hundred = (dem%1000)/100; tens = (dem%100)/10; unit = dem%10; for (i=0; i<20; i++) { led1 = on; P0 = so[thousand]; delay_ms(100); led1 = off; led2 = on; P0 = so[hundred]; delay_ms(100); led2 = off; led3 = on; P0 = so[tens]; delay_ms(100); led3 = off; led4 = on; P0 = so[unit]; delay_ms(100); led4 = off; } } void delay_ms (unsigned int t) { unsigned int i,j; for (i=1; i<=t; i++) { for (j=1; j<125; j++); //delay_ms 1ms } } void main() { pwm_out = 0; init(); while (1) { if (low == 0) { medium = high = 1; low = 0; pwm_out = 1; delay_ms(30); pwm_out = 0; delay_ms(60); } if (medium == 0) { low = high = 1; medium = 0; pwm_out = 1; delay_ms(50); pwm_out = 0; delay_ms(50); } if (high == 0) { low = medium = 1; high = 0; pwm_out = 1; delay_ms(90); pwm_out = 0; delay_ms(10); } if (stop == 0) { low = medium = high = 1; pwm_out = 0; } hienthi (f); } }
sbit pwm_out = P3^2;lines, which I have no idea what are supposed to achieve. This is definitely not a standard C syntax. If it is an extension, are you sure your compiler is supporting it? \$\endgroup\$