51_LanQiaoBei/2025/User/main.c
2025-04-13 01:02:19 +08:00

104 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 头文件申明*/
#include <STC15F2K60S2.H>
#include <Key.h>
#include <Seg.h>
#include <Led.h>
#include <Init.h>
/* 变量申明*/
unsigned char Key_Slow_Down;//按键减速变量
unsigned char Key_Val,Key_Old,Key_Down,Key_Up;
unsigned int Seg_Slow_Down;
unsigned char Seg_Pos;
unsigned char Seg_Buf[8]=
{
16,16,16,16,16,16,16,16
};
unsigned char Seg_Point[8]=
{
0,0,0,0,0,0,0,0
};
unsigned char ucLed[8]=
{
1,0,0,0,0,0,0,0
};
unsigned char Seg_Show;
/* 处理函数key,seg,led*/
void Key_Proc()
{
if(Key_Slow_Down) return;
Key_Slow_Down = 1;
Key_Val = Key_Read();
Key_Down = Key_Val & (Key_Old ^ Key_Val);
Key_Up = ~Key_Val & (Key_Old ^ Key_Val);
Key_Old = Key_Val;
if(Key_Down != 0)
Seg_Show = Key_Down;
}
void Seg_Proc()
{
if(Seg_Slow_Down) return;
Seg_Slow_Down = 1;
Seg_Buf[0] = Seg_Show /10 %10;
Seg_Buf[1] = Seg_Show %10;
}
void Led_Proc()
{
}
/* 定时器函数(初始化、中断函数)*/
void Timer0_Init(void) //1毫秒@12.000MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x18; //设置定时初始值
TH0 = 0xFC; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1;
EA = 1;
}
void Timer0_Server() interrupt 1
{
if(++Key_Slow_Down == 10) Key_Slow_Down = 0;
if(++Seg_Slow_Down == 500) Seg_Slow_Down = 0;
if(++Seg_Pos == 8) Seg_Pos = 0;
Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]);
Led_Disp(Seg_Pos,ucLed[Seg_Pos]);
}
/* 主函数*/
void main()
{
System_Init();
Timer0_Init();
while(1)
{
Key_Proc();
Seg_Proc();
Led_Proc();
}
}