我在medvin里模拟仿真的时候 就可以返回的啊
#include <REG52.H> #include <MATH.H> #include <intrins.h>
#define uchar unsigned char #define uint unsigned int
void Init_T0( ); void Enable_int(); void Watchdog(); void Init_TGC(); void Init_Encoder(); void BeepOn(); void BeepOff(); void Send_Data(uchar bite); void Rec_Data(void); void LightLed(void); void Delay40us();
uint DelayTime,DetectTime; uint ActiveJob,ActiveJob0; uint PortNo,Activeport; uint PWMP; uint BeepMode,BeepTime,BeepReq; uint Gain1Data,Gain2Data; uint IPMode,push;
uchar LED; uchar TgcData[8]; uchar KeyData; uchar Send_Buff; sfr P4=0xC0; sfr ADCH=0xC6; sfr T3=0xFF; sfr ADCON=0xC5; sfr PWM0=0xFC; sfr IEN0=0xA8; sbit Gain1A=P3^0; sbit Gain1B=P3^1; sbit Gain2A=P2^6; sbit Gain2B=P2^7; sbit SwitchB=P3^7; sbit CLK=P2^3; sbit DAT=P2^4; sbit EN0=P3^2; sbit EN1=P3^3; sbit EN2=P3^4;
main() { bit Gain1A0,Gain2A0; uchar row,Table,scan,col; uchar code KeyCode[]= { 0,35,8,9,25,10,11,23, 121,36,0,7,24,119,34,22, 0,37,123,6,26,120,118,21, 0,33,124,5,122,38,117,20, 0,32,0,4,0,39,50,19, 0,47,15,3,31,0,49,18, 133,0,115,125,75,0,0,17, 0,46,116,114,0,52,0,48, 0,81,80,0,0,51,0,16, 0,86,85,0,43,0,61,30, 0,107,113,110,112,101,102,2 }; uchar code pccode[]= {0,52,61,62,68,70,69,60, 9,51,0,54,67,10,43,53, 0,59,7,46,77,1,18,44, 0,35,124,37,120,66,11,45, /* 124 print screen*/ 0,27,0,38,0,75,50,36, 0,34,102,30,28,0,42,29, 133,0,12,126,75,0,0,20, // 133menu 75comment must change 0,26,3,4,0,58,0,33, 0,81,80,0,0,49,0,13, // 81 SAVE 80 FREQ must change 0,86,85,0,90,0,41,88, // 86 85 change 0,107,6,0,5,101,116,22 // 107 101 cahngge }; uchar code LEDcode[]= {121,133,81,86,107,113,85,116, 115,124,123,125,114,112,75,119, 120,101,102,30,117,118,122 }; P2&=0xDF; P0=0xFF; Enable_int(); Init_T0( ); //begin: for(;;) { //ActiveJob=0; P4=0; P2=0x03; if(P1!=0xFF) //check press the key or not { // if(!ActiveJob) //check again ?? // { DelayTime=15; // eliminate trembling while(DelayTime); // } } // P4=0; // P2=0x03; // P1=0xBF;
if (P1!=0xFF) { for(row=0;row<8;row++) { P4=~(1<<row); // check every row P1=0xFF; scan=0x01; for(col=0;col<8;col++) { if((P1&scan)==0) // scan every collume { ActiveJob=1; Table=row+8*col; goto lable; } scan=_irol_(scan,1); } } }
// if(!ActiveJob0) if((P2&0x07)!=0x07) { DelayTime=15; while(DelayTime); }
if((P2&0x07)!=0x07) { for(row=0;row<8;row++) { P4=~(1<<row); // check every row if((P2&0x01)==0) //p2.0 { ActiveJob=1; Table=row+64; goto lable; } if((P2&0x02)==0) //p2.1 { ActiveJob=1; Table=row+72; goto lable; } if((P2&0x04)==0) //p2.2 { ActiveJob=1; Table=row+80; goto lable; } } }
}
lable: if(ActiveJob) { ActiveJob=0; KeyData=pccode[Table]; Send_Data(KeyData); Delay40us(); Delay40us(); Delay40us(); Delay40us(); Delay40us();
// for(LED=0;LED<24;LED++) // { // if(LEDcode[LED]==KeyData) // LightLed(); // } }
//goto begin; } /******************************************* INTERRUPT **************************************/
void T0_Int() interrupt 1 using 1 /* timer0 overflow interrupt */ { bit temp; TR0=0; /* stop timer0 */ TH0=0xFB; TL0=0xF6; /* reload T0 */ TR0=1; /* restart timer0 */ push++; if(push>100) //100ms check the switch { if(SwitchB==0&&temp==1) IPMode++; else if(SwitchB==0) temp=1; if(IPMode>3) IPMode=1; } if(DelayTime>0) DelayTime--; if(BeepTime>0) BeepTime--; }
/******************************************* INITIALIZE *************************************/ void Enable_int() { TCON=0x00; IEN0=0x82; //EA=1 ET0=1
} void Init_T0() /* timer0 initialization */ { TMOD=0x01; /* mode 1, 16-bit timer */ TH0=0xFC, TL0=0x66; /* set counter registers */ TCON|=0x10; /* TR0=1, start timer0 */ } |