📄 init_roution.c
字号:
#include "c8051F330.h"
#include "define.h"
#include <intrins.h>
//#include "define_GLobal.h"
#ifndef Init_C
#define Init_C
#endif
//U8 xdata Test_Data[6];
//-----------------------------------------------------------------------------
// UNIONs, STRUCTUREs, and ENUMs
//-----------------------------------------------------------------------------
/*typedef union LONG
{ // byte-addressable LONG
long l;
unsigned char b[4];
} LONG;
LONG command_LONG;
typedef union INT
{ // byte-addressable INT
int i;
unsigned char b[2];
} INT;
INT temp_INT;
/*==================================================
Name : INT0_Init()
Function :
====================================================*/
void INT0_Init (void)
{
}
/*==================================================
Name : INT1_Init()
Function :
====================================================*/
void INT1_Init (void)
{
}
/*==================================================
Name : OSCILLATOR_EXTCLK_Init()
Function : This routine initializes the system clock to use the external Capacitor Oscillator
as its clock source and disables the internal oscillator.
====================================================*/
void OSCILLATOR_EXTCLK_init(void)
{
int i = 0;
//Rosc_Input = 0;
//Rosc_Output = 0;
P0MDIN &= 0x0f3;
// OSCICN = 0x00; //switch off internal oscillator
EA=0;
OSCXCN = 0x61; // Enalbe etxOscillator 110 crystal 32.768khz
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0); // XTLVD
CLKSEL = 0x01; //switch to external oscillator
EA=1;
}
/*==================================================
Name : OSCILLATOR_High_Speed_Init()
Function : This function initializes the system clock to high speed
====================================================*/
void OSCILLATOR_High_Speed_Init (void)
{
int i = 0;
//CLKSEL = 0x00; //switch to internal High oscillator
OSCICN =0x83;// 0x87; // Configure internal oscillator for 24.5M
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCICN & 0x40) == 0);
}
/*==================================================
Name : OSCILLATOR_Low_Speed_Init()
Function :
====================================================*/
void OSCILLATOR_Low_Speed_Init (void)
{
int i = 0;
// OSCLCN=0x83; // 1x000011 hi L_F
OSCLCN=0xb7; // 1x110111 low L_F 80k
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCLCN & 0x40) == 0);
}
/*==================================================
Name : Timer2_Init_High_Speed()
Function :
====================================================*/
void Timer2_Init_High_Speed (void)
{
; // Start Timer2
}
/*==================================================
Name : Timer2_Init_Low_Speed()
Function :
====================================================*/
void Timer2_Init_Low_Speed (void)
{
// Start Timer2
}
/*==================================================
Name : Change_to_High_Speed_Mode()
Function :
====================================================*/
void Change_to_High_Speed_Mode(void)
{
EA=0;
OSCILLATOR_High_Speed_Init();
CLKSEL=0x00;
Timer2_Init_High_Speed();
EA=1;
}
/*==================================================
Name : Change_to_High_Speed_Mode()
Function :
====================================================*/
void Change_to_Low_Speed_Mode(void)
{
EA=0;
// OSCILLATOR_Low_Speed_Init();
CLKSEL=0x02;
Timer2_Init_Low_Speed();
EA=1;
}
/*==================================================
Name : PORT_Init()
Function : This function configures the crossbar and GPIO ports.
====================================================*/
void PORT_Init (void)
{
P0MDIN = 0xf2; //11110010B,内部VREF输出,0是配置成模拟输入//P0MDIN = 0x38;P0.1,P0.2 and P0.6 are configured as ADC0 input ports.p0.0被用作REF 00111000B,
P1MDIN = 0x0ff;
P0MDOUT= 0xcd; //11001101B,0是漏极开路输出,1是推挽 //P0MDOUT= 0xff;Force P0.1,P0.2 to be push-pull 10000110B
// P1MDOUT= 0xad; //all input ports 10101101
P1MDOUT= 0xfb; //p1.2漏极开路输出// 11111011
P0SKIP = 0xff;//00001101B,0是不被跳过,1要跳过//P0SKIP = 0xcf;(01100111B) Should be skipped by the Digital Crossbar. p0.0被用作REF
P1SKIP = 0xff; //P1.1-P1.7 are configured as ADC0 input ports. (11111111B)Should be skipped by the Digital Crossbar.
XBR0 = 0x00;//XBR0 = 0x01; enable UART,SPI,内部VREF
XBR1 = 0x40; // Enable crossbar, enable weak pull-ups,
}
/*==================================================
Name : Timer1_Init()
Function :
====================================================*/
void Timer1_Init()
{
// TCON = 0x40;
TMOD = 0x10; // TMOD: timer 1, mode 1 16-bit
CKCON |= 0x01; // Timer0/Timer1 clocked based on SYSCLK/4;
//TH1 = 161;
//TH1=0xE8;
//TL1=0x12;
TH1=0xFF;
TL1=0xF0;
STOP_TIMER1; // start Timer1
//START_TIMER1;
ET1 = 1; // enable Timer 1 as interrupt source
}
/*==================================================
Name : init_adc()
Function :
====================================================*/
void init_adc(void)
{
;
}
/*=================================================
Name : Variable_Init()
Function :
==================================================*/
void Variable_Init()
{
Temp=0;
Press=0;
Altitude=0;
C1=0;
C2=0;
C3=0;
C4=0;
C5=0;
C6=0;
C7=0;
AA=0;
BB=0;
CC=0;
DD=0;
D1=0;
D2=0;
DUT=0;
OFF=0;
SENS=0;
X=0;
}
/*==================================================
Name : UART0_Init()
Function : Configure the UART0 using Timer1, for <baudrate> and 8-N-1.
====================================================*/
void UART0_Init (void)
{
;
}
/*=================================================
Name : Get_Data_FromFlashMemory()
Function : Get 1.ID_CODE
2.CalPoint1KWH
3.CalPoint1AD
4.CalPoint2KWH
5.CalPoint2AD
==================================================*/
void Get_Data_FromFlashMemory(void)
{
;
}
/*=================================================
Name : System_Init()
Function :
==================================================*/
void System_Init(void)
{
// Temp_Reset=RSTSRC;
PCA0MD &= ~0x40; //WDT定时器禁止
PCON=0x00;
Variable_Init();
// OSCILLATOR_EXTCLK_init();
Change_to_High_Speed_Mode();
//OSCILLATOR_Low_Speed_Init();
INT0_Init();
INT1_Init ();
PORT_Init (); // Initialize ports for normal operation
init_adc(); // Initialize ADC0
Timer1_Init();
UART0_Init ();
// Select_Plug(Plug_2);
Get_Data_FromFlashMemory();
// Calculate_Unit();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -