Tag Archives: Keil C Error

[Solved] Keil C Error: error C141: syntax error near ‘=‘, expected ‘__asm‘

1. This code is a clock code designed for the timer T0 programming of 89C52 single-chip microcomputer.

#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};	//Segment selection code for common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,0,10,0,0}; //hour,minute,sec,num is the number of T0 interrupts,disbuf is the number of displayed digits
#define codport P0; //Display segment output port
#define sitport P2; //Display bit code output port

void display() //display function
{
	unsigned int j; //for loop
	unsigned char i,scan; //scan is the bit code of the output control display bit, also called scan code
	scan=0x01;
	for(i=0;i<6;i++)
	{
		codport=0; //Display new content before clearing the screen, otherwise it will be displayed incorrectly in Proteus
		codport=ledcode[disbuf[i]]; //the number to be displayed send break code port
		sitport=~scan; //Bit code port low corresponding bit valid, lit
		scan=(scan<<1);
		for(j=0;j<500;j++);
	}
}

2、In the following program, the compilation shows an error
clock.c(14): warning C275: expression with possibly no effect
clock.c(14): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c(15): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c(16): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c – 3 Error(s), 1 Warning(s).
Locating the error found is

codport=0; //clear the screen before displaying new content, otherwise it will be displayed incorrectly in Proteus
codport=ledcode[disbuf[i]]; //the number to be displayed is sent to the code breaking port
sitport=~scan; //Bit code port low corresponding bit valid, lit

3. Since bit operations are required for codport and sitport, the modified macro is defined as

#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};	//Segment selection code for common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,0,10,0,0}; //hour,minute,sec,num is the number of T0 interrupts,disbuf is the number of displayed digits
sibt codport=P0; //display segment code output port
sbit sitport=P2; //display bit code output port

4. Compiled successfully after modification