这是同学给我的C
他说编译无法通过
而我只懂一点点C(看不出什么问题)
请大家指出问题吧
at89s52
貌似用来LED甩钟
#include <reg52.h>
/*硬件端口定义*/
sbit set0=P0^1;
sbit set1=P0^0;
sbit set2=P0^2;
sbit put1=P3^6;
sbit put2=P3^7;
/*时钟用数组*/
unsigned char BUFFER[]={0,0,0,0};
unsigned char maxnum[]={59,23};
/*显示数组*/
unsigned int v[14];
unsigned int w[8];
/*显示中断表*/
int code Tr[]={
2000,2000,2000,2000,2000,2000,
2000,2000,2000,2000,2000,2000,
2000,2000,2000,2000,2000,2000,
2550,2500,2450,2400,2350,2300,
2250,2200,2150,2100,2050,2000,
1950,1900,1850,1800,1750,1700,
1650,1600,1550,1500,1450,1400,
1400,1450,1500,1550,1600,1650,
1700,1750,1800,1850,1900,1950,
2000,2050,2100,2150,2200,2250,
2300,2350,2400,2450,2500,2550,
2000,2000,2000,2000,2000,2000,
2000,2000,2000,2000,2000,2000,
2000,2000,2000,2000,2000,2000,
};
/*字符字模*/
unsigned char code ASCIIDOC[] = // ASCII
{
0x7C,0x8A,0x92,0xA2,0x7C,0x00, // -0-00
0x00,0x42,0xFE,0x02,0x00,0x00, // -1-01
0x46,0x8A,0x92,0x92,0x62,0x00, // -2-02
0x84,0x82,0x92,0xB2,0xCC,0x00, // -3-03
0x18,0x28,0x48,0xFE,0x08,0x00, // -4-04
0xE4,0xA2,0xA2,0xA2,0x9C,0x00, // -5-05
0x3C,0x52,0x92,0x92,0x8C,0x00, // -6-06
0x80,0x8E,0x90,0xA0,0xC0,0x00, // -7-07
0x6C,0x92,0x92,0x92,0x6C,0x00, // -8-08
0x62,0x92,0x92,0x94,0x78,0x00, // -9-09
0x00,0x00,0x00,0x00,0x00,0x00, // - -10
0x00,0x00,0xFA,0x00,0x00,0x00, // -!-11
0x04,0x08,0x10,0x20,0x40,0x00, // -/-12
0x00,0x6C,0x6C,0x00,0x00,0x00, // -:-13
0x3E,0x48,0x88,0x48,0x3E,0x00, // -A-14
0xFE,0x92,0x92,0x92,0x6C,0x00, // -B-15
0x7C,0x82,0x82,0x82,0x44,0x00, // -C-16
0xFE,0x82,0x82,0x82,0x7C,0x00, // -D-17
0xFE,0x92,0x92,0x92,0x82,0x00, // -E-18
0xFE,0x90,0x90,0x90,0x80,0x00, // -F-19
0x7C,0x82,0x8A,0x8A,0x4E,0x00, // -G-20
0xFE,0x10,0x10,0x10,0xFE,0x00, // -H-21
0x00,0x82,0xFE,0x82,0x00,0x00, // -I-22
0x04,0x02,0x82,0xFC,0x80,0x00, // -J-23
0xFE,0x10,0x28,0x44,0x82,0x00, // -K-24
0xFE,0x02,0x02,0x02,0x02,0x00, // -L-25
0xFE,0x40,0x30,0x40,0xFE,0x00, // -M-26
0xFE,0x20,0x10,0x08,0xFE,0x00, // -N-27
0x7C,0x82,0x82,0x82,0x7C,0x00, // -O-28
0xFE,0x90,0x90,0x90,0x60,0x00, // -P-29
0x7C,0x82,0x8A,0x84,0x7A,0x00, // -Q-30
0xFE,0x90,0x98,0x94,0x62,0x00, // -R-31
0x64,0x92,0x92,0x92,0x4C,0x00, // -S-32
0x80,0x80,0xFE,0x80,0x80,0x00, // -T-33
0xFC,0x02,0x02,0x02,0xFC,0x00, // -U-34
0xF8,0x04,0x02,0x04,0xF8,0x00, // -V-35
0xFE,0x04,0x18,0x04,0xFE,0x00, // -W-36
0xC6,0x28,0x10,0x28,0xC6,0x00, // -X-37
0xC0,0x20,0x1E,0x20,0xC0,0x00, // -Y-38
0x86,0x8A,0x92,0xA2,0xC2,0x00, // -Z-39
0x24,0x2A,0x2A,0x1C,0x02,0x00, // -a-40
0xFE,0x14,0x22,0x22,0x1C,0x00, // -b-41
0x1C,0x22,0x22,0x22,0x10,0x00, // -c-42
0x1C,0x22,0x22,0x14,0xFE,0x00, // -d-43
0x1C,0x2A,0x2A,0x2A,0x10,0x00, // -e-44
0x10,0x7E,0x90,0x90,0x40,0x00, // -f-45
0x19,0x25,0x25,0x25,0x1E,0x00, // -g-46
0xFE,0x10,0x20,0x20,0x1E,0x00, // -h-47
0x00,0x00,0x9E,0x00,0x00,0x00, // -i-48
0x00,0x01,0x11,0x9E,0x00,0x00, // -j-49
0xFE,0x08,0x14,0x22,0x02,0x00, // -k-50
0x00,0x82,0xFE,0x02,0x00,0x00, // -l-51
0x1E,0x20,0x1E,0x20,0x1E,0x00, // -m-52
0x20,0x1E,0x20,0x20,0x1E,0x00, // -n-53
0x1C,0x22,0x22,0x22,0x1C,0x00, // -o-54
0x3F,0x24,0x24,0x24,0x18,0x00, // -p-55
0x18,0x24,0x24,0x24,0x3F,0x00, // -q-56
0x20,0x1E,0x20,0x20,0x10,0x00, // -r-57
0x12,0x2A,0x2A,0x2A,0x24,0x00, // -s-58
0x20,0xFC,0x22,0x22,0x24,0x00, // -t-59
0x3C,0x02,0x02,0x3C,0x02,0x00, // -u-60
0x38,0x04,0x02,0x04,0x38,0x00, // -v-61
0x3C,0x02,0x3C,0x02,0x3C,0x00, // -w-62
0x22,0x14,0x08,0x14,0x22,0x00, // -x-63
0x39,0x05,0x05,0x09,0x3E,0x00, // -y-64
0x22,0x26,0x2A,0x32,0x22,0x00, // -z-65
};
unsigned int Ti;
unsigned char ii,jj,mm, ff ,TZ ,Ms ,Ta;
/*延时程序*/
void Delay(unsigned int msec)
{
unsigned int x,y;
for(x=0; x<=msec;x++)
{
for(y=0;y<=110;y++);
}
}
/*键盘去抖处理函数*/
unsigned char ChKey(bit Key)
{
if(Key==0){
Delay(100);
if(Key==0) return(1);
}
}
/*定时中断1 处理(时钟)函数*/
void timer0(void) interrupt 1 using 1
{
TH0=-(50000/256);
TL0=-(50000%256);
TR0=1;
BUFFER[0]=BUFFER[0]+1;
}
/*定时中断2 处理(LED 驱动和音圈驱动)函数*/
void timer1(void) interrupt 3 using 1
{
TH1=Ti/256; TL1=Ti%256;
if((ii*6+jj)==Ta) {put1=~put1;put2=~put2;}; //音圈电机驱动输出
if(ff==1){
if(Ms*w[ii-3]==1) P2=0xff; else P2=~ASCIIDOC[v[ii]*6+jj]; //正向显示
}
else {
if(Ms*w[10-ii]==1) P2=0xff; else P2=~ASCIIDOC[v[13-ii]*6+5-jj]; //反向显示
}
jj++;
if(jj>5) {ii++; jj=0;}
if(ii>13) {ii=0;ff=!ff;}
Ti=-Tr[ii*6+jj]; //读显示中断表
}
/*主程序*/
void main(void)
{
//变量初始化
Ms=0;
ff=0;
Ta=46; //正反显一致性调整, 取值范围在42~50 之间, 根据实际确定
put1=0;put2=1;
//中断初始化
TMOD=0x11;
TH0=-5000/256; TL0=-5000%256;
TR0=1;ET0=1;
TH1=-2000/256; TL1=-2000%256;
TR1=1;ET1=1;
//十四个字符中前三个和后三个不显(不用)
v[0]=10;
v[1]=10;
v[2]=10;
v[11]=10;
v[12]=10;
v[13]=10;
/*摇摆棒初始启动*/
do {
mm++;
Delay(120+mm);
put1=~put1; put2=~put2;
}while(mm<60);
Delay(20);
/*启动显示*/
ii=0;jj=0;
EA=1;
/*正式运行*/
for(;;){
v[3]=36;v[4]=44;v[5]=51;v[6]=42;v[7]=54;v[8]=52;v[9]=44;v[10]=11; //显示欢迎
Delay(6000);
v[3]=10;v[4]=10;v[5]=10;v[6]=10;v[7]=10;v[8]=10;v[9]=10;v[10]=10; //关闭显示
Delay(600);
v[3]=0;v[4]=0;v[5]=13;v[6]=0;v[7]=0;v[8]=13;v[9]=0;v[10]=0; //显示时钟初始状
态
/*进入时钟状态*/
while(1){
//时钟处理
if (BUFFER[0]>21){ //进位到秒
BUFFER[0]=0; BUFFER[1]=BUFFER[1]+1;
Ms=!Ms;
if (BUFFER[1]==60){ //进位到分
BUFFER[1]=0;BUFFER[2]=BUFFER[2]+1;
if (BUFFER[2]==60){
BUFFER[2]=0;BUFFER[3]=BUFFER[3]+1; //进位到时
if (BUFFER[3]==24) BUFFER[3]=0;
}
}
}
//将显示内容送显示缓冲区
v[9]=BUFFER[1]/10;
v[10]=BUFFER[1]-v[9]*10;
v[6]=BUFFER[2]/10;
v[7]=BUFFER[2]-v[6]*10;
v[3]=BUFFER[3]/10;
v[4]=BUFFER[3]-v[3]*10;
//键盘处理
if(ChKey(set0)==1){ //模式键
Ms=1; //秒闪开
if(TZ<2) TZ++; else TZ=0; //三种状态循环转换
switch(TZ){
case 0:w[0]=0;w[1]=0;w[2]=0;w[3]=0;w[4]=0;w[5]=0;w[6]=0;w[7]=0;break;
case 1:w[0]=0;w[1]=0;w[2]=0;w[3]=1;w[4]=1;w[5]=0;w[6]=0;w[7]=0;break;
case 2:w[0]=1;w[1]=1;w[2]=0;w[3]=0;w[4]=0;w[5]=0;w[6]=0;w[7]=0;break;
}
Ms=0; //秒闪关
};
Delay(80);
if(ChKey(set1)==1){ if(BUFFER[TZ+1]<maxnum[TZ-1]) BUFFER[TZ+1]++; else
BUFFER[TZ+1]=0;Delay(300);};
//键盘"+"
if(ChKey(set2)==1){ if(BUFFER[TZ+1]>0) BUFFER[TZ+1]--; else
BUFFER[TZ+1]=maxnum[TZ-1];Delay(300);};
//键盘"-"
Delay(80);
}
}
}
200字以内,仅用于支线交流,主线讨论请采用回复功能。