I am writing a program to control 3 DC motor levels and display speed (RPM) on 7 segment LED using 8051. Use external interrupt to read pulse from encoder. When compiling, the program reports error
C141: syntax error near '=', expected ';'.
Here is 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); } }