#include<msp430g2553.h>
#include <stdio.h>
int count=0;
int LED[4];
long fre;
//频率部分
unsigned char LED_0F[] =
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf};
// 0 1 2 3 4 5 6 7 8 9 A b C d E F -
/*************延时函数************/
void delay(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
//1s延时的计数闸门
void delay1(void)
{
unsigned long i;
for(i=0;i<119000;i++)
{
_NOP(); // 该函数用来产生一个 MSP430 系统时钟周期的延时
}
}
/*************430初始化函数************/
void LED_OUT(char X)
{
char i;
for(i=8;i>=1;i--)
{
if (X&0x80) P2OUT |= 0x01; else P2OUT &= ~0x01;
X<<=1;
P2OUT &= ~0x04;
P2OUT |= 0x04; // SCK 上升沿操作 数据写入寄出去
}
}
void display(void)
{ // 声明计数数据变量
unsigned char *led;
char i;
led=LED_0F+LED[0];
i=*led;
LED_OUT(i); // 段选
LED_OUT(0x01); // 位选
P2OUT &= ~0x02;
P2OUT |= 0x02; // RCK上升沿操作 寄出去输出到数码
led=LED_0F+LED[1];
i=*led;
LED_OUT(i); // 段选
LED_OUT(0x02); // 位选
P2OUT &= ~0x02;
P2OUT |= 0x02; // RCK上升沿操作 寄出去输出到数码
led=LED_0F+LED[2];
i=*led;
LED_OUT(i); // 段选
LED_OUT(0x04); // 位选
P2OUT &= ~0x02;
P2OUT |= 0x02; // RCK上升沿操作 寄出去输出到数码
led=LED_0F+LED[3];
i=*led;
LED_OUT(i); // 段选
LED_OUT(0x08); // 位选
P2OUT &= ~0x02;
P2OUT |= 0x02; // RCK上升沿操作 寄出去输出到数码
}
/*************主函数************/
void init(void)
{
//Time0初始化
TA1CTL = TASSEL_1 + MC_1 + TAIE;
TA1CCTL0 = CCIE;
TA1CCR0 = 32768;
//Time1初始化
TA0CCTL1 = CM_1 + CCIS_0 + CAP + CCIE;
P1DIR &= ~BIT2;//p2.0output others input
P1SEL |= BIT2;
_EINT();
}
void main(void)
{
WDTCTL=WDTPW+WDTHOLD; // 关闭看门狗
P2DIR =BIT0+BIT1+BIT2;
P1DIR=BIT6;
init();
LED[0]=0; //
LED[1]=0;
LED[2]=0;
LED[3]=0;
while(1)
{
display();
}
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer1(void)
{
_DINT();
fre=count;
count=0;
if(fre>=10000)
{
LED[0]=fre/10000;
LED[1]=fre%10000/1000;
LED[2]=fre%10000%1000/100;
LED[3]=10;
}
else
{
LED[0]=fre/1000;
LED[1]=fre%1000/100;
LED[2]=fre%1000%100/10;
LED[3]=fre%1000%100%10;
}
P1OUT ^= BIT6;
_EINT();
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer0(void)
{
_DINT();
switch(TAIV)//向量查询
{
case 2:count++; //捕获中断
break;//CCR1
case 4:break;//CCR2
case 10:
break;
}
_EINT();
}
|