#include "Seg.h"
unsigned char seg_dula[] = {
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, // 0-7
0x80, 0x90,0xff};
// 位码表 (选择第几位数码管)
unsigned char seg_wela[] = {
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 };
void Seg_Disp(unsigned char wela,dula,point){
P0=0xff;
P2=P2&0x1f|0xe0;
P2&=0x1f;
P0=seg_wela[wela];
P2=P2&0x1f|0xc0;
P2&=0x1f;
if(point)
P0=seg_dula[dula]&0x7f;
else
P0=seg_dula[dula];
P2=P2&0x1f|0xe0;
P2&=0x1f;
}
/* 头文件声明区域 */
#include <Key.h>
#include <Init.h>
#include <Led.h>
#include <Seg.h>
#include <STC15F2K60S2.H>
/* 变量声明区*/
unsigned char Key_Slow_Donw;
unsigned char Seg_Slow_Donw;
unsigned char Key_Val,Key_Donw,Key_Up,Key_Old;
unsigned char Seg_Buf[8]={1,2,3,4,5,6,7,8};
unsigned char Seg_Pos;
unsigned char Seg_Point[8]={0,0,0,0,0,0,0,0};
/*按键处理函数*/
void Key_Proc()
{
if(Key_Slow_Donw) return;
Key_Slow_Donw=1;
Key_Val=Key_Read();
Key_Donw=Key_Val&(Key_Old^Key_Val); // 检测按下
Key_Up=~Key_Val&(Key_Old^Key_Val); // 检测抬起
Key_Old=Key_Val;
}
void Seg_Proc(){
if(Seg_Slow_Donw) return;
Seg_Slow_Donw=1;
}
/* 其他显示函数 */
void Led_Proc()
{
}
void Timer0Init(void) //1毫秒@12.000MHz
{
AUXR |= 0x70; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
}
void Timer0Server() interrupt 1
{
if(++Key_Slow_Donw==10) Key_Slow_Donw=0;
if(++Seg_Slow_Donw==10) Seg_Slow_Donw=0;
if(++Seg_Pos==8) Seg_Pos=0;
Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]);
}
void main(void)
{
sys_init();
Timer0Init();
while(1)
{
Led_Proc();
Key_Proc();
Seg_Proc();
}
return ;
}
我的代码如上 但是出现了下面这些问题/* 头文件声明区域 */
#include <Key.h>
#include <Init.h>
#include <Led.h>
#include <Seg.h>
#include <STC15F2K60S2.H>
/* 变量声明区*/
unsigned char Key_Slow_Donw;
unsigned char Seg_Slow_Donw;
unsigned char Key_Val,Key_Donw,Key_Up,Key_Old;
unsigned char Seg_Buf[8]={1,2,3,4,5,6,7,8};
unsigned char Seg_Pos;
unsigned char Seg_Point[8]={0,0,0,0,0,0,0,0};
/*按键处理函数*/
void Key_Proc()
{
if(Key_Slow_Donw) return;
Key_Slow_Donw=1;
Key_Val=Key_Read();
Key_Donw=Key_Val&(Key_Old^Key_Val); // 检测按下
Key_Up=~Key_Val&(Key_Old^Key_Val); // 检测抬起
Key_Old=Key_Val;
}
void Seg_Proc(){
if(Seg_Slow_Donw) return;
Seg_Slow_Donw=1;
}
/* 其他显示函数 */
void Led_Proc()
{
}
void Timer0Init(void) //1毫秒@12.000MHz
{
AUXR |= 0x70; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
}
void Timer0Server() interrupt 1
{
if(++Key_Slow_Donw==10) Key_Slow_Donw=0;
if(++Seg_Slow_Donw==10) Seg_Slow_Donw=0;
if(++Seg_Pos==8) Seg_Pos=0;
Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]);
}
void main(void)
{
sys_init();
Timer0Init();
while(1)
{
Led_Proc();
Key_Proc();
Seg_Proc();
}
return ;
}
我应该如何修改