
DJI drones, Fluke multimeters, Xiaomi phones, Huawei watches are waiting for you!

void wrc(uint8 c){ delay(1); rs=0; rw=0; e=0; P0=c; e=1; delay(1); e=0;}void wrd(uint8 dat){ delay(1); rs=1; rw=0; e=0; P0=dat; e=1; delay(1); e=0; rs=0;}void init(){ delay(1); wrc(0x38); wrc(0x38); wrc(0x38); wrc(0x06); wrc(0x0c); wrc(0x01);}
unsigned char A_D(unsigned char CH) //AD function{ unsigned char i,adval,test; //define local variables and initialize adval=0x00; test=0x00; DI=1; //DI initial high level before the first clock pulse's falling edge, indicating the start signal _nop_(); CS=0; //chip select _nop_(); Clk=1; //clk rising edge, start bit written in _nop_(); if(CH==0x00) //select channel 0 { Clk=0; //clk low level DI=1; _nop_(); Clk=1; //clk rising edge, first bit of channel 0 written in _nop_(); Clk=0; DI=1; _nop_(); Clk=1; //clk rising edge, second bit of channel 0 written in _nop_(); } else { Clk=0; DI=1; _nop_(); Clk=1; //clk rising edge, first bit of channel 1 written in _nop_(); Clk=0; DI=1; _nop_(); //clk rising edge, second bit of channel 1 written in Clk=1; _nop_(); } Clk=0; DI=1; for(i=0;i<8;i++) //read eight AD values from high to low { _nop_(); adval<<=1; Clk=1; _nop_(); Clk=0; if(DO) adval|=0x01; else adval|=0x00; } for(i=0;i<8;i++) { test>>=1; //read eight AD values from low to high if(DO) test|=0x80; else test|=0x00; _nop_(); Clk=1; _nop_(); Clk=0; } if(adval==test) dat=test; //if both read values are equal, assign the read number to DAT _nop_(); CS=1; DO=1; Clk=1; return dat; }
uint8 keyscan() //key scan program{ uint8 h,l,value; P1=0x0f; h=P1&0x0f; if(h!=0x0f) { delay(1); if(h!=0x0f) { h=P1&0x0f; l=P1|0xf0; P1=l; l=P1&0xf0; h=P1&0x0f; value=h+l; } return value; }}





Click to read the original text, to learn more about the event!