# Include <export x44x. h> <br/> # define uchar unsigned char <br/> # define uint unsigned int <br/> uchar disp [] = {0x12, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xEE, 0xff }; <br/> unsigned char keyscan (void) // The <SPAN class = 'wp _ keywordlink '> Program </span> has four rows and three columns on the keyboard, 12 buttons <br/>{< br/> unsigned char x = 0xff; <br/> p1dir = 0x0f; <br/> p1out = 0x01; // scan the first line <br/> If (p1in & 0xf0) = 0x10) // If a key is pressed on the first line and on the first line, the key value is 0 <br/> x = 0; <br/> else if (p1in & 0xf0) = 0x20) // If a key is pressed on the first and second columns, the key value is 1 <br/> x = 1; <br/> else if (p1in & 0xf0) = 0x40) // if the first row and the third column have a key <br/> X = 2, the key value is 2 <br/> else if (p1in & 0xf0) = 0x80) // if there is a key on the first and third columns, <br/> X = 3; <br/> else <br/> {<br/> p1out = 0x02; // scan the second row <br/> If (p1in & 0xf0) = 0x10) // If a key is pressed on the line of the second row and the first column, the key value is 3 <br/> X = 4; <br/> else if (p1in & 0xf0) = 0x20) // if there is a key on the line of the second row and the second column, press <br/> X = 5; //, the key value is 4 else <br/> else if (p1in & 0xf0) = 0x40) // If the row 2 and column 3 have a key <br/> X = 6, the key value is 5 <br/> else if (p1in & 0xf0) = 0x80) // If the row 2 and column 3 have a key <br/> X = 7, the key value is 5 <br/> else <br/> {<br/> p1out = 0x04; // scan the third row, <br/> If (p1in & 0xf0) = 0x10) <br/> X = 8; <br/> else if (p1in & 0xf0) = 0x20) <br/> X = 9; <br/> else if (p1in & 0xf0) = 0x40) <br/> X = 10; <br/> else if (p1in & 0xf0) = 0x80) <br/> X = 11; <br/> else <br/> {<br/> p1out = 0x08; // scan row 4 <br/> If (p1in & 0xf0) = 0x10) <br/> X = 12; <br/> else if (p1in & 0xf0) = 0x20) <br/> X = 13; <br/> else if (p1in & 0xf0) = 0x40) <br/> X = 14; <br/> else if (p1in & 0xf0) = 0x80) <br/> X = 15; <br/>}< br/> return (X ); <br/>}< br/> void main () <br/>{< br/> wdtctl = wdtpw + wdthold; <br/> p1dir = 0x0f; <br/> p3dir = 0xff; <br/> while (1) <br/>{< br/> p3out = keyscan (); <br/>}< br/>}
the primary part is a 4*3 Keyboard Scan program, which is changed to a 4*4 Keyboard Scan program.