我遇到一个问题 就是 delay函数有重复定义,不知道怎么修改了
- #include<reg52.h>
- #include<intrins.h>
- #include<mouse.h>
- #define unchar unsigned char;
- #define unint unsigned int;
- sbit beef=P3^7;
- unchar i,j;
- unchar code LM[8]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};
- unchar code RM[8]={0x11,0x99,0x88,0xcc,0x44,0x66,0x22,0x33};
- unchar code forward[8]={0x11,0x93,0x82,0xc6,0x44,0x6c,0x28,0x39};
- void delay_ms(unsigned int z)
- {
- unsigned char i,j;
- while(--z){
- _nop_();
- i=2;
- j=199;
- do{
- while(--j);
- }
- while(--i);
- }
- }
- void runLM(bit f){
- if(f){
- for(j=0;j<55;j++){
- for(i=0;i<8;i++){
- P1=(RM[i]);
- delay_ms(3);
- }
- }
- }
- }
- void runRM(bit f){
- if(f){
- for(j=0;j<55;j++){
- for(i=0;i<8;i++){
- P1=(LM[i]);
- delay_ms(3);
- }
- }
- }
- }
- void turnOff(bit f){
- if(f){
- for(j=0;j<110;j++){
- for(i=0;i<8;i++){
- P1=(LM[i]);
- delay_ms(3);
- }
- }
- }
- }
- void Lxz(bit f){
- if(f){
- for(j=0;j<8;j++){
- for(i=0;i<8;i++){
- P1=(RM[i]|0x0f);
- delay_ms(3);
- }
- }
- }
- }
-
- void Rxz(bit f){
- if(f){
- for(j=0;j<8;j++){
- for(i=0;i<8;i++){
- P1=(LM[i]|0xf0);
- delay_ms(3);
- }
- }
- }
- }
-
- void Go(bit f){
- if(f){
- for(j=0;j<101;j++){
- for(i=0;i<8;i++){
- P1=(forward[i]);
- delay_ms(3);
- }
- if(irRU==1&&irC==0&irR==1){
- Lxz(1);
- }
- if(irLU==1&&irC==0&&irL==1){
- Rxz(1);
- }
- }
- }
- }
-
- void Control(){
- if(irC==0&&irL==1&&irR==1){
- Go(1);
- delay_ms(800);
- }
- if(irC==1&&irR==1&&irL==0){
- runLM(1);
- delay_ms(800);
- Go(1);
- }
- if(irC==1&&irR==0&&irL==1){
- runRM(1);
- delay_ms(800);
- Go(1);
- }
- if(irC==1&&irR==0&&irL==0){
- runRM(1);
- delay_ms(800);
- Go(1);
- }
- if(irC==0&&irR==0&&irL==0){
- runRM(1);
- delay_ms(800);
- Go(1);
- }
- if(irC==1&irL==1&irR==1){
- turnOff(1);
- delay_ms(800);
- Go(1);
- }
- }
-
- void setTime2(unsigned int us){
- TH2=(65536-us)/256;
- RCAP2H=(65536-us)/256;
- TL2=(65536-us)%256;
- RCAP2L=(65536-us)%256;
- }
- void intTime2(){
- EA=1;
- ET2=1;
- setTime2(5000);
- TR2=1;
- }
- void time2()interrupt 5{
- static bit ir=0;
- TF2=0;
- if(!ir)
- MOUSE_IR_ON(i);
- else{
- switch(i++){
- case 0:{if(irR1){irC=0;}
- else{irC=1;}}break;
- case 1:{if(irR2){irL=0;}
- else{irL=1;}}break;
- case 2:{if(irR3){irR=0;}
- else{irR=1;}}break;
- case 3:{if(irR4){irLU=0;}
- else{irLU=1;}}break;
- case 4:{if(irR5){irRU=0;}
- else{irRU=1;}}break;
- }if(i==5) i=0;
- }ir=~ir;
- }
- void main(){
- setTime2();
- delay_ms(1000);
- while(1){
- Control();
- delay_ms(800);
- }
- }
复制代码 电路图:http://www.51hei.com/bbs/dpj-200855-1.html
|