计数时钟和滚动汉字显示c语言程序,MSP430F449单片机RTC时钟C语言程序(带闹钟)...

本文介绍了一个使用MSP430F449单片机实现的RTC时钟程序,包括软件万年历功能、自动切换屏幕、手动时间调整、闹钟设置和LED指示等功能。程序能自动识别闰年,并通过按键在三个屏幕上切换显示时间,当达到设定的闹钟时间时,会点亮LED灯直至用户确认。
摘要由CSDN通过智能技术生成

功能: 实现软件万年历功能,并自动识别闰年,A屏每显示5秒种就自动切换到B屏,B屏再显示5秒种就自动切换到C屏,C屏再显示5秒种就自动切换到A屏,通过按键在A屏、B屏和C屏之间切换 ,可通过按键手动设定和调整时间,当调整时对应调整位要有闪烁功能,有闹钟功能,可设置几点几分闹钟,当前时间等于闹钟时间时,用点亮LED指示,直到某个键(自定义)被按下时,熄灭LED灯

***************************************************/

#include

unsigned char cnt;                                                  // 计数器

unsigned char tian;                                                 // 天寄存器

unsigned char key_code;                                             // 按键值

unsigned char flag;                                                 // 换屏标志位

unsigned char twinkle_num;                                          // 闪烁标志位

unsigned char function_flag;                                        // 加减功能标志位

unsigned char function_ping1,function_ping2,function_ping3;         // 每屏闪烁位

unsigned char change_num;                                           // 闪屏时间定时

unsigned char change_ping;                                          // 三屏计数位

unsigned char clock_flag;                                           // 闹钟标志位

unsigned char ping_flag;                                            // 按键跟踪闪屏标志位

unsigned char num_flag;                                             // 按键计数闪屏标志位

unsigned char tian_flag;                                            // 天判断标志位

unsigned char run_flag;                                             // 闰年判断标志位

unsigned int key_num = 150;                                         // 按键消逗延时时间

unsigned int year = 2008;                                           // 年

unsigned char month = 2;                                            // 月

unsigned char day = 28;                                             // 日

unsigned char hour = 23;                                            // 小时

unsigned char min = 59;                                             // 分

unsigned char sec = 57;                                             // 秒

unsigned char nao_hour = 0;                                         // 闹钟时

unsigned char nao_min = 0;                                          // 闹钟分

unsigned char nao_sec = 0;                                          // 闹钟秒

const unsigned char tianshu[13] =

{0,31,28,31,30,31,30,31,31,30,31,30,31};                            // 每月天数表

char digit[12] =                                                    // 液晶显示段码表

{

0x7b,

0x12,

0x4f,

0x1f,

0x36,

0x3d,

0x7d,

0x13,

0x7f,

0x3F,

0x00

};

void init_clk(void);                                                // 初始化时钟

void key_scan(void);                                                // 按键扫描

void key_value(void);                                               // 按键值确定

void rtc(void);                                                     // 时钟扫描函数

void rtc_show(void);                                                // rtc扫描函数

void leap_year(void);                                               // 闰年判定函数

void main(void)

{

init_clk();                                                       // 时钟初始化

while(1)

{

key_scan();                                                     // 按键扫描

key_value();                                                    // 键值确定

rtc_show();                                                     // RTC显示

leap_year();                                                    // 闰年判定

if((sec == nao_sec) && (min == nao_min) && (hour == nao_hour))  // 闹钟判定

{

clock_flag = 1;                                               // 闹钟标志位置一

}

}

}

void init_clk(void)

{

unsigned char i;

WDTCTL = WDTPW + WDTHOLD;                                         // 关闭看门狗

FLL_CTL0 |= XCAP14PF;                                             // 选择14PF电容

IE2 |= BTIE;                                                      // 开启基本定时器中断

BTCTL = BT_ADLY_250 + BTFRFQ1;                                    // 250ms  16分频

LCDCTL = LCDON + LCD4MUX + LCDP2;                                 // STK LCD 4Mux, S0-S14

P5SEL = 0xFC;                                                     // 选择P5口第二功能

P1DIR |= 0x01;                                                    // P1.0选择输出

_EINT();                                                          // 开总中断

for (i=0; i<19; i++)

{

LCDMEM[i] = 0;                                                  //清LCD缓冲区

}

}

void key_scan(void)

{

static unsigned int num;                                          // 按键消抖计数器

if((P1IN&0x0e) != 0x0e)                                           // 如果不等于表示有键按下

{

num++;                                                          // 消逗计数器加

key_code = 0;                                                   // 键值清零

}

else

{

num = 0;                                                        // 按键抖动,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值