/******************************************************************
* 实验名称:可调数码管电子钟(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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
MSP430单片机模块程序大全,TI杯电子设计大赛非常有用
共443个文件
ewp:45个
ewd:42个
s43:26个
5星 · 超过95%的资源 需积分: 12 172 下载量 97 浏览量
2010-08-12
19:59:00
上传
评论 8
收藏 2.49MB ZIP 举报
温馨提示
MSP430单片机模块程序大全,还有仿真,TI杯电子设计大赛非常有用,毫不容易我们团队总结出来的
资源推荐
资源详情
资源评论
收起资源包目录
MSP430单片机模块程序大全,TI杯电子设计大赛非常有用 (443个子文件)
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.a43 763B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.d90.asm 21B
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
clock.cspy.bat 3KB
ADC12.cspy.bat 3KB
00.cspy.bat 3KB
Dot.cspy.bat 3KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
clock_A.cspy.bat 2KB
IO.cspy.bat 2KB
IO_A.cspy.bat 2KB
clock.c 5KB
LCD1602.c 5KB
main.c 3KB
UART.c 3KB
SPI.c 3KB
main.c 2KB
timerA.c 2KB
main.c 2KB
horse.c 2KB
Mul_8LED.c 1KB
7LED.c 1KB
IO.c 932B
00.d43 17KB
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
clock.d43 479B
ADC12.d90 15KB
clock.d90 14KB
Dot.d90 13KB
00.d90 13KB
UART.d90 13KB
LCD1602.d90 11KB
timerA.d90 11KB
SPI.d90 9KB
clock.d90 9KB
Mul_8LED.d90 9KB
7LED.d90 8KB
IO.d90 8KB
IO.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
clock.dbgdt 4KB
IO_A.dbgdt 4KB
clock_A.dbgdt 63B
clock_A.dbgdt 63B
ADC12.dbgdt 63B
00.dbgdt 63B
clock_A.dbgdt 63B
clock_A.dbgdt 63B
clock_A.dbgdt 63B
Dot.dbgdt 63B
clock_A.dbgdt 63B
clock_A.dbgdt 63B
clock_A.dbgdt 63B
clock_A.dbgdt 63B
Last Loaded Dot.DBK 215KB
Last Loaded SPI.DBK 143KB
共 443 条
- 1
- 2
- 3
- 4
- 5
aixuedetianshi
- 粉丝: 18
- 资源: 45
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页