config.c
来自「菜鸟,详细NRF24E1运用,程序,电路」· C语言 代码 · 共 201 行
C
201 行
#include "reg24le1.h"
#include "config.h"
#include "intrins.h"
#include "Sys.h"
volatile unsigned char Udata;
void system_init(void)
{
EA = 0;
// CLK
CLKCTRL = 0x28; // Clock sourced by XCOSC16M
CLKLFCTRL = 0x01; // RCOSC32K
Timer_Ms(50);
// RF
SPIRCON1 = 0x0B;
RFCKEN = 1; // enable L01 clock
RF = 0;
// INTERRUPT
WUIRQ = 0; // wakeup int enabled
P0DIR&=0X7F;
P07=0;
}
//---------------------------------------------------------------------------
void Uart_Init(void)
{
// UART
P0DIR &= 0xF7; // P03 (TxD) is output
P0DIR |= 0x10; // P04 (RxD) is input
S0CON = 0x50;
PCON |= 0x80; // SMOD = 1
WDCON |= 0x80; // Select internal baud rate generator
S0RELL = 0x30; // BAUD_38K4 //2400
S0RELH = 0x03;
//ES0 = 1; // Enable UART0 interrupt
}
//---------------------------------------------------------------------------
//
// 等待指定的微秒数
//
//---------------------------------------------------------------------------
void Timer_Us(void)
{
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
//---------------------------------------------------------------------------
void Timer_10Us(unsigned char nTime)
{
while((nTime--)!=0) Timer_Us();
}
//---------------------------------------------------------------------------
//
// 等待指定的毫秒数
//
//---------------------------------------------------------------------------
void Timer_Ms(int nTime)
{
int j;
while((nTime--)!=0)
for( j = 0; j < 350; j++);
}
void hal_wdog_init(unsigned int start_value)
{
WDSV = LSB(start_value); // Write the 8 LSB to the WD counter
WDSV = MSB(start_value); // Write the 8 MSB to the WD counter
}
//---------------------------------------------------------------------------
void hal_wdog_restart(void)
{
unsigned char wd_msb, wd_lsb;
wd_lsb = WDSV;
wd_msb = WDSV;
WDSV = wd_lsb; // Write the 8 LSB to the WD counter
WDSV = wd_msb; // Write the 8 MSB to the WD counter
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
static void ifp_interrupt(void) interrupt INTERRUPT_IFP { }
//---------------------------------------------------------------------------
static void tf0_interrupt(void) interrupt INTERRUPT_TF0
{
// 时钟中断函数(1ms发生一次)
TH0 = 0xFA;
TL0 = 0xCA;
}
//---------------------------------------------------------------------------
static void pofirq_interrupt(void) interrupt INTERRUPT_POFIRQ {}
//---------------------------------------------------------------------------
static void tf1_interrupt(void) interrupt INTERRUPT_TF1 {}
//---------------------------------------------------------------------------
static void tf2_interrupt(void) interrupt INTERRUPT_TF2 {}
//---------------------------------------------------------------------------
static void msdone_interrupt(void) interrupt INTERRUPT_MSDONE {}
//---------------------------------------------------------------------------
static void wuopirq_interrupt(void) interrupt INTERRUPT_WUOPIRQ { }
//---------------------------------------------------------------------------
static void miscirq_interrupt(void) interrupt INTERRUPT_MISCIRQ {}
//---------------------------------------------------------------------------
static void tick_interrupt(void) interrupt INTERRUPT_TICK{}
//---------------------------------------------------------------------------
static void ri0_interrupt(void) interrupt INTERRUPT_UART
{
if (RI0 == 1)
{
Udata = S0BUF;
S0BUF = Udata;
RI0 = 0;
}
else if(TI0 == 1)
{
TI0 = 0;
}
}
//---------------------------------------------------------------------------
//use this to do serial communiacation
void putchar( unsigned char dat)
{
S0BUF = dat;
while(!TI0);
TI0 = 0;
}
void puts( char * s)
{
while(*s!='\0')
{
putchar(*s);
s++;
}
}
char getch(void)
{
char rc;
if(RI0)
{
RI0=0;
rc=S0BUF;
}
return rc;
}
unsigned char keycheck(void)
{
P1CON=0XD0;//P10
if(!P10)
{
delay(5);
if(!P10)
{ while(!P10);
return TRUE; //如果按下就返回真
}
}
return FALSE; // 返回假
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?