新人求助。让数码管显示0-99
时间:10-02
整理:3721RD
点击:
帮忙看看代码哪里错了?
#include <msp430x14x.h>
typedef unsigned char uchar;
//数码管7位段码:0--f
uchar scandata[16] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//记录显示位数的全局变量
uchar counter,a[2];
uchar refresh_led(void);
/********************主函数********************/
void main(void)
{
/*下面六行程序关闭所有的IO口*/
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
WDTCTL = WDT_ADLY_1000; // 设置内部看门狗工作在定时器模式,1000ms中断一次
IE1 |= WDTIE; // 使能看门狗中断
P4DIR = 0xff; //设置P4,P5的IO方向为输出
P5DIR = 0xff;
P4OUT = 0xff; //设置P4,P5的输出初值
P5OUT = 0xff;
_BIS_SR(LPM3_bits + GIE); //CPU进入LPM3低功耗模式,同时打开全局中断
}
uchar refresh_led(){
static uchar j = 0;
switch(j)
{
case 0:P4OUT = 0xfc; j++;P5OUT = scandata[a[0]];break;
case 1:P4OUT = 0xfc; j=0;P5OUT = scandata[a[1]];break;
default: break;
}
}
/*******************************************
函数名称:watchdog_timer
功 能:看门狗中断服务函数,在这里输出数码管的
段选和位选信号
参 数:无
返回值 :无
********************************************/
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
static uchar sec = 0;
sec++;
a[0] = sec%10;
a[1] = sec/10;
if(sec == 100)
{
sec = 0;
}
refresh_led();
}
#include <msp430x14x.h>
typedef unsigned char uchar;
//数码管7位段码:0--f
uchar scandata[16] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//记录显示位数的全局变量
uchar counter,a[2];
uchar refresh_led(void);
/********************主函数********************/
void main(void)
{
/*下面六行程序关闭所有的IO口*/
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
WDTCTL = WDT_ADLY_1000; // 设置内部看门狗工作在定时器模式,1000ms中断一次
IE1 |= WDTIE; // 使能看门狗中断
P4DIR = 0xff; //设置P4,P5的IO方向为输出
P5DIR = 0xff;
P4OUT = 0xff; //设置P4,P5的输出初值
P5OUT = 0xff;
_BIS_SR(LPM3_bits + GIE); //CPU进入LPM3低功耗模式,同时打开全局中断
}
uchar refresh_led(){
static uchar j = 0;
switch(j)
{
case 0:P4OUT = 0xfc; j++;P5OUT = scandata[a[0]];break;
case 1:P4OUT = 0xfc; j=0;P5OUT = scandata[a[1]];break;
default: break;
}
}
/*******************************************
函数名称:watchdog_timer
功 能:看门狗中断服务函数,在这里输出数码管的
段选和位选信号
参 数:无
返回值 :无
********************************************/
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
static uchar sec = 0;
sec++;
a[0] = sec%10;
a[1] = sec/10;
if(sec == 100)
{
sec = 0;
}
refresh_led();
}