📄 initmcu.c
字号:
//------------------------------------------------------------------------------
//
// filename : initmcu.c
// funcation : initialize the resoucre of hardware
// designer : lrx
// time : 2005-5-11 10:35
// All right are reserved
//
//------------------------------------------------------------------------------
#define INITMCU_GLOBAL 1
#include "includes.h"
//------------------------------------------------------------------------------
// intialize input and output
//------------------------------------------------------------------------------
uchar uart1count=0;
uint uart2count=0;
uint timecount =0;
static uchar watchdog_count=0;
void InitIO(void)
{
pu02 = 1; //P1_0 --- P1_3 pullup
pu03 = 1; //P1_4 --- P1_7 pullup
pu10 = 1; //P4_0 --- P4_3 pullup
pu11 = 1; //P4_4 --- P4_7 pullup
pu14 = 1; //P6_0 --- P6_3 pullup
pu15 = 1; //P6_4 --- P6_7 pullup
//pu16 = 1;
pu17 = 1; //P7_4 --- P7_7 pullup
pu20 = 1; //P8_0 --- P8_3 pullup
pu21 = 1; //P8_4 --- P8_7 pullup
pu22 = 1; //P9_0 --- P9_3 pullup
pu23 = 1; //P9_4 --- P9_7 pullup
//pu24 = 1; //P10_0 --- P10_3 pullup
pu25 = 1; //p10_4 --- p10_7 pullup
//-----------------port direction-------
pd1_0 = PORT_OUT;
pd1_1 = PORT_OUT;
pd1_2 = PORT_OUT;
pd1_3 = PORT_OUT;
pd1_4 = PORT_IN;
pd1_5 = PORT_IN;
pd1_6 = PORT_IN;
pd1_7 = PORT_IN;
pd6_0 = PORT_OUT;
pd6_1 = PORT_IN;
pd6_2 = PORT_IN;
pd6_3 = PORT_IN; //PORT_OUT;
pd6_4 = PORT_OUT;
pd6_5 = PORT_IN;
pd6_6 = PORT_IN;
pd6_7 = PORT_OUT;
pd7_0 = PORT_OUT;
pd7_1 = PORT_IN;
pd7_2 = PORT_IN;
pd7_3 = PORT_OUT;
pd7_4 = PORT_OUT;
pd7_5 = PORT_OUT;
pd7_6 = PORT_OUT;
pd7_7 = PORT_IN;
pd8_0 = PORT_OUT;
pd8_1 = PORT_OUT;
pd8_2 = PORT_IN;
pd8_3 = PORT_IN;
pd8_4 = PORT_IN;
pd8_6 = PORT_OUT;
pd8_7 = PORT_OUT;
prc2 = 1;
pd9 = 0xfd;
// pd9_0 = PORT_OUT;
// pd9_1 = PORT_IN;
// pd9_2 = PORT_OUT;
// pd9_3 = PORT_OUT;
// pd9_4 = PORT_OUT;
// pd9_5 = PORT_OUT;
// pd9_6 = PORT_OUT;
// pd9_7 = PORT_OUT;
prc2 = 0;
pd10 = 0xff;
p10 = 0xff;
asm("NOP");
pd10_0 = PORT_IN;
pd10_1 = PORT_IN;
pd10_2 = PORT_IN;
pd10_3 = PORT_IN;
pd10_4 = PORT_IN;
pd10_5 = PORT_IN;
pd10_6 = PORT_IN;
pd10_7 = PORT_IN;
//-------------INITIALIZE PORT---------//
SHUTDOWN_CON = VOL_LOW; //断油断电//
BAT_CON = VOL_LOW; //电池充电//
GPS_ON = VOL_LOW; //gps电源//
BELL_OUT = VOL_LOW; //汽车喇叭输出//
ALARM_POWER = VOL_HIGH; //遥控器电源//
ALARM_TXD = VOL_HIGH;//
SHUTDOWN_CON = VOL_LOW; //断油断电//
GPS_BAT_CON =VOL_LOW;//diable gps bat// add by lxo;lable 122601
}
//------------------------------------------------------------------------------
// intialize timer a0
//------------------------------------------------------------------------------
void InitTa0(void)
{
ta0s = 0; //stop timer a0
ta0ic = 0x0;
ta0mr = 0x80; //select mode 0 for timer;source f32
ta0 = (INT16U)((INT32U)(OSC*10*1000)/32-1); //(f*time)/devide-1=n
ta0ud = 0; //up/down flag 0
}
//------------------------------------------------------------------------------
// start timer a0
//------------------------------------------------------------------------------
void StartTa0(void)
{
ta0ic = 0x02; //select interupt level 2
ta0s = 1; //start timer
}
//------------------------------------------------------------------------------
// stop timer a0
//------------------------------------------------------------------------------
void StopTa0(void)
{
ta0ic = 0x0; //select interupt level 2
ta0s = 0; //start timer
}
//------------------------------------------------------------------------------
// timer a0 interrupt
//------------------------------------------------------------------------------
void TimerA0Int(void)
{
// OS_EXIT_CRITICAL();
Timer_Reduce();
}
//------------------------------------------------------------------------------
// intialize timer a1
//------------------------------------------------------------------------------
void InitTa1(void)
{
ta1ic = 0x0;
ta1s = 0; //stop timer a1
ta1mr = 0x80; //select mode 0 for timer;source f32
ta1 = (INT16U)((INT32U)(OSC*10*1000)/32-1); //(f*time)/devide-1=n
ta1ud = 0; //up/down flag 0
}
//------------------------------------------------------------------------------
// start timer a0
//------------------------------------------------------------------------------
void StartTa1(void)
{
ta1ic = 0x02; //select interupt level 2
ta1s = 1; //start timer
}
//------------------------------------------------------------------------------
// stop timer a0
//------------------------------------------------------------------------------
void StopTa1(void)
{
ta1ic = 0x0;
ta1s = 0; //start timer
}
//------------------------------------------------------------------------------
// delay ms
//------------------------------------------------------------------------------
void Delay10ms(uint timeout)
{
OS_ENTER_CRITICAL();
TenMsecCount=0;
OS_EXIT_CRITICAL();
while(TenMsecCount<timeout)
{
//clr_watchdog();
}
}
//------------------------------------------------------------------------------
void TimerA1Int(void)
{
static uint minute=0;
//static uchar ringsign=0;
if(TenMsecCount!=0xffff)TenMsecCount++;
if(minute>6000)
{
minute = 0;
if(gpspostime!=0xffff)gpspostime++;
}
else minute++;
if(ring.time!=0xffff)ring.time++;
if(ring.time==600)
{
Send_Taskmsg(GprsTaskid,SEND_NO_CLIP,NULL);
}
if(timecount>=99)
{
Second1Flag =1;
timecount =0;
}
else timecount++;
}
//------------------------------------------------------------------------------
// intialize timer a2
//------------------------------------------------------------------------------
void InitTa2(INT16U bps)
{
ta2s = 0;
ta2ic = 0;
ta2mr = 0x40; //select mode 0 for timer;source f8
ta2 = (INT16U)((INT32U)(OSC*10000)/(8*bps)-1); //(f*time)/devide-1=n
ta2ud = 0; //up/down flag 0
}
//------------------------------------------------------------------------------
// enable timer a2
//------------------------------------------------------------------------------
void StartTa2(void) // 12 for bps 1200bps;24 for 24000bps//
{
ta2ic = 0x02; //select interupt level 2//
ta2s = 1; //start timer a2;//
}
//------------------------------------------------------------------------------
// disable time a2
//------------------------------------------------------------------------------
void StopTa2(void)
{
ta2ic = 0x0;
ta2s = 0;
}
//------------------------------------------------------------------------------
// TIMER A2 INTERRUPT
//------------------------------------------------------------------------------
void TimerA2Int(void)
{
// OS_EXIT_CRITICAL();
if(semiuart.sendstatus==_BUSY&&semiuart.sendlen!=0)
{
if(Step_Send==0) //起始位//
{
ALARM_TXD = VOL_LOW;
semi_senddata = semiuart.sendbuf[semiuart.sendlen-1];
}
else if (Step_Send>0&&Step_Send<9) //数据位//
{
ALARM_TXD = semi_senddata&0x01;
semi_senddata = semi_senddata>>1;
}
else if(Step_Send==9) //停止位//
{
ALARM_TXD = VOL_HIGH;
}
else if(Step_Send==10)
{
ALARM_TXD = VOL_HIGH;
semiuart.sendlen--;
if(semiuart.sendlen==0)
{
semiuart.sendstatus = _IDLE;
}
}
Step_Send ++;
if(Step_Send>=11) Step_Send = 0;
}
}
//------------------------------------------------------------------------------
// intialize timer a3
//------------------------------------------------------------------------------
void InitTa3(INT16U bps)
{
ta3s = 0;
ta3ic = 0;
ta3mr = 0x40; //select mode 0 for timer;source f8
ta3 = (INT16U)((INT32U)(OSC*10000)/(8*bps)-1); //(f*time)/devide-1=n
ta3ud = 0; //up/down flag 0
}
//------------------------------------------------------------------------------
// enable timer a3
//------------------------------------------------------------------------------
void StartTa3(void) // 12 for bps 1200bps;24 for 24000bps
{
ta3ic = 0x02; //select interupt level 2
ta3s = 1; //start timer a2;
}
//------------------------------------------------------------------------------
// disable time a3
//------------------------------------------------------------------------------
void StopTa3(void)
{
ta3ic = 0x0;
ta3s = 0;
}
//------------------------------------------------------------------------------
// TIMER A3 INTERRUPT
//------------------------------------------------------------------------------
void TimerA3Int(void)
{
// OS_EXIT_CRITICAL();
if(Step_Recv==0)
{
if(ALARM_RXD==VOL_LOW) //起始位//
{
InitTa3(12); //波特率1200bps//
StartTa3();
semi_recvdata = 0;
}
else
{
StopTa3(); //错误返回模拟串口的接收//
Enable_Int1();
}
}
else if(Step_Recv>0&&Step_Recv<9) //接受数据位//
{
if(ALARM_RXD==VOL_HIGH)
{
semi_recvdata |=0x01<<(Step_Recv-1);
}
}
else if(Step_Recv==9) //接收停止位//
{
StopTa3();
Enable_Int1();
if(ALARM_RXD==VOL_HIGH) //保存有效数据//
{
semiuart.recvbuf[semiuart.recvlen] = semi_recvdata;
semiuart.recvlen++;
Send_Taskmsg(AlarmTaskid,SEMIUARTRECV,NULL);
}
}
Step_Recv++;
}
//------------------------------------------------------------------------------
// init int1
//------------------------------------------------------------------------------
void InitInt1(void)
{
ifsr1 = 0; //select one edge
int1ic = 0x0; //select interupt level 3,down edge
}
//------------------------------------------------------------------------------
// enable int1int
//------------------------------------------------------------------------------
void Enable_Int1(void)
{
ifsr1 = 0; //select one edge
int1ic = 0x03; //select interupt level 3,down edge
}
//------------------------------------------------------------------------------
// disable intiint
//------------------------------------------------------------------------------
void Disable_Int1(void)
{
int1ic = 0x0; //disable the int1 interupt
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -