//中断函数应该会写吧*_*
void Timer_Config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE)
TIM_DeInit(TIM2)
TIM_TimeBaseStructure.TIM_Period=1000//自动重装载寄存器周期的值(计数值)
TIM_TimeBaseStructure.TIM_Prescaler= (7200 - 1)//时钟预分频数
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1//采样分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up//向上计数模式
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure)
TIM_ClearFlag(TIM2, TIM_FLAG_Update)//清除溢出中断标志
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE)
TIM_Cmd(TIM2, ENABLE)//开启时钟
}
我这里有一段js动态时钟的代码,日历的比较复杂,没有研究:<scripttype="text/javascript">
setInterval(function() {
var week
var date
var today = new Date()
var year = today.getFullYear()
var month = today.getMonth() + 1
var day = today.getDate()
var ss = today.getDay()
var hours = today.getHours()
var minutes = today.getMinutes()
var seconds = today.getSeconds()
date = year + "年" + month +"月" + day + "日 "
if (ss == 0) week = "星期日"
if (ss == 1) week = "星期一"
if (ss == 2) week = "星期二"
if (ss == 3) week = "星期三"
if (ss == 4) week = "星期四"
if (ss == 5) week = "星期五"
if (ss == 6) week = "星期六"
if (minutes <= 9) minutes ="0" + minutes
if (seconds <= 9) seconds ="0" + seconds
document.getElementById('p_time').innerHTML = "今天是:" + date
+ week + " " + hours + ":" + minutes + ":" +
seconds
},
1000)
</script>
这里一定要注意,html里要有一个id为p_time的div。
css 有个 animation 可以实现动画,仅仅是动起来,没法实现实时与系统对时(需要js)60秒跳动60次旋转360度。(可以使用linear 线性运动)
# animation:anim_mm 60s linear infinite
animation:mm 60s steps(60) infinite
@keyframes mm{
to{ transform:rotate(360deg) }
}