📄 appinit.c
字号:
#include "includes.h"
#include <timers.h>
#include <usart.h>
#include <i2c.h>
void HW_Bd_Init(void){
//system oscillator = 14.7456MHz
//Under 3V VCC, the operating frequency can only reach 16MHz
//Init the oscillator system
PSPCONbits.CMLK1 = 1;
PSPCONbits.CMLK0 = 1;
OSCCON = 0b00000000; //Disable the PLL, use primary oscillator input
//Init the external memory interface and chip select pins
PSPCONbits.CMLK1 = 1;
PSPCONbits.CMLK0 = 1;
MEMCON = 0b00110000;
//Init ports
//Init timers
IPR1bits.TMR1IP = 0; //set timer1 interrupt as low priority
WriteTimer1(0xffff-18432); //10ms at 14.7456MHz
OpenTimer1( TIMER_INT_ON &
T1_16BIT_RW &
T1_SOURCE_INT &
T1_PS_1_8 &
T1_OSC1EN_OFF &
T1_SYNC_EXT_OFF);
//Init the COM port
OpenUSART( USART_TX_INT_ON &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
7); //value is for 14.7456MHz
//I2C
OpenI2C(MASTER, SLEW_ON);
SSPADD = 9; // under 14.7456MHz, bit rate is about 368k
//Interrupt
RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -