有没有人用过STM8L152C6的RTC时钟
时间:10-02
整理:3721RD
点击:
有没有人用过STM8L152C6的RTC时钟,我现在要用STM8L152C6的RTC时钟作出手表计时,不使用库函数编程,在百度一直找不到相关代码,只找不到RTC时钟焕解的代码,有没有人能帮忙给人相关代码,在数据手册上描述初始化RTC时钟的部分也不大明白,有做过这方面的请告诉怎么写
#include <iostm8l152c6.h>
#include <intrinsics.h>
unsigned int Beep_Freq = 500; //蜂鸣器输出频率
#define LED_out PC_ODR_bit.ODR7
void Port_Init(void){
PC_DDR_bit.DDR7 = 1;
PC_CR1_bit.C17 = 1;
PC_CR2_bit.C27 = 0;
PC_ODR_bit.ODR7 = 1;
}
void RTC_AWU()
{
CLK_PCKENR2 |= 0x04; //外设RTC时钟允许,Frtc = Flsi/8 = 38K/8
CLK_CRTCR = 0x04; //CLK_CRTCR[7:5]=000B 则RTC clock source/1
//CLK_CRTCR[4;1]=0010B 则选择LSI
while( (CLK_CRTCR&0x01) == 0x1 ); //CLK_CRTCR[0]=1为忙
//RTC解锁,必须先写0xCA后写0x53
RTC_WPR = 0xCA;
RTC_WPR = 0x53;
RTC_CR2_WUTE = 0; //必须先清专用定时器唤醒允许位,再操作RTC其它寄存器
RTC_CR1 = 0x00; //wakeup时钟选择,RTC_CR1[2:0]=000B则选择 RTCCLK/16
while( RTC_ISR1_WUTWF == 0 ); //等待wakeup时钟允许,即:WUTWF=1为允许
//写定时计数器的值(下向计数的)
// Wakeup周期 = 1/(Frtc/8/16)*(WUT[15:0]+1)
// = 1/(38K/8/16)*(10000+1)
// = 3.368ms*10001 =
// RTC_WUTRH = 10000/256;
// RTC_WUTRL = 10000%256;
RTC_WUTRH = 1000/256;
RTC_WUTRL = 1000%256;
RTC_CR2_WUTIE = 1;
RTC_CR2_WUTE = 1;
asm("RIM");
}
//********************************************************************************
//RTC AWU中断
/*#pragma vector=0X06*/
#pragma vector=RTC_WAKEUP_vector
__interrupt void RTC_AWU_vector()
{
RTC_ISR2_WUTF = 0; //清RTC AWU中断标志
LED_out = !LED_out;
}
void main(void)
{
// CLK_PCKENR2 |= 0x02;
__disable_interrupt();
CLK_CKdivR = 0x00;
Port_Init();
RTC_AWU();
__enable_interrupt();
for(;;)
{;
}
}
#include <iostm8l152c6.h>
#include <intrinsics.h>
unsigned int Beep_Freq = 500; //蜂鸣器输出频率
#define LED_out PC_ODR_bit.ODR7
void Port_Init(void){
PC_DDR_bit.DDR7 = 1;
PC_CR1_bit.C17 = 1;
PC_CR2_bit.C27 = 0;
PC_ODR_bit.ODR7 = 1;
}
void RTC_AWU()
{
CLK_PCKENR2 |= 0x04; //外设RTC时钟允许,Frtc = Flsi/8 = 38K/8
CLK_CRTCR = 0x04; //CLK_CRTCR[7:5]=000B 则RTC clock source/1
//CLK_CRTCR[4;1]=0010B 则选择LSI
while( (CLK_CRTCR&0x01) == 0x1 ); //CLK_CRTCR[0]=1为忙
//RTC解锁,必须先写0xCA后写0x53
RTC_WPR = 0xCA;
RTC_WPR = 0x53;
RTC_CR2_WUTE = 0; //必须先清专用定时器唤醒允许位,再操作RTC其它寄存器
RTC_CR1 = 0x00; //wakeup时钟选择,RTC_CR1[2:0]=000B则选择 RTCCLK/16
while( RTC_ISR1_WUTWF == 0 ); //等待wakeup时钟允许,即:WUTWF=1为允许
//写定时计数器的值(下向计数的)
// Wakeup周期 = 1/(Frtc/8/16)*(WUT[15:0]+1)
// = 1/(38K/8/16)*(10000+1)
// = 3.368ms*10001 =
// RTC_WUTRH = 10000/256;
// RTC_WUTRL = 10000%256;
RTC_WUTRH = 1000/256;
RTC_WUTRL = 1000%256;
RTC_CR2_WUTIE = 1;
RTC_CR2_WUTE = 1;
asm("RIM");
}
//********************************************************************************
//RTC AWU中断
/*#pragma vector=0X06*/
#pragma vector=RTC_WAKEUP_vector
__interrupt void RTC_AWU_vector()
{
RTC_ISR2_WUTF = 0; //清RTC AWU中断标志
LED_out = !LED_out;
}
void main(void)
{
// CLK_PCKENR2 |= 0x02;
__disable_interrupt();
CLK_CKdivR = 0x00;
Port_Init();
RTC_AWU();
__enable_interrupt();
for(;;)
{;
}
}
最近大家是不是去过节了,都没回答
不错。值得学习!