Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

RTC example on ARM7 LPC2148 using WinARM

Finally got my LPC2148 RTC working on my development board. arm7 base development board for lpc2148

I am quite new to ARM microcontrollers, so I managed to make a few tests using them by driving some peripherals and writing some test routines. The first code I tried was a simple LED blink program first lpc2148 arm7 microcontroller test led blink

This one is running microcontrollers’ real-time clock (RTC) and generating interrupts every second. When Interrupt occurs, the microcontroller sends a particular message to UART that I could see via the Terminal program.

The main program:

/******************************************************************
* 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;
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
}
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
}
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;
}

And zipped project files:RTC clock example on ERM7 LPC2148 using WinARM

3 Comments:

  1. Sumit Bhatnagar

    My objective is to use the Olimex LPC2148 Header board shown here:
    http://www.sparkfun.com/commerce/product_info.php?products_id=676

    Issue is how to use the UART. I have currently written a led blinking program for this board. How can I test out the UART on this board/use hyperterm

  2. hi,
    I want to decode the TV remote signals using LPC2148 to cotrol devices using remote.I’m using 12Mhz crystal.plz any one can help

    thanks & regards,
    suresh

  3. sir ,please send the keilc program for receiving serial data from sonic sensor

Leave a Reply