📄 main.c
字号:
#include <main.h>
#include <REG54.H>
#define TRUE 0x1
#define FALSE 0x0
typedef unsigned int uint;
typedef unsigned char uchar;
sbit keyOne=P1^0; //--setkey
sbit keyTwo=P1^1; //--number is select to fist Led
sbit keyThree=P1^2; //--number is select to second Led
sbit keyFour=P1^3; //--save
sbit keyFive=P0^7; //--positoin
sbit keySix=P2^7; //--otherS key
//--
sbit RelayOne=P1^4; //--
sbit RelayTwo=P1^6; //--
sbit RelayThree=P1^7; //--
sbit RelayFour=P1^5; //--
sbit RelayFive=P3^0; //--
sbit RelaySix=P3^1; //--
sbit RelaySeven=P3^2; //--
sbit RelayEight=P3^3; //--
sbit RelayNine=P3^4; //--
sbit RelayTen=P3^5; //--
//--
#define firstL 0x34
#define secondL 0x24
#define thirdL 0x13
#define fourth 0x1f
#define huaChe
#define ZhengXin
#define modeA 0x12
#define ModeB 0x13
unsigned char const CharCodeForBcd[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x7e,0x97,0x79};
const unsigned char p2code[]={0x7e,0x30,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x7e,0x97,0x79};
unsigned char keyOneValue = 0;//--S1的按键for select workMode
unsigned char keyTwoValue = 0;//--S2的按键次数 for select motoin
unsigned char keyThreeValue = 0;//--S3的按键次数
unsigned char keyFourV = 0;
void delayMs(uint n);//--延时函数
void display(unsigned char keyA,unsigned char keyB);//--数码管运算显示
void keyboardScan(void);//--按键扫描
void RelayControl(unsigned VP1,unsigned char VP3);//--
void main(void)
{
P1 = 0xff; //---初始化系统
P3 = 0xff;
P0 = 0xff;
P2 = 0xff;
delayMs(1);
while(1)
{
keyboardScan();
display(keyOneValue,keyTwoValue);
}
}
void delayMs(uint n)//--延时函数
{
while(n)
{
n--;
}
}//--
void display(unsigned char keyA,unsigned char keyB)//--数码管运算显示
{
switch(keyA)
{
case 0:
break;
case 1:
break;
}
P0=CharCodeForBcd[Value & 0x0f];
P2=p2code[(Value & 0xf0)>>4];
}
//--
void keyboardScan(void)//--按键扫描
{
static bit a = 0;
static bit b = 0;
static bit c= 0;
static bit d= 0;
if(keyOne == FALSE) //--按S1
{
if(~a)
{
delayMs(10);
if(keyOne == FALSE)
{
a =1;
keyOneValue++;//--process keyValue
if(keyOneValue>5)
keyOneValue=0;
}
}
}
else a =0;
if(keyTwo == FALSE)//--按S2
{
if(~b)
{
delayMs(10);
if(keyTwo == FALSE)
{
b = 1;
keyTwoValue++;
if(keyTwoValue>5)
keyTwoValue=0;//--process keyValue
}
}
}
else b =0;
if(keyThree == FALSE)//--按S3
{
if(~c)
{
delayMs(10);
if(keyThree == FALSE)
{
c = 1;
keyThreeValue++;
if(keyThreeValue>2)
keyThreeValue=0; //--process keyValue
}
}
}
else c = FALSE;
if(keyFour == FALSE)//--按S3
{
if (~d)
{
delayMs(10);
if(keyFour == FALSE)
{
d = 1;
keyFourV++;
if(keyFourV>2)
keyFourV=0; //--process keyValue
}
}
}
else d = FALSE;
}
void RelayControl(unsigned VP1,unsigned char VP3)//--
{
;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -