/******************************************************************
* 实验名称:可调数码管电子钟(MSP430F249)
*
* 实验说明:
* 通设置系统主时钟(MCLK=8Mhz ) 、辅助时钟(ACLK=8Mhz )、
* 子系统时钟(SMCLK=8Mhz )
* 编译软件:Embedded Workbench 5.3
*
*仿真软件:proteus7.7 sp 2
*
*作者:hameyou QQ:385434903
*
*日期:2010-7-31
******************************************************************/
#include <MSP430x24x.h>
#define uchar unsigned char
#define uint unsigned int
uchar const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, //共阴数码管段选码表,无小数点
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
struct {
uchar hou;
uchar min;
uchar sec;
}time;
struct {
uchar hou:1;
uchar min:1;
uchar sec:1;
}Flashflag;
uchar Disbuf[8],Index;
uint count1ms,FlashCnt;
uchar Keytimes=0;
void delayms(uint t)
{
uint i;
while(t--)
for(i=1330;i>0;i--);//进过参数的调整
}
void Init_Timer_A(void)
{
CCTL0 = CCIE; // 使能CCR0 中断
TAR=0xFC18; // 计数装入初值
TACTL=TASSEL_2+MC_2+TAIE+ID_3;//设置时钟源和计数模式 采用SMCLK/8 =1Mhz
}
void Refreshtime(void)
{
if(Flashflag.hou)
{
Disbuf[1]=table[time.hou%10];
Disbuf[0]=table[time.hou/10];
}
else
{
Disbuf[1]=0x00;
Disbuf[0]=0x00;
}
if(Flashflag.min)
{
Disbuf[3]=table[time.min/10];
Disbuf[4]=table[time.min%10];
}
else
{
Disbuf[3]=0x00;
Disbuf[4]=0x00;
}
if(Flashflag.sec)
{
Disbuf[6]=table[time.sec/10];
Disbuf[7]=table[time.sec%10];
}
else
{
Disbuf[6]=0x00;
Disbuf[7]=0x00;
}
}
uchar ReadKey(void)
{
static uchar count;
uchar temp;
temp=P2IN&0x07;
if(temp!=0x07)
{
if(++count==10)
{
return temp;
}else if(count>=200)
{
count=180;
return temp;
}else
return 0xFF;
}else
{
count=0;
return 0xFF;
}
}
void KeyProcess(void)
{
uchar temp;
temp=ReadKey();
if(temp!=0xFF)
{
temp=temp^0x07;
if(temp&0x01)
{
if(++Keytimes==4)
{
Keytimes=0;
Flashflag.hou=1;
Flashflag.min=1;
Flashflag.sec=1;
FlashCnt=0;
}
}
if(temp&0x02)
{
if(Keytimes==1)
{
if(++time.hou>=24)
time.hou=0;
}
else if(Keytimes==2)
{
if(++time.min>=60)
time.min=0;
}
else if(Keytimes==3)
{
if(++time.sec>=60)
time.sec=0;
}
}
if(temp&0x04)
{
if(Keytimes==1)
{
if(time.hou--==0)
time.hou=23;
}
else if(Keytimes==2)
{
if(time.min--==0)
time.min=59;
}
else if(Keytimes==3)
{
if(time.sec--==60)
time.sec=59;
}
}
}
}
void main(void)
{
WDTCTL=WDTPW + WDTHOLD; // 关闭看门狗
P4DIR=0x01;
P1DIR=0xFF; // 设置方向
P1SEL=0; // 设置为普通I/O 口
P3DIR=0xFF; // 设置方向
P3SEL=0; // 设置为普通I/O 口
P1OUT=0x00;
P3OUT=0xFF;
P2DIR=0x0;
P2OUT=0x07;
P2SEL=0x00;
time.hou=12;
Flashflag.hou=1;
Flashflag.min=1;
Flashflag.sec=1;
Disbuf[2]=0x40;
Disbuf[5]=0x40;
Refreshtime();
Init_Timer_A();
_BIS_SR(LPM0_bits+ GIE);//进入低功耗睡眠模式
while(1)
{
P3OUT=0xFF;
P1OUT=Disbuf[Index];
P3OUT=~(1<<Index);
if(++Index==8) Index=0;
delayms(1);
}
}
#pragma vector=TIMERA0_VECTOR //定时器A 中断服务程序
__interrupt void Timer_a(void)
{
switch(TAIV) //TAIV 表示中断向量号
{
case 2:break;
case 4:break;
case 10: //TAIV=10 表示中断计数器溢出中断
TAR=0xFC18;// (65536-1000)
P4OUT=P4OUT^0x01;
if(++count1ms==220)
{
time.sec++;
count1ms=0;
if(time.sec>=60)
{
time.sec=0;
time.min++;
if(time.min>=60)
{
time.min=0;
if(++time.hou>=24)
time.hou=0;
}
}
}
if(Keytimes)
{
if(++FlashCnt>=80)
{
if(Keytimes==1)
{
Flashflag.hou=!Flashflag.hou;
Flashflag.min=1;
Flashflag.sec=1;
}
else if(Keytimes==2)
{
Flashflag.min=!Flashflag.min;
Flashflag.hou=1;
Flashflag.sec=1;
}
else if(Keytimes==3)
{
Flashflag.sec=!Flashflag.sec;
Flashflag.hou=1;
Flashflag.min=1;
}
FlashCnt=0;
}
}
KeyProcess();
Refreshtime();
//TACCR0=0xF000;
break;
}
LPM0_EXIT;
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于MSP430F249的电子钟仿真(源码+仿真)
共38个文件
ewp:5个
ewd:5个
dni:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 55 浏览量
2024-04-26
17:55:11
上传
评论
收藏 44KB 7Z 举报
温馨提示
基于MSP430F249的电子钟仿真(源码+仿真) 基于MSP430F249的电子钟仿真(源码+仿真) 基于MSP430F249的电子钟仿真(源码+仿真) 基于MSP430F249的电子钟仿真(源码+仿真) 基于MSP430F249的电子钟仿真(源码+仿真)
资源推荐
资源详情
资源评论
收起资源包目录
基于MSP430F249的电子钟仿真(源码+仿真).7z (38个子文件)
基于MSP430F249的电子钟仿真(源码+仿真)
clock.ewd 13KB
clock.DSN 125KB
clock_A.ewd 12KB
clock_A.ewp 43KB
Backup (2) of clock.ewd 12KB
Backup of clock.ewp 30KB
clock_A.dep 565B
SourceFile
clock.c 5KB
clock_A.s43 2KB
clock.eww 159B
clock.PWI 1KB
clock.pdsprj.DESKTOP-L4T3F68.xl.workspace 3KB
Backup of clock.ewd 9KB
clock.dep 3KB
Backup of clock_A.ewp 30KB
Backup of clock_A.ewd 9KB
Last Loaded clock.DBK 125KB
clock.ewp 45KB
Backup (2) of clock.ewp 43KB
Debug
List
clock.s43 27KB
Obj
clock.r43 39KB
clock.pbd 114B
Exe
clock.hex 3KB
clock.ubrof 9KB
clock.d90 14KB
clock.d90.asm 21B
clock.a43 763B
clock.d43 479B
clock.rof 9KB
settings
clock.fmt 55B
clock.dni 809B
clock.wsdt 4KB
clock_A.dbgdt 63B
clock_A.fmt 55B
clock_A.dni 475B
clock.dbgdt 4KB
clock_A.cspy.bat 2KB
clock.cspy.bat 3KB
共 38 条
- 1
资源评论
森旺电子
- 粉丝: 6987
- 资源: 252
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功