本帖最后由 lettersprite 于 2016-1-12 16:50 编辑
//本程序只是不求精确的时钟程序,使用的是金沙滩工作室学习板
#include <reg52.h>sbit ADDR0 = P1^0;sbit ADDR1 = P1^1;sbit ADDR2 = P1^2;sbit ADDR3 = P1^3;sbit ENLED = P1^4;unsigned char code image[] ={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};char ge,shi,bai,qian,wan,shiwan,sec;char fen=25;char xiaoshi=15;
//static unsigned int shu=0;//static unsigned char i=0;void main(){ EA = 1; //使能总中断 ENLED = 0; //使能U4,选择LED点阵 ADDR3 = 1; TMOD = 0x01; //设置T0为模式1 TH0 = 0xFC; //为T0赋初值0xFC67,定时1ms TL0 = 0x67; ET0 = 1; //使能T0中断 TR0 = 1; //启动T0 while (1) { ge=sec%10; shi=sec/10%10; bai=fen%10; qian=fen/10%10; wan=xiaoshi%10; shiwan=xiaoshi/10%10; }}/* 定时器0中断服务函数 */void InterruptTimer0() interrupt 1{ TH0 = 0xFC; //为T0赋初值0xFC67,定时1ms TL0 = 0x67;
static unsigned int shu=0;//定时计数 static unsigned char i=0;//数码管片选//这两个静态变量放在主程序前,程序能正常编译,但是放这里就出错,为什么?有什么问题吗?求大神指点。 if(shu==1000){shu=0;sec++;} if(sec==60){sec=0;fen++;} if(fen==60){fen=0;xiaoshi++;} if(xiaoshi==24){xiaoshi=0;} shu++; switch (i) { case 0:ADDR0=0;ADDR1=0;ADDR2=0;P0=image[ge];i++;break; case 1:ADDR0=1;ADDR1=0;ADDR2=0;P0=image[shi];i++;break; case 2:ADDR0=0;ADDR1=1;ADDR2=0;P0=image[bai];i++;break; case 3:ADDR0=1;ADDR1=1;ADDR2=0;P0=image[qian];i++;break; case 4:ADDR0=0;ADDR1=0;ADDR2=1;P0=image[wan];i++;break; case 5:ADDR0=1;ADDR1=0;ADDR2=1;P0=image[shiwan];i=0;break; default:break; } }
错误提示:Build target 'Target 1'assembling STARTUP.A51...compiling lianxi.c...LIANXI.C(39): error C141: syntax error near 'static'LIANXI.C(39): error C202: 'shu': undefined identifierLIANXI.C(40): error C141: syntax error near 'static'LIANXI.C(40): error C202: 'i': undefined identifierLIANXI.C(41): error C202: 'shu': undefined identifierLIANXI.C(41): error C202: 'shu': undefined identifierLIANXI.C(45): error C202: 'shu': undefined identifierLIANXI.C(46): error C202: 'i': undefined identifierLIANXI.C(48): error C202: 'i': undefined identifierLIANXI.C(49): error C202: 'i': undefined identifierLIANXI.C(50): error C202: 'i': undefined identifierLIANXI.C(51): error C202: 'i': undefined identifierLIANXI.C(52): error C202: 'i': undefined identifierLIANXI.C(53): error C202: 'i': undefined identifierTarget not created
-
-
程序.txt
下载积分: 积分 -1 分
2.3 KB, 下载次数: 8, 下载积分: 积分 -1 分
希望对你有帮助吧
一周热门 更多>