ARM LPC2138/48 Mini Development Board – Internal Real Time Clock (RTC)
Sample code to use the internal RTC of LPC 2138/48 is given below. Here seconds, minutes & hour are initialized to 0. Time gets updated every second and is displayed on LCD in the format hh:mm:ss.
Changing the initial time : To change the initial time, just load the desired values into the corresponding registers HOUR, MIN & SEC.
Running the RTC : If you want to run the RTC forever after loading the initial values, follow these steps
- Ensure that the RTC battery is placed in battery holder.
- Flash the code.
- Comment the lines which load the initial values of time.
- Build the code & flash it again
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
/************************************************************************************* HEADER FILES **************************************************************************************/ #include<lpc21xx.h> unsigned char flag=0; /************************************************************************************* INTERRUPT SERVICE ROUTINE **************************************************************************************/ void RTC_int(void)__irq { ILR = 0X01; /* Clears counter increment interrupt */ flag = 1; /* Set flag on interrupt */ VICVectAddr = 0X00000000; } /************************************************************************************* * Function : RTC_Init * * * * Description : Function to initialize internal RTC * * * * Parameters : None * **************************************************************************************/ void RTC_Init() { ILR = 0X03; /* Interrupt from counter increment block */ CCR = 0X11; /* RTC Time counters enable */ CIIR = 0X01; /* Interrupt generated in each second */ SEC = 0x00; /* Load initial value into seconds register*/ MIN = 0x00; /* Load initial value into minutes register*/ HOUR = 0x00; /* Load initial value into hour register */ VICIntEnable = 0x00002000; /* RTC interrupt enabled */ VICVectCntl0 = 0x0000002D; /* RTC interrupt assigned to slot0 */ VICVectAddr0 = (unsigned)RTC_int; } /************************************************************************************* * Function : Delay * * * * Description : Function for delay * * * * Parameters : b - delay time * **************************************************************************************/ void Delay(unsigned long b) { while (--b!=0); /* Decrement b for delay */ } /************************************************************************************* * Function : Write_Command * * * * Description : Function to give command to LCD * * * * Parameters : cmd - command * **************************************************************************************/ void Write_Command(int cmd) { IO1CLR |= 0x00f00000; /* Clear D4-D7 */ IO1CLR |= 0x00040000; /* Read/Write = 0 */ IO1CLR |= 0X00020000; /* RS = 0,Command register */ IO1SET |= 0x00f00000 & cmd; /* Set D4-D7 */ IO1SET |= 0X00080000; /* Enable - high */ Delay(30000); IO1CLR |= 0x00080000; /* Enable - low */ } /************************************************************************************* * Function : Write_Data * * * * Description : Function to display data on LCD * * * * Parameters : dat - character to be displayed * **************************************************************************************/ void Write_Data(int dat) { IO1CLR |= 0x00f00000; /* Clear D4-D7 */ IO1CLR |= 0x00040000; /* Read/Write = 0 */ IO1SET |= 0X00020000; /* RS = 1,Data register */ IO1SET |= 0x00f00000 & dat; /* Set D4-D7 */ IO1SET |= 0X00080000; /* Enable - high */ Delay(30000); IO1CLR |= 0x00080000; /* Enable - low */ } /************************************************************************************* * Function : LCD_Data * * * * Description : Function to give data to display on LCD * * * * Parameters : dat - data * **************************************************************************************/ void LCD_Data(char dat) { Write_Data(dat << 16); Write_Data(dat << 20); } /************************************************************************************* * Function : LCD_Command * * * * Description : Function to give command to LCD * * * * Parameters : cmd - command * **************************************************************************************/ void LCD_Command(char cmd) { Write_Command(cmd << 16); Write_Command(cmd << 20); } /************************************************************************************* * Function : LCD_String * * * * Description : Function to display string on LCD * * * * Parameters : String to be displayed * **************************************************************************************/ void LCD_String(char *CPtr) { while(*CPtr != '\0') /* Check for string termination */ { LCD_Data(*CPtr); /* Display the character */ CPtr++; /* Increment the pointer */ Delay(20000); } } /************************************************************************************* * Function : LCD_Init * * * * Description : Function to initialize LCD * * * * Parameters : None * **************************************************************************************/ void LCD_Init(void) { IO1DIR |= 0x00FE0000; /* Set P1.17-P1.23 as output */ Delay(200000) ; Write_Command(0x30 << 16); Delay(100000); Write_Command(0x30 << 16); Delay(100000); Write_Command(0x30 << 16); Delay(100000); Write_Command(0x20 << 16); /* Enable 4 bit mode */ LCD_Command(0x01); /* Clear display */ LCD_Command(0x06); /* Auto address inc */ LCD_Command(0x0c); /* Cursor off */ LCD_Command(0x80); /* First location */ } /************************************************************************************* MAIN FUNCTION **************************************************************************************/ int main(void) { LCD_Init(); /* Initialize LCD module */ RTC_Init(); /* Initialize RTC module */ while(1) { if(flag) { LCD_Command(0x80); /* 1st row, 1st location */ flag=0; /* Clear flag */ LCD_Data(HOUR/10 + '0'); /* Display hour */ LCD_Data(HOUR%10 + '0'); LCD_Data(':') ; LCD_Data(MIN/10 + '0'); /* Display Minute */ LCD_Data(MIN%10 + '0'); LCD_Data(':') ; LCD_Data(SEC/10 + '0'); /* Display Second */ LCD_Data(SEC%10 + '0'); } } } /******************************* END OF PROGRAM ************************************/ |
Topics related to ARM LPC2138/48 Mini Development Board
- ARM LPC2138/48 Mini Development Board – Overview
- ARM LPC2138/48 Mini Development Board – LED Interfacing
- ARM LPC2138/48 Mini Development Board – LCD Interfacing
- ARM LPC2138/48 Mini Development Board – UART0 Interfacing
- ARM LPC2138/48 Mini Development Board – UART1 Interfacing
- ARM LPC2138/48 Mini Development Board – Switches Interfacing
- ARM LPC2138/48 Mini Development Board – BUZZER Interfacing
- ARM LPC2138/48 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2138/48 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2138/48 Mini Development Board – Interfacing Servo motor
- ARM LPC2138/48 Mini Development Board – Internal Real Time Clock (RTC)
- ARM LPC2148 Mini Development Board – USB Interfacing (Human Interface Device)
Resources
- Softwares
- Datasheets
How to buy?
- Click here to buy rhydoLABZ ARM LPC2129 Development board-Mini
- Click here to buy rhydoLABZ ARM LPC2138 Development Board-Mini
- Click here to buy rhydoLABZ ARM LPC2148 Development Board-Mini
SupportPlease share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.