Home > other >  SCM interrupt exit
SCM interrupt exit

Time:09-20

Small white ask bosses, 51 microcontroller STC89C52 chip, made a adjustment LED headlamp unit based on the environmental illumination, infrared manual control in the implementation of the time there was a problem: infrared single-chip microcomputer to control, but don't know how to quit after control external interrupt 0, although there are response and LED headlamp unit in control, but also a bit of a very weak light, and the light will be susceptible to automatically adjust again, ask bosses give directions

CodePudding user response:

Such as bosses,,,,,,,,,

CodePudding user response:

Call others guessing? No PIC, no code!

CodePudding user response:

refer to the second floor the wise know already should good karma response:
call others guessing? No PIC, no code!

I'm sorry, I'm code directly stick up? I am alone when a comment, because I write the code is not standard, still want to is to realize the function

CodePudding user response:

refer to the second floor the wise know already should good karma response:
call others guessing? No PIC, no code!

# include "reg52. H"//this file defines the MCU some special function register # include "XPT2046. H" typedef unsigned int under-16;//to statement to define data types typedef unsigned char u8; Sbit LSA=P2 ^ 2; Sbit LSB=P2 ^ 3; Sbit LSC=P2 ^ 4; Sbit LED1=P2 ^ 0; Sbit LED3=P2 ^ 5; Sbit LED4=P2 ^ 6; Sbit LED5=P2 ^ 7; Sbit IRIN highlights=P3 ^ 2; Under-16 leed. U8 disp [4]. U8 IrValue [6]. U8 Time; U8 DisplayData [8]. U8 code smgduan [10]={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * letter of several: delay * function function: delay function, I=1, delay about 10 us * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void delay (under-16 I) {while (I -); }/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function name: IrInit * () function: initialize the infrared receiver * input: without output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void IrInit () {IT0=1;//drop along the trigger EX0=1;//open the interrupt 0 allows EA=1;//open the interrupt IRIN highlights=1;//initialize the port}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function name: datapros () * functions: data processing function * input: without output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */under-16 datapros () {under-16 temp. The static u8 I; If (I==50) {I=0; Temp=Read_AD_Data xa4 (0);//AIN2 photoresistance} i++; Leed=temp; Disp [0]=smgduan temp/1000;//one thousand disp [1]=smgduan 1000/100 [temp %];//one hundred disp [2]=smgduan [temp % 1000% 100/10];//bits disp [3]=smgduan 10] [temp % 1000% 100%; Return leed. }/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function name: DigDisplay * () function features: * enter the digital tube display function: no output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void DigDisplay () {u8 I; for(i=0; i<4. I++) {switch (I)//person, choose the digital tube light, {case (0) : LSA=0; LSB=0; LSC=0; break;//show 0 case (1) : the LSA=1; LSB=0; LSC=0; break;//show a case 1 (2) : the LSA=0; LSB=1; LSC=0; break;//show the second case (3) : the LSA=1; LSB=1; LSC=0; break;//show the third} P0=disp [3 -] I;//send data delay (100);//for a period of time between scanning P0=0 x00;//blanking}}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * letter of several: LedPlay * function function: LED display gear * entered: no * output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void LedPlay () {under-16 involvement by sutl=leed/100; The switch (involvement by sutl) {case 1: LED4=0; LED5=0; LED3=0; break; Case 2: LED4=0; LED5=0; LED3=1; break; Case 3: LED4=0; LED5=0; LED3=1; break; Case 5: LED4=1; LED5=0; LED3=1; break; Default: LED4=1; LED5=1; LED3=1; }}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function name: SponseIr () function: * function according to make action * input operation: IrValue output: * no * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void SponseIr under-16 (dat) {switch (dat) {case 0 x0c: LED3=1; break; Case 0 x18: LED3=1; LED4=1; break; Case 0 x5e: LED3=1; LED4=1; LED5=1; break; }}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * letter of several: the main function: * function main function * entered: no * output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void main () {IrInit ();//infrared initialize the while (1) {datapros ();//the data processing function DigDisplay ();//digital tube display function LedPlay ();//the LED response function SponseIr (IrValue [2]). }}///infrared response * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the function name: ReadIr () function: * function reads the interrupt function of infrared numerical * input: without output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */void ReadIr () interrupt 0 {u8 j, k; Under-16 err; Time=0; Delay (700);//7 ms if (IRIN highlights==0)//confirm whether to receive the correct signal {err=1000;//1000 * 10 us=10 ms, more than that to receive the wrong signal/* when the two terms are really cycle, if there is a conditional jump out of the loop is false, lest program error, die here */while ((IRIN highlights==0) & amp; & (err> 0))//wait {the 9 in front of the low level of ms delay (1); Err,; } the if (IRIN highlights==1)//if correct wait until 9 ms low level {err=500; While ((IRIN highlights==1) & amp; & (err> 0))//wait for 4.5 ms initial high level {past delay (1); Err,; } the for (k=0; K<4. K++) {//a total of four groups of data for (j=0; J<8; J++)//receiving a set of data {err=60; While ((IRIN highlights==0) & amp; & (err> 0))//waiting for the signal in front of us low level over the past 560 {delay (1); Err,; } err=500; While ((IRIN highlights==1) & amp; & (err> 0))//high level the length of time calculation, {delay (10);//0.1 ms Time++; Err,; If (Time> 30) {return; }} IrValue [k] & gt;>=1; Which set of data//k said the if (Time> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related