1#include? <reg52.h>2 #defineUchar unsigned char3 #defineUINT unsigned int4 //number of LED digital tubes5Sbit DIO = p2^0;//Serial Data Input6Sbit LRCLK = p2^1;//clock pulse signal--rising edge effective7Sbit LSCLK = p2^2;//Incoming signal ———— rising edge8UnsignedCharCode led_0f[] =9{//0 1 2 5 6 9 A BC D E F-Ten 0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8c,0xBF,0xC6,0xa1,0x86,0xFF,0XBF One }; AUchar Scan_keyboard (void);//Scan Keyboard - voidDelay_ms (intn);//millisecond-delay function - voidget_led (Uchar key);//get the array values for the LEDs the voidLED_ON (Uchar x);//Light LED Digital tube - voidMain () - { - while(1){ +Uchar key =Scan_keyboard (); - get_led (key); + } A } at voidDelay_ms (intN) - { - inti =0, j =0; - for(i =0; I < n; i++) - for(j =0; J < -; J + +); - } in voidled_on (Uchar lcode) - { to UINTi; + for(i =8; I >=1; i--) - { the if(Lcode &0x80) *DIO =1; $ ElsePanax NotoginsengDIO =0; -Lcode <<=1; theLSCLK =0; +LSCLK =1; A } the } + voidLed_code (uchar value) - { $Uchar Code *led_table;//Look up the table pointer $Uchar Lcode;//to get the display code - //Show 1th bit -led_table = led_0f +value; theLcode = *led_table; - led_on (lcode);WuyiLED_ON (0x01); theLRCLK =0; -LRCLK =1; Wu //Show 2nd Bit - } About voidget_led (uchar key) $ { - if(Key = =0x00) - return;//if it is 0x00, the description does not scan to a value and returns - Switch(Key) A { + Case 0xEE: Led_code (0); Break;//0 Press the corresponding key to display the corresponding code value the Case 0xde: Led_code (1); Break;//1 Press the corresponding key to display the corresponding code value - Case 0xBE: Led_code (2); Break;//2 $ Case 0x7e: Led_code (3); Break;//3 the Case 0xed: Led_code (4); Break;//4 the Case 0xDD: Led_code (5); Break;//5 the Case 0xbd: Led_code (6); Break;//6 the Case 0x7d: Led_code (7); Break;//7 - Case 0xeb: Led_code (8); Break;//8 in Case 0xdb: Led_code (9); Break;//9 the Case 0XBB: Led_code (Ten); Break;//a the Case 0x7b: Led_code ( One); Break;//b About Case 0xe7: Led_code ( A); Break;//C the Case 0xd7: Led_code ( -); Break;//D the Case 0xb7: Led_code ( -); Break;//e the Case 0x77: Led_code ( the); Break;//F + } - } the Uchar Scan_keyboard ()Bayi { theUchar Row_wire, Col_wire;//define line and column lines, line 0-3, line 4-7 theP1 =0xf0;//line output is all 0, line output is all 1 -Col_wire = P1 &0xf0;//read into row line value - if(Col_wire! =0xf0) the { theDelay_ms (1);//to shake the delay the if(Col_wire! =0xf0) the { -Col_wire = P1 &0xf0;//read into row line value theP1 = Col_wire |0x0f;//output Current column line values theRow_wire = P1 &0x0f;//Read line values the return(Col_wire + row_wire);//keyboard Last combination code value94 } the } the return 0x00; the}
Single chip microcomputer & 4x4 Matrix keyboard & 4-bit serial 595 Digital tube display