S3C2440 Real-time Clock RTC

Publisher:LogicLeaperLatest update time:2016-04-18 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
        The Real Time Clock (RTC) unit can be operated by a backup battery when the system power is off. The RTC can be

The RTC unit operates on an
external 32.768kHz crystal oscillator and can perform alarm functions.

RTC operation is relatively simple, and the register settings are described in detail in the data sheet, so I will not write about them here. I will post an RTC code. This program refers to Tianxiang's RTC program code, mainly because his code is better and modularized. I modified his code to have an alarm (using a buzzer) and it can run on the TQ2440 board. Program functions: The serial port displays the time once per second and LED1 flashes once. In the alarm setting, when the second is 20, the alarm time is displayed and the buzzer sounds for a few seconds.

 
  1. #include "2440addr.h"  
  2. #include "Option.h"  
  3. #include "2440lib.h"  
  4. #include "def.h"  
  5.   
  6. #define LED1_ON (rGPBDAT &=~(1<<5))  
  7. #define LED1_OFF (rGPBDAT |=(1<<5) )  
  8.   
  9. void __irq RTC_tickHandler(void);  
  10. void __irq RTC_alarmHandler(void);  
  11.   
  12.   
  13. U8 alarmflag=0;  
  14.   
  15. typedef struct Date //Define a structure representing date and time  
  16.     { U16 year;  
  17.         U8 month;  
  18.         U8 day;  
  19.         U8 week_day;  
  20.         U8 hour;  
  21.         U8 minute;  
  22.         U8 second;  
  23.     }date;  
  24.       
  25. date C_date;      
  26. char *week_num[7]={ "SUN","MON","TUES","WED","THURS","FRI","SAT" }; ​​//define a pointer array  
  27.   
  28. void Beep_Freq_Set( U32 freq )  
  29. {  
  30.   
  31.     rGPBCON &=~3;  
  32.     rGPBCON |= 2; //Set GPB0 to OUT0  
  33.   
  34.     rGPBUP=0x0; //Enable pull-up  
  35.   
  36.     rTCFG0 &=~0xff;  
  37.     rTCFG0 |=15; //Prescaler value is 15  
  38.       
  39.     rTCFG1 &=~0x0f;  
  40.     rTCFG1 |=0x02; //Division value is 8  
  41.       
  42.     rTCNTB0 = (PCLK>>7)/freq; //Set the value of timer 0 count buffer     
  43.     rTCMPB0 = rTCNTB0>>1; // Timer 0 compares the buffer value, PWM output duty cycle 50%     
  44.     
  45.     rTCON &= ~0x1f;    
  46.     rTCON |= 0xb; //Auto reload, turn off phase shift, manually update, turn on timer 0     
  47.     rTCON &= ~2; // Clear the manual update bit     
  48. }    
  49.     
  50. void Beep_Stop( void )    
  51. {    
  52.     rGPBCON &= ~3; //set GPB0 as output     
  53.     rGPBCON |= 1;    
  54.     rGPBDAT &= ~1; //output low level     
  55. }    
  56.   
  57. void delay(int x)  
  58. {  
  59.     int i,j;  
  60.     for(i=0;i
  61.     for(j=0;j<1000000;j++);  
  62. }  
  63. /********************************** 
  64. * Set the real-time clock date and time 
  65. *********************************/  
  66. void RTC_setdate(date *p_date)  
  67. {  
  68.     rRTCCON=0x01; //RTC read and write enable, BCD clock, counter, no reset  
  69.       
  70.     rBCDYEAR = p_date->year;  
  71.     rBCDMON = p_date->month;  
  72.     rBCDDATE = p_date->day;  
  73.     rBCDDAY = p_date->week_day; //Set date and time  
  74.     rBCDHOUR = p_date->hour;  
  75.     rBCDMIN = p_date->minute;  
  76.     rBCDSEC = p_date->second;  
  77.       
  78.     rRTCCON=0x00; //RTC read and write disabled, BCD clock, counter, no reset  
  79. }  
  80.   
  81. /********************************** 
  82. * Read real-time clock date and time 
  83. *********************************/  
  84. void RTC_getdate(date *p_date)  
  85. {  
  86.     rRTCCON=0x01; //RTC read and write enable, BCD clock, counter, no reset  
  87.           
  88.     p_date->year = rBCDYEAR+0x2000;  
  89.     p_date->month = rBCDMON;  
  90.     p_date->day = rBCDDATE;  
  91.     p_date->week_day = rBCDDAY; //Read date and time  
  92.     p_date->hour = rBCDHOUR;  
  93.     p_date->minute = rBCDMIN;  
  94.     p_date->second = rBCDSEC;      
  95.   
  96.     rRTCCON=0x00; //RTC read and write disabled, BCD clock, counter, no reset  
  97. }  
  98.   
  99. /********************************** 
  100. * TICK interrupt initialization 
  101. *********************************/  
  102. void RTC_tickIRQ_Init(U8 tick)  
  103. {  
  104.     ClearPending(BIT_TICK); // Clear the flag  
  105.     EnableIrq(BIT_TICK); //Enable interrupt source  
  106.       
  107.     pISR_TICK=(unsigned)RTC_tickHandler; //interrupt function entry address  
  108.       
  109.     rRTCCON=0x00;  
  110.       
  111.     rTICNT=(tick&0x7f)|0x80; //Enable interrupt  
  112. }  
  113.   
  114. /********************************** 
  115. * Set alarm date, time and alarm wake-up mode 
  116. *********************************/  
  117. void RTC_alarm_setdate(date *p_date,U8 mode)  
  118. {  
  119.     rRTCCON = 0x01;  
  120.       
  121.     rALMYEAR = p_date->year;  
  122.     rALMMON = p_date->month;  
  123.     rALMDATE = p_date->day;    
  124.     rALMHOUR = p_date->hour;  
  125.     rALMMIN = p_date->minute;  
  126.     rALMSEC = p_date->second;  
  127.     rRTCALM = mode; //RTC alarm control register  
  128.       
  129.     rRTCCON = 0x00;  
  130.       
  131.     ClearPending(BIT_RTC); //Clear flag                    
  132.     EnableIrq(BIT_RTC); //open RTC alarm INTERRUPT  
  133.       
  134.     pISR_RTC = (unsigned)RTC_alarmHandler;  
  135. }  
  136.   
  137. void Main(void)  
  138. {  
  139.   
  140.     SelectFclk(2); //Set the system clock to 400M       
  141.     ChangeClockDivider(2, 1); //Set the frequency division to 1:4:8  
  142.     CalcBusClk(); //Calculate bus frequency  
  143.       
  144.     rGPHCON &=~((3<<4)|(3<<6));     
  145.     rGPHCON |=(2<<4)|(2<<6); //GPH2--TXD[0];GPH3--RXD[0]       
  146.     rGPHUP=0x00; //Enable pull-up function  
  147.           
  148.     Uart_Init(0,115200);  
  149.     Uart_Select(0);  
  150.       
  151.     rGPBCON &=~((3<<10)|(3<<12)|(3<<14)|(3<<16)); // Clear GPBCON[10:17]  
  152.     rGPBCON |=((1<<10)|(1<<12)|(1<<14)|(1<<16)); //Set GPB5~8 to output  
  153.     rGPBUP &=~((1<<5)|(1<<6)|(1<<7)|(1<<8)); //Set the pull-up function of GPB5~8  
  154.     rGPBDAT |=(1<<5)|(1<<6)|(1<<7)|(1<<8); //Turn off LED  
  155.       
  156.     Beep_Stop(); //The buzzer stops sounding and is used as an alarm  
  157.       
  158.     C_date.year = 0x12;  
  159.     C_date.month = 0x05;  
  160.     C_date.day = 0x09;  
  161.     C_date.week_day = 0x03; //Set the current date and time  
  162.     C_date.hour = 0x12;  
  163.     C_date.minute = 0x00;  
  164.     C_date.second = 0x10;     
  165.       
  166.     RTC_setdate(&C_date);  
  167.       
  168.     C_date.second=0x20;  
  169.       
  170.     RTC_alarm_setdate(&C_date,0x41); //0x41 means enabling the RTC alarm and the second clock alarm  
  171.       
  172.     RTC_tickIRQ_Init(127); // Set the tick to occur once per second  
  173.       
  174.       
  175.     Uart_Printf("\n ---Real-time clock test program---\n");  
  176.     while(Uart_GetKey()!= ESC_KEY)  
  177.     {  
  178.         LED1_OFF;  
  179.         RTC_getdate(&C_date);  
  180.         if(alarmflag)  
  181.         {  
  182.             alarmflag=0;  
  183.           
  184.             Uart_Printf("\nRTC ALARM %02x:%02x:%02x \n",C_date.hour,C_date.minute,C_date.second);  
  185.             Beep_Freq_Set(1000);  
  186.             delay(5);  
  187.             Beep_Stop();  
  188.         }  
  189.     }  
  190.   
  191. }  
  192.   
  193. /********************************** 
  194. * TICK interrupt 
  195. *********************************/  
  196. void __irq RTC_tickHandler(void)  
  197. {  
  198.     ClearPending(BIT_TICK);  
  199.     LED1_ON; //Refresh LED1  
  200.     Delay(500);  
  201.     RTC_getdate(&C_date);  
  202.     Uart_Printf("RTC TIME: %04x-%02x-%02x %s %02x:%02x:%02x\n", C_date.year,C_date.month,C_date.day,week_num[C_date.week_day], C_date.hour , C_date.minute, C_date.second );  
  203.       
  204. }   
  205.   
  206. /********************************** 
  207. * TICK interrupt 
  208. *********************************/  
  209. void __irq RTC_alarmHandler(void)  
  210. {  
  211.    alarmflag = 1;  
  212.    ClearPending(BIT_RTC);  
  213. }  


 

Keywords:S3C2440 Reference address:S3C2440 Real-time Clock RTC

Previous article:S3C2440 IIC bus interface
Next article:S3C2440 Interrupt Controller

Recommended ReadingLatest update time:2024-11-16 17:40

S3C2440 Lighting
To light up the LED on the development board, you need to first check the schematic diagram, find the corresponding pins, and understand the schematic diagram to see how the light will light up on the circuit. 1. Look at the schematic diagram JZ2440v2_sch.pdf and find the corresponding pins   nLED_1 corresponds to
[Microcontroller]
Understand the principle and application of S3C2440 touch screen driver
1. Development environment Host: VMWare--Fedora 9 Development board: Mini2440--64MB Nand, Kernel:2.6.30.4 Compiler: arm-linux-gcc-4.3.2 2. Prerequisite knowledge 1. Linux input subsystem (Input Subsystem): In Linux, the input subsystem is composed of the input subsystem device driver layer, the input subsystem core
[Microcontroller]
Understand the principle and application of S3C2440 touch screen driver
S3C2440 bare metal -------LCD_framework and preparation
1. Framework 2. Preparation We need to prepare a program that supports norfalsh and nandflash booting. When our program is smaller than 4K, we can copy the nandflash program to the on-chip 4K memory, but now our program is larger than 4K, so we need to copy the program to SDRAM.
[Microcontroller]
S3C2440 bare metal -------LCD_framework and preparation
Design of electric energy metering live checker system based on S3C2440 processor and Windows CE
With the rapid development of my country's economy, the demand for large-scale industrial and commercial electricity is growing rapidly. High-voltage power supply systems with national voltage standards of 10 kV and above are commonly used in urban and rural areas of my country. Due to considerations of power supply r
[Microcontroller]
Design of electric energy metering live checker system based on S3C2440 processor and Windows CE
STM8L RTC
The STM8L clock is divided into internal clock and external clock. Internal clocks: HSI (16MHz high-speed internal clock), LSI (38 kHz low-speed internal clock)      External clocks: HSE (16 MHz high-speed external clock), LSE (32.768kHz low-speed external clock) STM8 RTC clock can use LSI (38KHz) or LSE (32.768
[Microcontroller]
S3C2440 bare metal experiment timer
S3c2440 has 5 16-bit timers. Timers 0, 1, 2, and 3 have pulse width modulation (PWM) functions. Timer 4 has an internal timer without an output pin. Timer 0 has a dead zone generator for high-current devices.   Timers 0 and 1 share an 8-bit prescaler (prescaler), and timers 2, 3, and 4 share another 8-bit prescaler .
[Microcontroller]
Nordic52810 Getting Started - Real Time Clock (RTC)
RTC-24-bit real-time clock counter, the RTC module uses the low-frequency clock LCFK, 52810 has two RTC modules RTC0 and RTC1 Statement: When the Bluetooth protocol stack is enabled, RTC0 will be used; the APP_TIMER library uses RTC1, so when the APP_TIMER component is enabled, RTC1 cannot be used directly 1. Prin
[Microcontroller]
Nordic52810 Getting Started - Real Time Clock (RTC)
GNU ARM Assembly--(VIII) s3c2440 watchdog
       Since the microcontroller, watchdog has been indispensable. In various application environments, the program may run away or die. At this time, a watchdog is needed to ensure that the entire system returns to normal.         As usual, the datasheet description of s3c2440 is given: Overview:     The watchdog
[Microcontroller]
GNU ARM Assembly--(VIII) s3c2440 watchdog
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号