MSP430数码管的使用Ⅰ
扫描二维码
随时随地手机看文章
首先应该了解数码管及其工作原理。了解你使用的是共阴还是共阳数码管,其次了解数码管的段选位选。
接下来是一个例程
#include
typedef unsigned char uchar;
#define wei_h P5OUT |= BIT5
#define wei_l P5OUT &= BIT5
#define duan_l P6OUT &= ~BIT6
#define duan_h P6OUT |= BIT6
uchar table[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar num = 0;
void main( void )
{
P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDT_ADLY_1_9;
IE1 |= WDTIE;
P6DIR |= BIT2;P6OUT |= BIT2;
P5DIR = 0XFF;
P4DIR = 0XFF;
P5OUT = 0X00;
P4OUT = 0XFF;
_BIS_SR(LPM3_bits + GIE);
}
#pragma vector = WDT_VECTOR
__interrupt void watchdog_timer(void)
{
P4OUT = table[num];
duan_h;
duan_l;
P4OUT = ~(1 << num);
wei_h;
wei_l;
num++;
if(num == 8)
num = 0;
}
MSP430的输出方向的设置非常重要。切勿忘记。