📄 init.c
字号:
#include <htc.h>/*** Device configuration registers ***//* * Osc. system clock switching = Enabled * Oscillator type = RC-OSC2 as RA6 */__CONFIG(1, OSCSEN & RCRA6);/* * Brown-out reset = Enabled * Brown-out detect voltage = 4.5V * Power-up timer = Enabled * Watchdog postscaler = 1:128 * Watchdog timer = Disabled-Controlled by SWDTEN bit */__CONFIG(2, BOREN & BORV45 & PWRTEN & WDTPS128 & WDTDIS);/* * CCP Multiplexed = RC1 */__CONFIG(3, CCP2RC1);/* * Background debugger = Disabled * Low-voltage programming = Disabled * Stack error reset = Disabled */__CONFIG(4, DEBUGDIS & LVPDIS & STVRDIS);/* * Code protect sector 3 = Disabled * Code protect sector 2 = Disabled * Code protect sector 1 = Disabled * Code protect sector 0 = Disabled * Protect EEPROM = Disabled * Code protect boot block = Disabled */__CONFIG(5, 0xFFFF);/* * Write protect sector 3 = Disabled * Write protect sector 2 = Disabled * Write protect sector 1 = Disabled * Write protect sector 0 = Disabled * Write protect EEPROM = Disabled * Write protect boot block = Disabled * Write protect config. = Disabled */__CONFIG(6, 0xFFFF);/* * Read protect sector 3 = Disabled * Read protect sector 2 = Disabled * Read protect sector 1 = Disabled * Read protect sector 0 = Disabled * Read protect boot block = Disabled */__CONFIG(7, 0xFFFF);// Peripheral initialization functionvoid init(void){ /***** Common Code **** * Timer 0 interrupt is enabled * Peripheral interrupts will be enabled * All interrupts temporarily disabled during init */ INTCON = 0b01100000; /* * Timer 0 interrupt priority is high */ INTCON2 = 0b00000100; /***** 18F452 Code **** * Interrupt priority system enabled */ RCON = 0b10000000; /***** Timer 0 Code **** * Timer prescale ratio = 1:16 * Timer 0 is clocked internally. * 16-Bit operation * Timer 0 is active */ T0CON = 0b10000011; /***** Timer 1 Code **** * Timer 1 is active * Timer 1 derived from system clock * Not synchronised with external input * Oscillator turned off to save power * Timer prescale ratio = 1:8 * Timer 1 is read in one 16-bit operation */ T1CON = 0b10110101; /* * Timer 1 interrupt is enabled */ PIE1 = 0b00000001; /* * Timer 1 interrupt priority is high */ IPR1 = 0b00000001; ei(); // Global interrupts enabled }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -