void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
LCDACTL = LCDON + LCD4MUX + LCDFREQ_128; // 4mux LCD, ACLK/128
LCDAPCTL0 = 0x0F; // Segments 0-13
P5SEL = 0x1C; // Set COM pins for LCD
for( n = 0; n <20 ; n ++)
{
LCDMEM[n] = 0; // Clear LCD
}
index=0;
num=0;
P1DIR |= 0x01; // Set P1.0 as output
BTCTL = BTDIV + BT_fCLK2_DIV16; // ACLK/(256*16)
IE2 |= BTIE; // Enable BT interrupt
while(1)
{
SD16CTL = SD16REFON+SD16SSEL1; // 1.2V ref, SMCLK
SD16CCTL0 |= SD16SNGL; // Single conv
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
SD16CCTL0 |= SD16SC; // Set bit to start conversion
while ((SD16CCTL0 & SD16IFG)==0); // Poll interrupt flag
result = SD16MEM0;
if (++index == 10)
{
index = 0; // SET BREAKPOINT HERE
}
_NOP();
SD16CTL=0x00;
IE2=0x80;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
}
}
// Basic Timer Interrupt Service Routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer_ISR(void)
{
P1OUT ^= 0x01; // Toggle P1.0
num=num+1;
if(num>10)
{
num=0;
lcd();
for (i = 0; i < 0x9000; i++); // Delay
_BIC_SR_IRQ(LPM3_bits);
IE2=0x00;
}
}
//******************************************************************************
//******************************************************************************
#include <msp430x42x0.h>
// LCD segment definitions.
#define d 0x80
#define e 0x40
#define g 0x20
#define f 0x10
#define h 0x08
#define c 0x04
#define a 0x01
#define b 0x02
const char char_gen[] = { // definitions for digits
a+b+c+d+e+f, // Displays "0"
b+c,
a+b+g+e+d, // Displays "1"
a+b+d+c+g, // Displays "2"
b+c+f+g, // Displays "3"
a+f+g+c+d+h, // Displays "4"
a+f+e+d+c+g, // Displays "5"
a+b+c, // Displays "6"
a+b+c+d+e+f+g, // Displays "7"
a+b+c+d+f+g // Displays "9"
};
unsigned int num=0;
volatile unsigned int i; // Use volatile to prevent removal
unsigned int result; // by compiler optimization
unsigned int index;
unsigned char dis_buf[5];
unsigned char n;
void lcd()
{
dis_buf[0]=result/10000%10;
dis_buf[1]=result/1000%10;
dis_buf[2]=result/100%10;
dis_buf[3]=result/10%10;
dis_buf[4]=result%10;
for (n=0; n<5; ++n) // Display "0123456"
LCDMEM[n] = char_gen[dis_buf[n]];
}
//******************************************************************************
//******************************************************************************
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
LCDACTL = LCDON + LCD4MUX + LCDFREQ_128; // 4mux LCD, ACLK/128
LCDAPCTL0 = 0x0F; // Segments 0-13
P5SEL = 0x1C; // Set COM pins for LCD
for( n = 0; n <20 ; n ++)
{
LCDMEM[n] = 0; // Clear LCD
}
index=0;
num=0;
P1DIR |= 0x01; // Set P1.0 as output
BTCTL = BTDIV + BT_fCLK2_DIV16; // ACLK/(256*16)
IE2 |= BTIE; // Enable BT interrupt
while(1)
{
SD16CTL = SD16REFON+SD16SSEL1; // 1.2V ref, SMCLK
SD16CCTL0 |= SD16SNGL; // Single conv
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
SD16CCTL0 |= SD16SC; // Set bit to start conversion
while ((SD16CCTL0 & SD16IFG)==0); // Poll interrupt flag
result = SD16MEM0;
if (++index == 10)
{
index = 0; // SET BREAKPOINT HERE
}
_NOP();
SD16CTL=0x00;
IE2=0x80;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
}
}
// Basic Timer Interrupt Service Routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer_ISR(void)
{
P1OUT ^= 0x01; // Toggle P1.0
num=num+1;
if(num>10)
{
num=0;
lcd();
for (i = 0; i < 0x9000; i++); // Delay
_BIC_SR_IRQ(LPM3_bits);
IE2=0x00;
}
}
一周热门 更多>