/******问题描述**********/
我只包含了一次reg52.h,但是编译器提示TMOD, TH1,TL1,ET0等都重复定义了,我也不是很明白为什么会这样。
lesson15_1.c(49): error C141: syntax error near '{'
lesson15_1.c(50): error C231: 'TMOD': redefinition
lesson15_1.c(50): error C231: 'TMOD': redefinition
lesson15_1.c(51): error C231: 'TH0': redefinition
lesson15_1.c(51): error C231: 'TH0': redefinition
lesson15_1.c(52): error C231: 'TL0': redefinition
lesson15_1.c(52): error C231: 'TL0': redefinition
lesson15_1.c(53): error C231: 'ET0': redefinition
lesson15_1.c(53): error C231: 'ET0': redefinition
lesson15_1.c(54): error C231: 'TR0': redefinition
lesson15_1.c(54): error C231: 'TR0': redefinition
lesson15_1.c(55): error C141: syntax error near '}'
/********************************源程序*********************************/
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define DataPort P0 //定义数据端口 程序中遇到DataPort 则用P0 替换
- uchar code DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- sbit Bit_Latch = P2^3;
- sbit Seg_Latch = P2^2;
- sbit infrared_receiver = P3^2;//P3^2是外部中断0的引脚
- uchar irtime;//红外全局变量
- bit irpro_ok, irok;//红外数据处理标志位,红外接收标志位
- uchar ircord[4], irdata[33];
- void IR_work();
- void IRcordpro();
- void Init_Timer0();
- void EX0_Init();
- void main()
- {
- Init_Timer0();//定时器0初始化
- EX0_Init();//外部中断初始化
-
- DataPort = 0xfe;
- Bit_Latch = 1;
- Bit_Latch = 0;
-
- while(1)
- {
- if(irok)
- {
- IRcordpro();
- irok = 0;
- }
- if(irpro_ok)//如果处理好后进行工作处理,如按对应的按键后显示对应的数字等
- {
- IR_work();
- }
- }
- }
- void Init_Timer0();
- {
- TMOD = 0x02;
- TH0 = 0x00;
- TL0 = 0x00;
- ET0 = 1;
- TR0 = 0;
- }
- void EX0_Init()
- {
- IT0 = 0;//外部中断0下降沿触发
- EX0 = 1;
- EA = 1;//开总中断
- }
- void IRcordpro()
- {
- uchar i, j, k;
- uchar cord, value;
-
- k = 1;
- for(i=0;i<4;i++)
- {
- for(j=0;j<8;j++)
- {
- cord = irdata[k];
- if(cord > 7)
- {
- value |= 0x80;
- }
- if(j<7)
- {
- value >>= 1;
- }
- k++;
- }
- ircord[i] = value;
- value = 0;
- }
- irpro_ok = 1;
- }
- void IR_work()
- {
- switch(ircord[2])
- {
- case 0x0c: DataPort = DuanMa[1];break;
- case 0x18: DataPort = DuanMa[2];break;
- case 0x5e: DataPort = DuanMa[3];break;
- case 0x08: DataPort = DuanMa[4];break;
- case 0x1c: DataPort = DuanMa[5];break;
- case 0x5a: DataPort = DuanMa[6];break;
- case 0x42: DataPort = DuanMa[7];break;
- case 0x52: DataPort = DuanMa[8];break;
- case 0x4a: DataPort = DuanMa[9];break;
- default: break;
- }
- irpro_ok = 1;
- }
- void Timer0() interrupt 1 using 1//定时器0中断
- {
- irtime++;
- }
- void EX0_IR() interrupt 0 //外部中断0
- {
- static uchar i;
- static bit startflag;
-
- if(startflag)
- {
- if(irtime < 63 && irtime > 33)
- {
- i = 0;
- }
- irdata[i] = irtime;
- irtime = 0;
- i++;
- if(i == 33)
- {
- irok = 1;
- i = 0;
- }
-
- }
- else
- {
- irtime = 0;
- startflag = 1;
- }
- }
复制代码
各位大佬走过路过进来帮我看看呀。
|