📄 pulse.c
字号:
/*
*********************************************************************************************************
* Pulse Generator control Module
*
* (c) Copyright 2006-08-01, XXXXXXXXXXXXXXXXX Corp., ltd,
* All Rights Reserved
*
* V1.00
*
* File : pulse.c
* By : z.x.s
*********************************************************************************************************
*/
#define PUSLE_GLOBALS
#include "includes.h"
sbit RUNFLG = P1^7;
/*
*********************************************************************************************************
* hardware abstract layer functions
*********************************************************************************************************
*/
//串口寄存器初始化
void InitUart()
{
RCAP2H=BAUDH;
RCAP2L=BAUDL;
T2CON=0x34; /*启动T2,选择T2作波特率发生器*/
T2MOD=0;
SCON=0x50;//0x52
PCON=0x00;
PS = 1;
TI = 1;
ES = 0; /*the interrupt disable*/
}
//定时器0寄存器初始化
void InitTimer0()
{
TMOD |= 0x01; /*set timer 1ms when cpu at 11.0592MHz*/
TH0 = Timer0H;
TL0 = Timer0L;
TR0 = 1; /*TR0 is set*/
ET0 = 1; /*the interrupt enable*/
}
//串口中断服务函数
ComIntISR() interrupt 4 using 1
{
EA = 0;
EA = 1;
}
//定时器0中断服务函数
Timer0IntISR() interrupt 1 using 2
{
TH0=Timer0H;
TL0=Timer0L; /*重置定时器*/
RUNFLG = ~RUNFLG;
DIOTaskDlyFlg = TRUE;
}
/*
*********************************************************************************************************
* Application layer functions
*********************************************************************************************************
*/
//系统硬件资源初始化
void InitHardWare(void)
{
EA = 0;
InitUart(); /*串口初始化*/
InitTimer0(); /*定时器0初始化*/
EA = 1; /*开中断*/
}
void InitUserVar(void)
{
DIOTaskDlyCnt = DIO_TASK_DLY_TICKS;
DIOTaskDlyFlg = 0;
}
/*
*********************************************************************************************************
* Main Entry
*********************************************************************************************************
*/
void main(void)
{
InitHardWare();
InitUserVar();
DIOInit();
DOSetSyncCtrMax(100);
DOCfgMode(0, /*
* the discrete output channel(0..DIO_MAX_DO-1)
*/
DO_MODE_BLINK_ASYNC, /*
* DO_MODE_LOW output is forced LOW
* DO_MODE_HIGH output is forced HIGH
* DO_MODE_DIRECT output is based on state of DOBypass
* DO_MODE_BLINK_SYNC output will be blinking synchronously with DOSyncCtr
* DO_MODE_BLINK_ASYNC output will be blinking based on DOA and DOB
*/
FALSE); /*
* indicates whether the output will be inverted.TRUE:yes FALSE:no
*/
DOCfgMode(1,DO_MODE_BLINK_ASYNC,0);
DOCfgMode(2,DO_MODE_BLINK_ASYNC,0);
DOCfgMode(3,DO_MODE_BLINK_ASYNC,0);
DOCfgMode(4,DO_MODE_BLINK_ASYNC,0);
DOCfgMode(5,DO_MODE_BLINK_ASYNC,0);
DOCfgMode(6,DO_MODE_BLINK_ASYNC,0);
DOCfgBlink(0, /*
* is the discrete output channel (0..DIO_MAX_DO-1).
*/
DO_BLINK_EN, /*
* DO_BLINK_EN Blink is always enabled
* DO_BLINK_EN_NORMAL Blink depends on user request's state
* DO_BLINK_EN_INV Blink depends on the complemented user request's state
*/
1, /*
* is the ON time relative to how often the DIO task executes (1..250)
* 1 * 500us(task excute time)
*/
2); /*
* is the ON time relative to how often the DIO task executes (1..250)
* 2 * 500us
*/
DOCfgBlink(1,DO_BLINK_EN,2,3);
DOCfgBlink(2,DO_BLINK_EN,2,4);
DOCfgBlink(3,DO_BLINK_EN,2,5);
DOCfgBlink(4,DO_BLINK_EN,2,6);
DOCfgBlink(5,DO_BLINK_EN,2,7);
DOCfgBlink(6,DO_BLINK_EN,2,8);
for(;;)DIOTask();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -