|
楼主 |
发表于 2011-8-5 23:57:09
|
显示全部楼层
回复【6楼】yisea123
-----------------------------------------------------------------------
有道理,我也是如此操作了,但是显示出来不对,麻烦帮忙看看程序
#include <iom128v.h>
#include <macros.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
#include"Display.c"
void init(void);
uint count=0;
ulong speed=0;
float time=0;
uint time1=0;
float time2=0;
const uchar temp[]={"speed: r/s"};
uchar table[6]={0,0,0,0,0,0};
void init(void)
{
DDRA=0xFF;
PORTA=0XFF;
DDRD=0XF0;
PORTD=0XFF;//带上拉输入
SREG|=BIT(7); //开全局中断
EIMSK=0x01; //开外部中断0
EICRA=0x02;//外部中断0
TCCR1B=0x04;//256分频
TCNT1H=0;
TCNT1L=0;
}
void main(void)
{
uint i;
LCD_init();
LCD_String(0,0,temp);
init();
while (1)
{
Write_Add(3,0);
Write_Num(table[0]);
Write_Num(table[1]);
Write_Num(table[2]);
Write_Num(table[3]);
Write_Num(table[4]);
Write_Num(table[5]);
}
}
#pragma interrupt_handler ext_int0_isr:2 //指定外部中断函数
void ext_int0_isr(void)
{
TIMSK=0;//关中断
time1=(256*TCNT1H+TCNT1L);
time2=time1*0.000032;
time=2.097*count+time2;
speed=(1/time);
table[0]=speed/10000;
table[1]=speed%10000/1000;
table[2]=speed%10000/1000;
table[3]=speed%1000/100;
table[4]=speed%100/10;
table[5]=speed%10;
count=0;
TCNT1H=0;
TCNT1L=0;
TIMSK|=BIT(2);//开中断
}
#pragma interrupt_handler BBB:15
void BBB(void)
{
count++;
} |
|