This piece of code is a piece of clock code designed to program the timer T0
of the 89C52
single-chip microcomputer.
#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f}; //Segment code of common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,10,0,0}; //Hours, minutes, seconds, num is the number of T0 interrupts, disbuf is the number of bits displayed
#define codport P0; //Display segment code output port
#define sitport P2; //Display bit code output port
void display() //Display function
{
unsigned int j; //used 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; //Clean the screen before displaying new content, otherwise it will display disorderly in Proteus
codport=ledcode[disbuf[i]]; //The number to be displayed is sent to the broken code port
sitport=~scan; //The low-level corresponding bit of the bit code port is valid and lights up
scan=(scan<<1);
for(j=0;j<500;j++);
}
}
In the following program, the compiler displays 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).
The location found to be wrong is
codport=0; //Clean the screen before displaying new content, otherwise it will display disorderly in Proteus
codport=ledcode[disbuf[i]]; //The number to be displayed is sent to the broken code port
sitport=~scan; //The low-level corresponding bit of the bit code port is valid and lights up
Since the bit operation is required for codport
and sitport
, the modification macro is defined as
#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f}; //Segment code of common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,10,0,0}; //Hours, minutes, seconds, num is the number of T0 interrupts, disbuf is the number of bits displayed
sibt codport=P0; //Display segment code output port
sbit sitport=P2; //Display bit code output port
Compile successfully after modification