p5.c
来自「y uurug bdf lgdfjg dfg df g dt」· C语言 代码 · 共 156 行
C
156 行
//Program to Configure the RTC and then to display the current time on the LCD
// Connect Data of LCD with P0.16-P0.23
// Connect Control of LCD with P0.8- P0.15
#include <LPC210x.h>
#define PLOCK 0x0400
#define TIME 20000
#define DISP_FUNC 0x38 // sets the display to 8-bit, 2 lines, 5x7 chars + cursor-off
#define DISP_ENTRY 0x06
#define DISP_CNTL 0x0E
#define DISP_ON 0x04
#define DISP_CURSOR 0x02
#define DISP_CLEAR 0x01
#define DISP_HOME 0x02
#define DISP_POS 0x80
#define DISP_BLINK 0x01
#define DISP_SECOND 0xC0
unsigned long b;
void Init(void);
void Delay (unsigned long a);
unsigned char i,j;
unsigned long Hour,Min,Sec;
char string[16]=" Advance ";
char string1[16]=" Technology ";
//---------------------------------------------------------
// System initializations
//PLL0FEED (PLL Feed Register) contains the 8-bit value last written to this register.
//To set the clock configuration, this register must be stored with consecutive values of 0xAA and 0x55
//---------------------------------------------------------
void Init() {
// Init PLL
PLLCFG=0x23; // P=2, M=4, PLLfreq = 235,9296 Mhz, CCLK = 58,9824 Mhz
PLLFEED=0xAA; PLLFEED=0x55;
PLLCON=0x1; // Enable the PLL
PLLFEED=0xAA; PLLFEED=0x55;
while(!(PLLSTAT & PLOCK)); // Wait for PLL to lock
PLLCON=0x3; // Connect PLL as clock source
PLLFEED=0xAA; PLLFEED=0x55;
//Init MAM & Flash memory fetch
MAMCR=0x2; //mam = flash
MAMTIM=0x4;
VPBDIV=0x1; //pclk = cclk
//GPIO init
IODIR=0xFFFFFFFF; //All pins are output(LED)
}
void Delay (unsigned long a)
{
while (--a!=0);
}
//For writing the instruction of the LCD
void inswrt(unsigned char c)
{
b = (c << 16)|(0x02<<8);
IOSET=b;
IOCLR = 0x00000200;
IOCLR = 0xFFFFFFFF;
Delay(TIME);
}
// For writing the data on the LCD
void datawrt(unsigned char c)
{
b = (c << 16)|(0x03<<8);
IOSET=b;
IOCLR = 0x00000300;
IOCLR = 0xFFFFFFFF;
Delay(TIME);
}
//---------------------------------------------------------
// RESET entry
//---------------------------------------------------------
int main()
{ IOCLR = 0xFFFFFFFF;
Init();
Delay(TIME);
// Instructions Before writing any data on the LCD
inswrt(DISP_FUNC);
inswrt(DISP_CNTL);
inswrt(DISP_ENTRY);
inswrt(DISP_CLEAR);
CCR = 0;
CIIR = 0x00000000;
AMR = 0xFFFFFFFF; //All the Alarm Register are masked and not used
// Setting the Current time on the RTC Registers
SEC=0x00000000;
MIN=0x00000001;
HOUR=0x00000004;
DOM=0x0000000A;
DOW=0x00000004;
DOY=0x000000010;
MONTH=0x00000008;
YEAR=0x000007D7;
/****** ORIGINAL VALUES *******/
PREINT = 1952;//1830;
PREFRAC = 4096;//1792;
// To Start the RTC
CCR=0x00000001;
while(1)
{
inswrt(DISP_POS);
i = DOM/10;
datawrt(i+0x30);
i = DOM%10;
datawrt(i+0x30);
datawrt('/');
i = MONTH/10;
datawrt(i+0x30);
i = MONTH%10;
datawrt(i+0x30);
datawrt('/');
inswrt(DISP_POS+0x09);
i = YEAR%10;
j = YEAR/10;
datawrt(i+0x30);
inswrt(DISP_POS+0x08);
i = j%10;
j = j/10;
datawrt(i+0x30);
inswrt(DISP_POS+0x07);
i = j/10;
j = j%10;
datawrt(j+0x30);
inswrt(DISP_POS+0x06);
datawrt(i+0x30);
inswrt(DISP_POS+0x40);
i = HOUR/10;
datawrt(i+0x30);
i = HOUR%10;
datawrt(i+0x30);
datawrt(':');
i = MIN/10;
datawrt(i+0x30);
i = MIN%10;
datawrt(i+0x30);
datawrt(':');
i = SEC/10;
datawrt(i+0x30);
i = SEC%10;
datawrt(i+0x30);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?