关于SMALL RTOS51 加多一个按键 程序就不正常了【恢复】
#include "config.h"uint8 code led_7={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uint8 code position={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uint8 time={45,58,23}; // 时、分、秒计数
uint8 dis_buff; // 显示缓冲区,存放要显示的6个字符的段码值
uint8 point_on; //秒闪烁标志位
sbit Key_Input = P2^7;
void Show(void);
void Time_Sum(void);
void Key_Do(void);
void init(void) //单片机初始化
{
P1=P3=0xff;
P2=0xff;
TCON=0;
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
ET0=1;
TR0=1;
}
void time_to_disbuffer(void) // 时间值送显示缓冲区函数
{
uint8 i,j=0;
for (i=0;i<=2;i++)
{
dis_buff = time % 10;
dis_buff = time / 10;
}
}
void display(void) // 扫描显示函数,执行时间24ms
{
uint8 i;
for(i=0;i<=5;i++)
{
P3 = led_7];
if (point_on && ( i==2 || i==4 ))P3|= 0x80;
P1 = position;
OSWait(K_TMO,1);
P1 = 0xff;
OSTimeTick();
}
}
void Show(void)
{
time_to_disbuffer();
while(1)
{
display(); //用于了24ms
}
}
void Time_Sum(void)
{
while(1)
{
/*if(Key_Input==0)time+=10;
if(time>59)time=0;*/
OSWait(K_TMO,250);//250*8ms=2s 有点不明白 却显示数码管为正常的1s
point_on=~point_on;
time++;
if(time>=60)
{
time=0;
time++;
if(time>=60)
{
time=0;
time++;
if(time>=24)
time=0;
}
}
time_to_disbuffer();
}
}
//处理按键要做的任务--------就加了这个Key_Do函数就不正常啦
void Key_Do(void)
{
if(Key_Input==0)time++;
}
void main(void)
{
OSInit();
init();
OSTaskCreate(Show, NULL, 0); //显示的优先级最高
OSTaskCreate(Time_Sum,NULL, 1);
OSTaskCreate(Key_Do,NULL, 2);
while(1)
{
PCON = PCON | 0x01; /* CPU进入休眠状态 */
}
}
---------------------该注意的地方1:-----------------------
OSTaskCreate(Show, NULL, 0); //显示的优先级最高
OSTaskCreate(Time_Sum,NULL, 1);
OSTaskCreate(Key_Do,NULL, 2);
-------------------该注意的地方2: -------------------
//任务定义
#ifdef IN_OS_CPU_C
extern void Show(void);
extern void Time_Sum(void);
extern void Key_Do(void);
void (* const TaskFuction)(void)={Show,Time_Sum,Key_Do};
//函数数组TaskFuction[]保存了各个任务初始PC指针,其按任务ID(既优先级次序)顺序保存
-------------------该注意的地方3: -------------------
#define OS_MAX_TASKS 3 /* 最大任务数1~16 */
#define OS_TICKS_PER_SEC 100 /* 声明1秒系统系统节拍数 */
#define EN_USER_TICK_TIMER 1 /* 禁止(0)或允许(1)系统定时中断调用用户函数UserTickTimer() */
#define EN_TIMER_SHARING 1 /* 禁止(0)或允许(1)定时器中断调用OSTimeTick() */
#define TICK_TIMER_SHARING 2 /* 定义进入多少次硬件中断为一次系统定时器软中断 */
#define OSWait_EN 1 /* 禁止(0)或允许(1)调用兼容函数OSWait */
-------------------该注意的地方4: -------------------
#define UserTickTimer() TF0=0; /* 系统定时中断中调用的用户函数 */
--------------------------------------该注意的地方5:-----------------------------------
#define OS_TIME_ISR 1 /* 系统定时器使用的中断 */ 呵呵,我顶下下,希望大虾能看见 任务必须是死循环
页:
[1]