1、此段代码为对89C52单片机的定时器T0编程,设计的一段时钟代码。
#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,10,0,0};
#define codport P0;
#define sitport P2;
void display()
{
unsigned int j;
unsigned char i,scan;
scan=0x01;
for(i=0;i<6;i++)
{
codport=0;
codport=ledcode[disbuf[i]];
sitport=~scan;
scan=(scan<<1);
for(j=0;j<500;j++);
}
}
2、在下列程序中,编译显示报错 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).
定位发现出错的是
codport=0;
codport=ledcode[disbuf[i]];
sitport=~scan;
3、由于对codport和sitport需要进行的是位操作,则将修改宏定义为
#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,10,0,0};
sibt codport=P0;
sbit sitport=P2;
4、修改后编译成功
|