📄 at89c52.c
字号:
#include <rtx51tny.h> /* RTX-51 tiny functions & defines */
#include <stdio.h>
#include <reg52.h>
int counter0; /* counter for task 0 */
int counter1; /* counter for task 1 */
int counter2;
int counter3;
int counter4;
int counter5;
static unsigned long counter6 = 0;
//测试定时
extern serial_initial();
void System_Initial();
job0 () _task_ 0 {
serial_initial();
printf("Start!\n");
System_Initial();
os_create_task(1);
os_create_task(2);
while(1) {
counter0++;
if((counter0 & 0xFF)==0x09)
counter0=0;
//os_send_signal(1); //启动计数器1
P0=~P0;
}
}
job1 ( ) _task_ 1 {
while(1)
{
//os_wait(K_TMO,10,0); //等待信号
os_wait(K_IVL,100,0);
counter1++;
if ((counter1 & 0xFF)==0x09)
counter1=0;
os_send_signal(2); //启动计数器2
}
}
job2 ( ) _task_ 2{
while(1) {
os_wait(K_SIG,0,0); //等待信号
counter2++;
}
}
void timer1() interrupt 3 using 2 //定时中断1
{
counter3++;
}
void int0() interrupt 0 using 3 //外部中断0
{
counter4++;
}
void int1() interrupt 2 using 1 //外部中断1
{
counter5++;
}
void timer2() interrupt 5 //定时中断2
{
TF2=0; //清除溢出标志
counter6++; //调试
}
void System_Initial()
{
ET1=1; //允许定时器1中断
EX0=1; //外部中断0允许
EX1=1; //外部中断1允许
RCAP2L = (65536UL-1000UL);
RCAP2H = (65536UL-1000UL) >> 8;
TH2=RCAP2L; //定时初值
TL2=RCAP2H;
T2CON=0x80; //定时方式,16位计数,允许自动重载
ET2=1; //允许定时器2中断
TR2=1;
EA=1; //开放中断
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -