📄 164display_test.c
字号:
// Target: C8051F32x
// Tool chain: Keil C51 8.16
// Command Line: None
//
// Release 1.0
// -Initial Revision (TP)
// -2008-11-17
//
//-----------------------------------------------------------------------------
// Includes and Device-Specific Parameters
//-----------------------------------------------------------------------------
#include <C8051F320.h>
#include "164display.h"
unsigned char key_data,key_state=0xff ;
bit KEY_FLAG=1;
#define KEY P2
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void PORT_Init (void);
void delay_ms(unsigned int ms);
void Key_Scan();
void Key1() ;
void Key2() ;
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main ()
{
PCA0MD &= ~0x40; // WDTE = 0 (disable watchdog timer)
OSCICN |= 0x03; // Set internal oscillator to highest
PORT_Init ();
while(1)
{
Key_Scan();
delay_ms(1);
}
}
//-----------------------------------------------------------------------------
// Initialization Routines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void PORT_Init ()
{
P0MDOUT = 0x00; // All P0 pins open-drain output
P1MDOUT |= 0xff; // Make the p1 a push-pull
// output
P2MDIN |= 0x03; // for key
XBR0 = 0x00; // Enable SMBus pins
XBR1 = 0x40; // Enable crossbar and weak pull-ups
P1 = 0xFF;
}
//-----------------------------------------------------------------------------
void delay_ms(unsigned int ms)
{
unsigned int delay_cx;
for(;ms>0;ms--)
{
for(delay_cx=0;delay_cx<123*12;delay_cx++);
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Key_Scan()
{
KEY=0XFF;
key_data=KEY;
if(key_data!=0xff)
{
//有按键
key_state<<=1;
if(!key_state)
{
if(KEY_FLAG)
{
//按键刚按下
KEY_FLAG=0;
key_data=KEY;
if(key_data==0XFE) Key1();
if(key_data==0XFD) Key2();
}
/*
else
{
//连续按建
}
*/
}
}
else
{
//没有按键
key_state=(key_state<<1)|0x01;
if(key_state==0xff)
{
KEY_FLAG=1;
}
}
}
//-----------------------------------------------------------------------------
void Key1()
{
Led_Display (1);
}
void Key2()
{
Led_Display (2);
}
//-----------------------------------------------------------------------------
// End Of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -