Cortex A8,RTC程序

本文介绍了一个基于S5PC100平台的实时钟(RTC)实现案例,通过初始化RTC并设置闹钟功能,实现了定时提醒的功能。程序使用了UART进行串口输出,并通过中断方式处理RTC报警。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "s5pc100.h"
#include "uart.h"


void key1_int(void);
void rtc_init(void);
void alm_int(void);
void bcd2str(unsigned int bcd, char *str);

char str[4];

int main()
{
	int i;

	uart_init();
	rtc_init();

	VIC0VECTADDR.VIC0VECTADDR28 = (unsigned int)alm_int;
	VIC0INTERRUPT.VIC0INTENABLE = (1 << 28);

	while (1) {
		puts("Current time is: ");
		bcd2str(RTCBCD.BCDHOUR & 0x3F, str);
		puts(str);
		puts(":");
		bcd2str(RTCBCD.BCDMIN & 0x7F, str);
		puts(str);
		puts(":");
		bcd2str(RTCBCD.BCDSEC & 0x7F, str);
		puts(str);
		puts("\n");
		for (i = 0; i < 3600000; i++);
	}

	return 0;
}

void do_irq(void)
{
	((void (*)(void))VIC0ADDRESS)();
	VIC0ADDRESS = 0;
}

void alm_int(void)
{
	puts("Please get up\n");
	RTCINTP |= 1<<1;
}

void rtc_init(void)
{
	RTCALARM.ALMSEC = 0x05;//设置闹铃时间
	RTCALARM.RTCALM |=  (1 << 6) | 1;//使能全局闹铃时钟,和秒闹铃时钟

	RTCCON = 0X01;//RTC控制使能
	//设置时间
	RTCBCD.BCDSEC  = 0x00;
	RTCBCD.BCDMIN  = 0x00;
	RTCBCD.BCDHOUR = 0x12;
	RTCBCD.BCDDATE = 0x15;
	RTCBCD.BCDMON  = 0x03;
	RTCBCD.BCDYEAR = 0x12;

	RTCCON = 0;//RTC控制关闭
}

void bcd2str(unsigned int bcd, char *str)
{
	str[0] = ((bcd >> 4) & 0xF) + '0';
	str[1] = ((bcd >> 0) & 0xF) + '0';
	str[2] = '\0';
}
工程源码: 点击打开链接
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值