我使用的是 w78e58bp 单片机,对开关通断进行判断,使用的是74HC165 ,总共44路,其中22路为常开,另外22为常闭。随着凸轮转动,开关进行通断,开关一边接5V高电平,另一边接74HC165的引脚,当通时,165输出信号,CPU采集判断。外部中断 HOR_IN=P3^4; //外部计数中断 采用光耦计数,一圈计数2次show_time为实际计数次数 test_time为要求的计数次数。当show_time=test_time,停止计数并显示44路信号通断次数。现在有个问题是,当show_time++到250多次时候就会停止采集信号并显示通断次数了。初步认为是定义show_time为 char data 最大数字为255 ,所以计数到这里就停止,但是当我定义show_time为 int data 时候,编译不过去。出现这个 PUBLIC REFERS TO IGNORED SEGMENT ,技术水平有限,求帮助,下面是部分相关程序,还需要什么请说明。!谢谢!!! unsigned char data test_time,show_time,key_number;unsigned char data OXL,OY,xl,y;bit status,r_in,s_out;unsigned char idata flag[44];unsigned int data IO[44];unsigned char idata mid[4],showmid[4],ct[4];sbit P10=P1^0;sbit P11=P1^1;sbit P12=P1^2;sbit P13=P1^3;sbit P14=P1^4;sbit P15=P1^5;sbit P16=P1^6;sbit P17=P1^7;sbit LCD_AO=P2^0; sbit LCD_CS=P2^1; sbit LCD_RST=P2^2;sbit KEY_CLK=P2^3; sbit KEY_CS=P2^4;sbit IO_PL=P2^5;sbit KEY_INT=P3^2;//KEY连接P3.2 sbit HOR_IN=P3^4; //外部计数中断sbit KEY_DATA=P3^5;//Dat连接P3.5 sbit IO_CLK=P4^0;sbit P42=P4^2; void load_io(void) //判断开关通断的程序,通为1 ,断为0 { unsigned char i; P1=0xff; IO_CLK=0; IO_PL=0; delay(4); IO_PL=1; delay(4);/* for(i=0;i<2;i++) { IO_CLK=1; delay(4); IO_CLK=0; } *//*现在取常开信号,如果需要再加常闭信号*/ for(i=0;i<22;i++) { if (P10) { if(flag==0) { IO=IO+1; flag=1; } } else { flag=0; } if (P11==0) //23-44 { if(flag[22+i]==0) { IO[22+i]=IO[22+i]+1; flag[22+i]=1; } } else { flag[22+i]=1; } P1=0xff; IO_CLK=1; delay(4); IO_CLK=0; }} void show_no2_led(void){ unsigned char i,led_num_add,key_int_num; bit sure_flag=0;/*****************************输入显示**********************************/ for (i=0;i<7;i++) //输入"请输入测试次数" { OXL=0x00+(2*i); OY=0x27+0x0A; write_led_16(22+i); } OXL=0x0E; OY=0x27+0x0A; write_led_16(35); //“:” for (i=0;i<4;i++) { OXL=0x10+(2*i); OY=0x2c+0x0A; write_led_16(0); }/*****************************判断按键**********************************/ OXL=0x10; OY=0x27+0x0A; xl=OXL; y=OY; status=0; while(sure_flag==0) { key_number=0xFF; if(status == 1)//if keyboard has been pressed { key_number=read7279(CMD_READ);//Read the keyboard delay(6000); switch (key_number) { case 0x0B : led_num_add=0; //输入"0" break; case 0x0E : led_num_add=1; //输入"1" break; case 0x03 : led_num_add=2; //输入"2" break; case 0x02 : led_num_add=3; //输入"3" break; case 0x0D : led_num_add=4; //输入"4" break; case 0x06 : led_num_add=5; //输入"5" break; case 0x05 : led_num_add=6; //输入"6" break; case 0x0C : led_num_add=7; //输入"7" break; case 0x09 : led_num_add=8; //输入"8" break; case 0x08 : led_num_add=9; //输入"9" break; case 0x0a : led_num_add=0x0a; break; case 0x07 : led_num_add=0x0b; break; default: led_num_add=0x0c; break; } if(led_num_add!=0x0a&&led_num_add!=0x0b&&led_num_add!=0x0c) { if(key_int_num<4) { write_led_16(led_num_add); switch (key_int_num) { case 0 : mid[0]=led_num_add; break; case 1 : mid[1]=led_num_add; break; case 2 : mid[2]=led_num_add; break; case 3 : mid[3]=led_num_add; break; default: break; } key_int_num=key_int_num+1; OXL=OXL+2; } } else if (key_number==0x0b) { OXL=xl; OY=y; key_int_num=0; clear_man_sel(); } else if(key_number==0x0a) { sure_flag=1; } else { ; } } status=0; } sure_flag=0;/*****************************由按键内容计算测试次数**********************************/ switch(key_int_num) { case 0 : test_time=0; break; case 1 : test_time=mid[0]; break; case 2 : test_time=mid[0]*10+mid[1]; break; case 3 : test_time=mid[0]*100+mid[1]*10+mid[2]; break; case 4 : test_time=mid[0]*1000+mid[1]*100+mid[2]*10+mid[3]; break; default : break; }/*****************************通信从CPU**********************************//********************开始计数直到要求的测试次数**************************/ while(test_time!=show_time) { load_io(); } write_sure();/*****************************通信从CPU**********************************/} void hor_int1(void) interrupt 2 using 1 //INT1中断{ unsigned char i; if(show_time { show_time=show_time++; /* showmid[0]=showmid[0]+1; if(showmid[0]==10) { showmid[0]=0; showmid[1]=showmid[1]+1; } if(showmid[1]==10) { showmid[1]=0; showmid[2]=showmid[2]+1; } if(showmid[2]==10) { showmid[2]=0; showmid[3]=showmid[3]+1; } if(showmid[3]==10) { showmid[3]=0; showmid[4]=showmid[4]+1; } if(showmid[4]==10) { showmid[4]=0; showmid[3]=0; showmid[2]=0; showmid[1]=0; showmid[0]=0; } for (i=0;i<5;i++) { OXL=0x10+(2*i); OY=0x2c+0x0A; write_led(showmid); }*/ }} |