#include<msp430f149.h>
#include"1602.h"
#include"string.h"
#define uint unsigned int
#define uchar unsigned char
#define NUM 16
char table1[]="width(us)";
uint new_cap=0,old_cap=0;
char N1;
long diff[NUM];
char index=0;
long data;
uchar table[]={'0','1','2','3','4','5','6','7','8','9'};
//char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
//0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//char position[]={0x20,0x10,0x08,0x04,0x02,0x01};
char led_buf[]={0,0,0,0,0,0};
void data_to_buf(long data1)
{
char i;
for(i=0;i<6;i++)
{
led_buf[i]=data1%10;
data1=data1/10;
}
}
void main()
{
int i,num;
WDTCTL=WDTPW+WDTHOLD;
init();
//P4DIR=0xff;
//P5DIR=0xff;
P1SEL|=0x02;
TACTL=TASSEL_2+MC_2+TAIE;
BCSCTL2|=SELS;
BCSCTL2=DIVS0+DIVS1;
TACCTL0=CM_1+CCIS_0+SCS+CAP+CCIE;
//TACCR0=20000;
_EINT();
write_com(0x80);
for(num=0;num<9;num++)
{
write_data(table1[num]);
}
while(1){
if(index==0)
{
data=0;
for(i=1;i<NUM;i++)
{
data+=diff[i];
}
data=data/15;
//write_com(0x01);
}
data_to_buf(data);
//isp();
write_com(0x80+0x40);
for(i=5;i>=0;i--)
{
write_data(table[led_buf[i]]);
}
}
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0(void)
{
new_cap=TACCR0;
diff[index]=65536*N1+new_cap-old_cap;
TACCTL0=CM_1+SCS+CAP+CCIE;
index++;
if(index==NUM)
{
index=0;
}
old_cap=new_cap;
N1=0;
}
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
{
switch(TAIV)
{
case 2:break;
case 4:break;
case 10:N1++;
break;
}
}
此帖出自
小平头技术问答
谢谢 我再看看
一周热门 更多>