为基于 ARM 架构的微控制器编写实时时钟

发布于 2024-08-10 00:00:58 字数 1000 浏览 4 评论 0 原文

我需要编写一个程序来实现ARM架构的实时时钟。示例:LPC213x

它应该显示小时、分钟和秒。我对 ARM 不了解,所以入门时遇到困难。

我的下面的代码不起作用

// ...

int main (void) {
    int hour=0;
    int min=0;
    int sec;
    init_serial(); /* Init UART */
    Initialize();
    CCR=0x11;
    PCONP=0x1815BE; 
    ILR=0x1;         //  Clearing Interrupt

    //printf("\nTime is %02d:%02x:%02d",hour,min,sec);

    while (1) { /* Loop forever */
    }
}

void Initialize()
{
VPBDIV=0x0;
//CCR=0x2; 
//ILR=0x3; 
HOUR=0x0;
SEC=0x0;
MIN=0x0;


ILR = 0x03; 
CCR = (1<<4) | (1<<0); 

VICVectAddr13 = (unsigned)read_rtc; 
VICVectCntl13 |= 0x20 | VIC_RTC; 
VICIntEnable |= (1 << VIC_RTC);

}
/* Interrupt Service Routine*/
__irq void read_rtc() 
{
int hour=0;
int min=0;
int sec;
ILR=0x1;         //  Clearing Interrupt
hour=(CTIME0 & MASKHR)>>16;
min= (CTIME0 & MASKMIN)>>8;
sec=CTIME0 & MASKSEC;

printf("\nTime is %02d:%02x:%02d",hour,min,sec);

//VICVectAddr=0xff;
VICVectAddr = 0;
}

I need to write a program to implement real time clock for ARM architecture. example: LPC213x

It should display Hour Minute and Seconds. I have no idea about ARM so having trouble getting started.

My code below is not working

// ...

int main (void) {
    int hour=0;
    int min=0;
    int sec;
    init_serial(); /* Init UART */
    Initialize();
    CCR=0x11;
    PCONP=0x1815BE; 
    ILR=0x1;         //  Clearing Interrupt

    //printf("\nTime is %02d:%02x:%02d",hour,min,sec);

    while (1) { /* Loop forever */
    }
}

void Initialize()
{
VPBDIV=0x0;
//CCR=0x2; 
//ILR=0x3; 
HOUR=0x0;
SEC=0x0;
MIN=0x0;


ILR = 0x03; 
CCR = (1<<4) | (1<<0); 

VICVectAddr13 = (unsigned)read_rtc; 
VICVectCntl13 |= 0x20 | VIC_RTC; 
VICIntEnable |= (1 << VIC_RTC);

}
/* Interrupt Service Routine*/
__irq void read_rtc() 
{
int hour=0;
int min=0;
int sec;
ILR=0x1;         //  Clearing Interrupt
hour=(CTIME0 & MASKHR)>>16;
min= (CTIME0 & MASKMIN)>>8;
sec=CTIME0 & MASKSEC;

printf("\nTime is %02d:%02x:%02d",hour,min,sec);

//VICVectAddr=0xff;
VICVectAddr = 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ぃ弥猫深巷。 2024-08-17 00:00:58

根据LPC213x的此板描述,它附带了一个示例程序称为“实时时钟 - 演示如何使用实时时钟”。这也意味着该板具有实时时钟硬件,这将使事情变得更加容易。

我建议您阅读该程序,了解如何与 RTC 硬件通信。下一步将是解决显示要求。两个明显的选择是 7 段 LED 显示屏,或 LCD

两者都是众所周知的技术,已编写了相关负载,请点击维基百科链接了解更多信息。

According to this board description for the LPC213x, it is delivered with an example program called "Real-Time Clock - Demonstrates how the real-time clock can be used". This also implies that the board features real-time clock hardware, which is going to make it a lot easier.

I suggest you read up on that program, to figure out how to talk to the RTC hardware. The next step would be to solve the display requirements. The two obvious choices are either 7-segment LED displays, or an LCD.

Both are well-known technologies about which loads have been written, follow the Wikipedia links to find out more.

在风中等你 2024-08-17 00:00:58

这就是LPC2468 的全部内容。我们也有一个 setTime 函数,但我不想为你做所有的工作。 ;) 我们有自定义寄存器文件以便于访问,但是如果您查看 LPC 手册,就会很明显地看出它们之间的关联。您只需将值移至正确的位置,然后进行按位运算即可。例如:

#define RTC_HOUR       (*(volatile RTC_HOUR_t *)(RTC_BASE_ADDR + (uint32_t)0x28))

时间结构:

typedef struct {
  uint8_t  seconds;        /* Second value - [0,59] */
  uint8_t  minutes;        /* Minute value - [0,59] */
  uint8_t  hour;           /* Hour value - [0,23] */
  uint8_t  mDay;           /* Day of the month value - [1,31] */
  uint8_t  month;          /* Month value - [1,12] */
  uint16_t year;           /* Year value - [0,4095] */
  uint8_t  wDay;           /* Day of week value - [0,6] */
  uint16_t yDay;           /* Day of year value - [1,365] */
} rtcTime_t;

RTC 功能:

void rtc_ClockStart(void) {
  /* Enable CLOCK into RTC */
  scb_ClockStart(M_RTC);
  RTC_CCR.B.CLKSRC = 1;
  RTC_CCR.B.CLKEN  = 1;
  return;
}

void rtc_ClockStop(void) {
  RTC_CCR.B.CLKEN = 0;
  /* Disable CLOCK into RTC */
  scb_ClockStop(M_RTC);
  return;
}

void rtc_GetTime(rtcTime_t *p_localTime) {
  /* Set RTC timer value */
  p_localTime->seconds = RTC_SEC.R;
  p_localTime->minutes = RTC_MIN.R;
  p_localTime->hour    = RTC_HOUR.R;
  p_localTime->mDay    = RTC_DOM.R;
  p_localTime->wDay    = RTC_DOW.R;
  p_localTime->yDay    = RTC_DOY.R;
  p_localTime->month   = RTC_MONTH.R;
  p_localTime->year    = RTC_YEAR.R;
}

系统控制块功能:

void scb_ClockStart(module_t module) {
  PCONP.R |= (uint32_t)1 << module;
}

void scb_ClockStop(module_t module) {
  PCONP.R &= ~((uint32_t)1 << module);
}

This is all for the LPC2468. We have a setTime function too, but I don't want to do ALL the work for you. ;) We have custom register files for ease of access, but if you look at the LPC manual, it's obvious where they correlate. You just have to shift values into the right place, and do bitwise operations. For example:

#define RTC_HOUR       (*(volatile RTC_HOUR_t *)(RTC_BASE_ADDR + (uint32_t)0x28))

Time struture:

typedef struct {
  uint8_t  seconds;        /* Second value - [0,59] */
  uint8_t  minutes;        /* Minute value - [0,59] */
  uint8_t  hour;           /* Hour value - [0,23] */
  uint8_t  mDay;           /* Day of the month value - [1,31] */
  uint8_t  month;          /* Month value - [1,12] */
  uint16_t year;           /* Year value - [0,4095] */
  uint8_t  wDay;           /* Day of week value - [0,6] */
  uint16_t yDay;           /* Day of year value - [1,365] */
} rtcTime_t;

RTC functions:

void rtc_ClockStart(void) {
  /* Enable CLOCK into RTC */
  scb_ClockStart(M_RTC);
  RTC_CCR.B.CLKSRC = 1;
  RTC_CCR.B.CLKEN  = 1;
  return;
}

void rtc_ClockStop(void) {
  RTC_CCR.B.CLKEN = 0;
  /* Disable CLOCK into RTC */
  scb_ClockStop(M_RTC);
  return;
}

void rtc_GetTime(rtcTime_t *p_localTime) {
  /* Set RTC timer value */
  p_localTime->seconds = RTC_SEC.R;
  p_localTime->minutes = RTC_MIN.R;
  p_localTime->hour    = RTC_HOUR.R;
  p_localTime->mDay    = RTC_DOM.R;
  p_localTime->wDay    = RTC_DOW.R;
  p_localTime->yDay    = RTC_DOY.R;
  p_localTime->month   = RTC_MONTH.R;
  p_localTime->year    = RTC_YEAR.R;
}

System control block functions:

void scb_ClockStart(module_t module) {
  PCONP.R |= (uint32_t)1 << module;
}

void scb_ClockStop(module_t module) {
  PCONP.R &= ~((uint32_t)1 << module);
}
手长情犹 2024-08-17 00:00:58

如果您需要有关 ARM 的信息,请参阅ARM 系统开发人员指南:设计和优化系统软件可能会对您有所帮助。

我们曾经为 ARM 做过类似的事情。

    #include "LPC21xx.h"
    void rtc()
    {
         *IODIR1 = 0x00FF0000;
             // Set LED ports to output
         *IOSET1 = 0x00020000;
         *PREINT = 0x000001C8;
            // Set RTC prescaler for 12.000Mhz Xtal
         *PREFRAC = 0x000061C0;
         *CCR = 0x01;
        *SEC = 0;
        *MIN = 0;
        *HOUR= 0;
    }

If you need information about ARM then this ARM System Developer's Guide: Designing and Optimizing System Software may help you.

We used to do some thing like this for ARM.

    #include "LPC21xx.h"
    void rtc()
    {
         *IODIR1 = 0x00FF0000;
             // Set LED ports to output
         *IOSET1 = 0x00020000;
         *PREINT = 0x000001C8;
            // Set RTC prescaler for 12.000Mhz Xtal
         *PREFRAC = 0x000061C0;
         *CCR = 0x01;
        *SEC = 0;
        *MIN = 0;
        *HOUR= 0;
    }
温折酒 2024-08-17 00:00:58

实时时钟 (RTC) 是一种跟踪当前时间的计算机时钟(最常见的是集成电路的形式)。尽管该术语通常指个人计算机、服务器和嵌入式系统中的设备,但 RTC 几乎存在于所有需要保持准确时间的电子设备中。

您可以参考这两个链接,我相信它会让您进一步理解:-

1)。使用 CMSIS 进行 ARM Cortex 编程:- http://www.firmcodes.com/cmsis/

2)。使用 ARM7 进行 RTC 编程:- http://www. Firmcodes.com/microcontrollers/arm/real-time-clock-of-arm7-lpc2148/

A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computers, servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

You May refer this two link, i am sure it will give you further understanding :-

1). ARM Cortex Programming using CMSIS:- http://www.firmcodes.com/cmsis/

2). RTC Programming with ARM7:- http://www.firmcodes.com/microcontrollers/arm/real-time-clock-of-arm7-lpc2148/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文