#include<reg52.h><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
#include<intrins.h>
#define display P1
#define keyboardCode P2
#define uint unsigned int
#define uchar unsigned char
uchar code initialKeyboardCode[] = { 0xef, 0xdf, 0xbf, 0x<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />7f }; //Set the initial keyboard code.
uchar code getKeyboardCode[] = { 0xee, 0xed, 0xeb, 0xe7, 0xde, 0xdd, 0xdb, 0xd7, //When the keyboard pressed
0xbe, 0xbd, 0xbb, 0xb7, 0x7e, 0x7d, 0x7b, 0x77 }; // down ,the mcu will get one of them.
uchar code theActionCode[] = { 0xf7, 0xf4, 0xf1, 0xf0, 0xf8, 0xf5, 0xf2, 0xf0, //The display code, you can rewrite
0xf9, 0xf6, 0xf3, 0xf0, 0xf8, 0xf5, 0xf2, 0xf0 }; // them if you want . But the code you rewrite must correspondence
// with the ”getkeyboardCode”.
void KeyboardScan(void)
{
uchar sender = 0x00;
uchar counterOne = 0x00;
uchar counterTwo = 0x00;
for(counterOne=0x00; counterOne<4; counterOne++)
{
keyboardCode = initialKeyboardCode[counterOne]; //Load the initialKeyboardCode
sender = keyboardCode; //Get the keyboardCode when the keyboard press down
//perhaps a delay here.
for(counterTwo=0x00; counterTwo<16; counterTwo++)
{
if(sender==getKeyboardCode[counterTwo]) //When a geyKeyboardCode equal to the sender ,
{
display = theActionCode[counterTwo];//Then load the display code from the theActioncode
//You can write you control functions here too.
}
}
}
}
//The test main function.
void main(void)
{
display = 0x00;
while(1)
{
KeyboardScan();
}
}
用户1154069 2007-6-1 11:54
我是搞PCB的,没看懂,要学一点才好。