📄 init_system.c
字号:
/************************************************************************
**Program Name: Init_System.c
** Copyright (c) 2001-2005 HUST EEIC CREATIVE NO.1 Workgroup
**Creator: Dasher Dan
**Date: 02-08-2005
**Description: This program is used to initialize SPCE061 system at the begining of each program
and also include some frequently used subfunctions
**Version Number: 1.0
************************************************************************/
#include "hardware.h"
#include "Init_System.h"
#include "led.h"
#include "Try1.h"
void Init_System()
{
__asm("INT OFF");
Init_IO( );
Init_Time();
Init_INT();
Init_ADC();
Init_DAC();
Init_SIO();
Init_UART();
Init_7219();
*P_INT_Ctrl=0x8000;
__asm("INT FIQ,IRQ");
}
/*************************************************************
**Function name: Init_IO() ;
**Input:
**0 0 0---带下拉电阻输入
**0 0 1---带上拉电阻输入
**0 1 0---悬浮输入
**0 1 1---悬浮输入
**1 0 0---反向输出高
**1 0 1---反向输出低
**1 1 0---缓存输出低
**1 1 1---缓存输出高
Output: none
**Description: this function is used to initialize SPCE061 IO port
//KEYBOARD 9IO---IOA0--IOA4 IN IOA5--IOA8 OUT
//DISPLAY MAX7219 3IO---CLK--IOB0 OUT,DIN--IOB1 OUT,LD--IOB2 OUT
//RECEIVE ULTRASONIC EXT2---IOB3 IN UP DRAG
//TRANSMIT ULTRASONIC IOB4---IOB4 OUT LOW DRAG
//ELECTRIC VALVE 2IO--- IOB5 OUT LOW DRAG, IOB6 OUT LOW DRAG
//UART 2IO---RX--IOB7 IN, TX--IOB10 OUT
**Return: none
**************************************************************/
void Init_IO()
{
*P_IOA_Dir = 0x01e0;
*P_IOA_Attrib = 0x01e0;
*P_IOB_Dir = 0x0477;
*P_IOB_Attrib = 0x0477;
*P_IOB_Data = 0x040f;
*P_FeedBack = 0x0000;
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_Time()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 System Clock, WatchDog,
LVD, TimerA, TimerB
Use TimerA to count, so as to calculate the distance
**Return: none
**************************************************************/
void Init_Time()
{
*P_SystemClock = (C_Fosc_Div_1|C_AutoMode|C_32K_Off|C_Fosc_40M);
*P_TimeBase_Setup = (C_TMB1_8Hz|C_TMB2_128Hz);
*P_TimeBase_Clear = C_TMBCLR;
*P_TimerA_Data = 0x0000;
*P_TimerA_Ctrl = (C_SourceA_Fosc2|C_SourceB_1|C_DutyOff); //ready to count, 20M Hz
*P_TimerB_Data = 0x0000;
*P_TimerB_Ctrl = (C_SourceC_0|C_DutyOff); //Close PWM
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_INT()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 interrupt system
**Return: none
**************************************************************/
void Init_INT()
{
*P_INT_Ctrl=(C_IRQ5_4Hz);
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_ADC()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 ADC
**Return: none
**************************************************************/
void Init_ADC()
{
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_DAC()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 DAC
**Return: none
**************************************************************/
void Init_DAC()
{
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_UART()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 UART
**Return: none
**************************************************************/
void Init_UART()
{
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Init_SIO()
**Input: none
**Output: none
**Description: this function is used to initialize SPCE061 SIO Clock
**Return: none
**************************************************************/
void Init_SIO()
{
*SIO_Ctrl = 0xc9;
CLEAR_WATCHDOG;
}
/*************************************************************
**Function name: Delay()
**Input: unsigned int Delay_Time
**Output: none
**Description: Each Delay_Time Delay 1 circle
**Return: none
**************************************************************/
void Delay(unsigned int Delay_Time)
{
unsigned int i;
for(i=0;i<Delay_Time;i++)
{
CLEAR_WATCHDOG;
}
}
/*************************************************************
**Function name: Delay1()
**Input: unsigned int Delay_Time
**Output: none
**Description: Each Delay_Time Delay 65535 circles
**Return: none
**************************************************************/
void Delay1(unsigned int Delay_Time)
{
unsigned int ii,i;
for(ii=Delay_Time;ii>0;ii--)
{
for(i = 65535; i>0; i--)
CLEAR_WATCHDOG;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -