?? 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 + -