📄 main.c
字号:
/******************************************************************************
*
* WinARM RTC application
*
* - UART0 send in Interrupt-Mode
* - Sends message every seccond.
* - RTC interupt every second
******************************************************************************/
#include "types.h"
#include "LPC214x.h"
#include "config.h"
#include "armVIC.h"
#include "uart.h"
uint32_t time_toggle=0;
/******************************************************************************
*
* Function Name: lowInit()
*
* Description:
* This function starts up the PLL then sets up the GPIO pins before
* waiting for the PLL to lock. It finally engages the PLL and
* returns
*
* Calling Sequence:
* void
*
* Returns:
* void
*
*****************************************************************************/
static void rtc0(void) __attribute__ ((interrupt ("IRQ")));
static void lowInit(void)
{
// set PLL multiplier & divisor.
// values computed from config.h
PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
// enable PLL
PLLCON = PLLCON_PLLE;
PLLFEED = 0xAA; // Make it happen. These two updates
PLLFEED = 0x55; // MUST occur in sequence.
// setup the parallel port pin
IO0CLR = PIO0_ZERO_BITS; // clear the ZEROs output
IO0SET = PIO0_ONE_BITS; // set the ONEs output
IO0DIR = PIO0_OUTPUT_BITS; // set the output bit direction
IO1CLR = PIO1_ZERO_BITS; // clear the ZEROs output
IO1SET = PIO1_ONE_BITS; // set the ONEs output
IO1DIR = PIO1_OUTPUT_BITS; // set the output bit direction
// wait for PLL lock
while (!(PLLSTAT & PLLSTAT_LOCK))
continue;
// enable & connect PLL
PLLCON = PLLCON_PLLE | PLLCON_PLLC;
PLLFEED = 0xAA; // Make it happen. These two updates
PLLFEED = 0x55; // MUST occur in sequence.
// setup & enable the MAM
MAMTIM = MAMTIM_CYCLES;
MAMCR = MAMCR_FULL;
// set the peripheral bus speed
// value computed from config.h
VPBDIV = VPBDIV_VALUE; // set the peripheral bus clock speed
}
/******************************************************************************
*
* Function Name: sysInit()
*
* Description:
* This function is responsible for initializing the program
* specific hardware
*
* Calling Sequence:
* void
*
* Returns:
* void
*
*****************************************************************************/
static void sysInit(void)
{
lowInit(); // setup clocks and processor port pins
// set the interrupt controller defaults
#if defined(RAM_RUN)
MEMMAP = MEMMAP_SRAM; // map interrupt vectors space into SRAM
#elif defined(ROM_RUN)
MEMMAP = MEMMAP_FLASH; // map interrupt vectors space into FLASH
#else
#error RUN_MODE not defined!
#endif
VICIntEnClear = 0xFFFFFFFF; // clear all interrupts
VICIntSelect = 0x00000000; // clear all FIQ selections
VICDefVectAddr = (uint32_t)reset; // point unvectored IRQs to reset()
// wdtInit(); // initialize the watchdog timer
initSysTime(); // initialize the system timer
uart0Init(UART_BAUD(HOST_BAUD), UART_8N1, UART_FIFO_8); // setup the UART
}
/*************************************************************/
void rtc0(void)
{
if (time_toggle==0)
{
uart0Puts("\n\rTic\r\n");//Tic Tac output to UART0
time_toggle=1;
}
else
{
uart0Puts("\n\rTac\r\n");
time_toggle=0;
}
ILR |= 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
PCON = 1; // IDLE mode
}
void init_rtc(void)
{
ILR = 3; // Disable 32'768 interrupt
CCR = 0x11; // Clock enable + 32'767Hz quartz enable
CIIR = 0x01; // Interupt every second
VICVectAddr1 = (unsigned long)rtc0; // set interrupt vector in 1
VICVectCntl1 = 0x0000002D; // use it for RTC Interrupt
VICIntEnable = 0x00002000; // Enable RTC Interrupt
}
void set_time(void)
{
YEAR = 2006; // Year
MONTH = 5; // Month
DOM = 23; // Day of month
DOY = 38; // Day of year
DOW = 143; // Day of week
HOUR = 23; // Hours
MIN = 14; // Minutes
SEC = 30; // Seconds
}
/******************************************************************************
*
* Function Name: main()
*
* Description:
* This function is the program entry point. After initializing the
* system, it sends a greeting out UART0 then enters an endless loop
* echoing chracters on the UART and blinking an LED every half
* second.
*
* Calling Sequence:
* void
*
* Returns:
* void
*
*****************************************************************************/
int main(void)
{
uint32_t startTime;
sysInit();
#if defined(UART0_TX_INT_MODE) || defined(UART0_RX_INT_MODE)
enableIRQ();
#endif
uart0Puts("\n\rRTC interupts every second\r\n");
startTime = getSysTICs();
init_rtc();
set_time();
for (;;) {
} // for
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -