#include "msp430f4152.h"
#define LCD_ZREO 0XFA//0xf5
#define LCD_ONE 0x60
#define LCD_TWO 0xD6
#define LCD_THREE 0xf4
#define LCD_FOUR 0x6c
#define LCD_FIVE 0xbc
#define LCD_SIX 0xbe
#define LCD_SEVEN 0xe0
#define LCD_EIGHT 0xfe
#define LCD_NINE 0xfc
unsigned char aa[10]={LCD_ZREO ,LCD_ONE ,LCD_TWO ,LCD_THREE , LCD_FOUR ,LCD_FIVE ,LCD_SIX ,LCD_SEVEN, LCD_EIGHT ,LCD_NINE };
unsigned int j,sub,data;
unsigned char i;
void clkinit()
{
FLL_CTL0 &= ~XT1OF;
FLL_CTL0 &= ~XTS_FLL;
FLL_CTL1 &= ~(FLL_DIV0);
FLL_CTL1 &= ~(FLL_DIV1);
}
void Portinit()
{
P1DIR |= 0X00;
P1SEL |= 0X01;
}
void Timer_Ainit()
{
TA0CTL |= TASSEL0 + MC1;
TA0CCR0=0;
TACCTL0 |= SCS + CM1 + CCIS0 + CAP + CCIE;
}
void LCDinit()
{
unsigned char i;
LCDACTL |= LCD4MUX + LCDON + LCDFREQ_128;
LCDAPCTL0 = 0X1F;
LCDAPCTL1 = 0X00;
LCDAVCTL0 |= LCDCPEN;
LCDAVCTL1 |= 0X18;
P5SEL = 0XF0;
for(i=0;i<10;i++)
LCDMEM[i] = 0;
}
void chazhi() //pulse recurrent time) 脉冲周期时间
{
sub = TA0CCR0;
sub = sub - j;
}
void LCDdiaplay()
{
LCDMEM[8] = 0;
LCDMEM[9] = 0;
data = sub%10; //32768
LCDMEM[7] = aa[data];
data = sub/10%10;
LCDMEM[6] = aa[data];
data = sub/100%10;
LCDMEM[5] = aa[data];
data = sub/1000%10;
LCDMEM[4] = aa[data];
data = sub/10000%10;
LCDMEM[3] = aa[data];
LCDMEM[2] = 0;
LCDMEM[1] = 0;
LCDMEM[0] = 0;
}
void testLCD()
{
LCDMEM[0]=0xff;
LCDMEM[1]=0xff;
LCDMEM[2]=0xff;
LCDMEM[3]=0xff;
LCDMEM[4]=0xff;
LCDMEM[5]=0xff;
LCDMEM[6]=0xff;
LCDMEM[7]=0xff;
LCDMEM[8]=0xff;
LCDMEM[9]=0xff;
}
void main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset
clkinit();
Portinit();
Timer_Ainit();
LCDinit();
j=sub=data=0;
testLCD();
_EINT();
while(1)
{
chazhi();
LCDdiaplay();
}
}
#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A1()
{
j =TA0CCR0;
TA0CTL &= ~TAIFG;
}
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A0()
{
j = TA0CCR0;
TACCTL0 &= ~CCIFG;
} |