Код: Выделить всё
#include "io430.h"
#include "stdarg.h"
int N1=BIT0;
int N2=BIT1;
int N3=BIT2;
int N4=BIT3;
#define a BIT7
#define b BIT1
#define c BIT2
#define d BIT3
#define e BIT4
#define f BIT5
#define g BIT6
int n1 = b+c;
int n2 = a+b+g+e+d;
int n3 = a+b+c+d+g;
int n4 = f+g+b+c;
int n5 = a+f+g+c+d;
int n6= f+e+d+c+g;
int n7 = a+b+c;
int n8 = a+b+c+d+e+f+g;
int n9 = a+b+c+f+g;
int n0=a+b+c+d+e+f;
volatile unsigned int CounterValue = 0;
volatile unsigned int StoredCount = 0;
unsigned int Result = 0;
void digit (int position, int values);
void clear(void);
int main( void )
{
P1DIR = (BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
P2DIR = (BIT0+BIT1+BIT2+BIT3);
P2OUT |= N1+N2+N3+N4;
P1OUT |= (BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
/*** Watchdog timer and clock Set-Up ***/
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation
/*** GPIO Set-Up ***/
P1DIR &= ~BIT0; // P1.0 set as input
P1SEL |= BIT0; // P1.0 set to primary peripheral Timer1_A
/*** Timer_A Set-Up ***/
TA0CCR0 = 20000; // 20000*400 = 8000000 or 8MHz
TA0CCTL0 |= CCIE; // Interrupt enable
TA0CTL |= TASSEL_2; // SMCLK
TA1CCTL0 |= CCIE + CCIS_0 + CM_2 + CAP; // Interrupt enable, capture select CCIxA, Positive edge, capture mode
TA1CTL |= TASSEL_2; // SMCLK
__low_power_mode_0();
for(;;){
TA0CTL |= MC0; // Start timer
TA1CTL |= MC1; // Start timer
while(CounterValue != 400); // Wait while CounterValue is not equal to 400
TA0CTL &= ~MC0; // Stop timer
TA1CTL &= ~MC1; // Stop timer
Result = StoredCount; // Store frequency in Result
CounterValue = 0; // Zero CounterValue
StoredCount = 0; // Zero StoredCount
TA0R = 0; // Zero Timer_A0 register
TA1R = 0; // Zero Timer_A1 register
for (int i=0; i<4; i++){
digit(i+1, Result%10);
Result/=10;
}
}
return 0;
}
void digit (int position, int values){
P2OUT |= N1+N2+N3+N4;
switch(position)
{
case 1:
P2OUT &= ~N1;
break;
case 2:
P2OUT &= ~N2;
break;
case 3:
P2OUT &= ~N3;
break;
case 4:
P2OUT &= ~N4;
break;
}
P1OUT |= (BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
switch (values)
{
case 0:
P1OUT &= ~n0;
break;
case 1:
P1OUT &= ~n1;
break;
case 2:
P1OUT &= ~n2;
break;
case 3:
P1OUT &= ~n3;
break;
case 4:
P1OUT &= ~n4;
break;
case 5:
P1OUT &= ~n5;
break;
case 6:
P1OUT &= ~n6;
break;
case 7:
P1OUT &= ~n7;
break;
case 8:
P1OUT &= ~n8;
break;
case 9:
P1OUT &= ~n9;
break;
}
}
void clear(void){
P2OUT |= N1+N2+N3+N4;
P1OUT |= (BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
__delay_cycles(500);
}
//Timer_A0 TACCR0 Interrupt Vector Handler Routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void)
{
CounterValue++;
}
//Timer_A1 TACCR0 Interrupt Vector Handler Routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer1_A0(void)
{
StoredCount++;
}