thanh xuân
Ban Chủ Nhiệm
Code:
#include <msp430.h>
unsigned int dau=0,i=0;
unsigned int a[]={0,0,0,0};
void setup_timer(){
TA0CTL=TASSEL_2+ID_3+MC_2+TAIE;
TA0CCTL0 = CM_3 + CCIS_0 + CAP + CCIE+ SCS;
}
void setup_port(){
// CCI1A -> P1.1 (datasheet)
P1SEL |= BIT1;
P1SEL2 &= ~BIT1;
P1DIR &= ~BIT1;
// Chon tro keo len
P1REN |= BIT1;
P1OUT |= BIT1;
P2SEL=0;
P2SEL2=0;
P2DIR=0xff;
P2OUT=0;
}
void main(void) {
int j=0,a1,a2,a3,a4,temp;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
setup_port();
setup_timer();
while(1){
if (j<i){
j +=1;
temp=a[j];
a1=temp % 10;
temp /=10;
a2=temp % 10;
temp /=10;
a3=temp % 10;
temp /=10;
a4=temp % 10;
temp /=10;
P2OUT=temp | BIT7;
__delay_cycles(500000);
P2OUT=a4 | BIT7;
__delay_cycles(500000);
P2OUT=a3 | BIT7;
__delay_cycles(500000);
P2OUT=a2 | BIT7;
__delay_cycles(500000);
P2OUT=a1 | BIT7;
__delay_cycles(500000);
}
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void timer0_a0_isr(){
i +=1;
a[i]=TA0CCR0-dau;
dau=TA0CCR0;
}