主程序C文件
/*
* AIR_SPEED.c
*MPXV7002DP +0.36数码管+atmega8
*MPXV7002DP 0点输出2.5V 最大5V 最小0V 模拟量 10位AD转换,量程0.3PSI 2000pa
*p=1/2*1.3*v^2 -> v=(2p/1.3)^0.5
*
*引脚定义:
*MPXV7002DPOUT>PC0(AD0)
*DISPDP>PB D1-6>PD2-7
*COMRX>PD0 TX>PD1
*KEYMODE>PC5 start>PC4
* Created: 2018-10-8 8:23:48
* Author: YUEBO
*/
/* Includes ------------------------------------------------------------------*/
#include <avr/io.h>
#include "mytype.h"
#include <avr/common.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
//#include <math.h>
#include "COMM.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define OUT PORTB
#define DISP PORTD
enum
{
test=0,//测量 不显示
now,//测量同时显示
S_A,//当前最大速度
S_B,//历史最大速度
S_C,//本次飞行距离
S_D,//历史飞行距离
} SM_state;
/* Private macro -------------------------------------------------------------*/
/* Private tab % array -------------------------------------------------------*/
unsigned char dis_tab[17] ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
unsigned char dis_select[6] = {0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char dis_buf[6];
PROGMEM const unsigned char speed_tab[1024]=
{2,45,3,47,4,25,4,90,5,48,6,0,6,49,6,93,
7,35,7,75,8,13,8,49,8,84,9,17,9,49,9,81,
10,11,10,40,10,69,10,96,11,23,11,50,11,76,12,01,
12,26,12,50,12,74,12,97,13,20,13,43,13,65,13,87,
14,8,14,29,14,50,14,71,14,91,15,11,15,31,15,50,
15,70,15,89,16,8,16,26,16,44,16,63,16,81,16,98,
17,16,17,33,17,51,17,68,17,85,18,01,18,18,18,34,
18,51,18,67,18,83,18,99,19,15,19,30,19,46,19,61,
19,76,19,92,20,07,20,22,20,36,20,51,20,66,20,80,
20,95,21,9,21,23,21,37,21,51,21,65,21,79,21,93,
22,6,22,20,22,33,22,47,22,60,22,73,22,87,23,0,
23,13,23,26,23,39,23,51,23,64,23,77,23,89,24,02,
24,14,24,27,24,39,24,51,24,64,24,76,24,88,25,0,
25,12,25,24,25,36,25,48,25,59,25,71,25,83,25,94,
26,06,26,17,26,29,26,40,26,52,26,63,26,74,26,85,
26,97,27,8,27,19,27,30,27,41,27,52,27,63,27,74,
27,84,27,95,28,06,28,17,28,27,28,38,28,48,28,59,
28,69,28,80,28,90,29,01,29,11,29,21,29,32,29,42,
29,52,29,62,29,72,29,82,29,92,30,02,30,12,30,22,
30,32,30,42,30,52,30,62,30,72,30,81,30,91,31,01,
31,11,31,20,31,30,31,39,31,49,31,58,31,68,31,77,
31,87,31,96,32,06,32,15,32,24,32,34,32,43,32,52,
32,61,32,71,32,80,32,89,32,98,33,07,33,16,33,25,
33,34,33,43,33,52,33,61,33,70,33,79,33,88,33,97,
34,06,34,14,34,23,34,32,34,41,34,49,34,58,34,67,
34,76,34,84,34,93,35,01,35,10,35,18,35,27,35,36,
35,44,35,52,35,61,35,69,35,78,35,86,35,95,36,03,
36,11,36,20,36,28,36,36,36,44,36,53,36,61,36,69,
36,77,36,85,36,93,37,02,37,10,37,18,37,26,37,34,
37,42,37,50,37,58,37,66,37,74,37,82,37,90,37,98,
38,06,38,14,38,21,38,29,38,37,38,45,38,53,38,61,
38,68,38,76,38,84,38,92,38,99,39,07,39,15,39,22,
39,30,39,38,39,45,39,53,39,60,39,68,39,76,39,83,
39,91,39,98,40,06,40,13,40,21,40,28,40,36,40,43,
40,50,40,58,40,65,40,73,40,80,40,87,40,95,41,02,
41,9,41,17,41,24,41,31,41,39,41,46,41,53,41,60,
41,67,41,75,41,82,41,89,41,96,42,03,42,11,42,18,
42,25,42,32,42,39,42,46,42,53,42,60,42,67,42,74,
42,81,42,88,42,95,43,02,43,9,43,16,43,23,43,30,
43,37,43,44,43,51,43,58,43,65,43,72,43,78,43,85,
43,92,43,99,44,06,44,13,44,19,44,26,44,33,44,40,
44,47,44,53,44,60,44,67,44,73,44,80,44,87,44,94,
45,0,45,07,45,14,45,20,45,27,45,34,45,40,45,47,
45,53,45,60,45,67,45,73,45,80,45,86,45,93,45,99,
46,06,46,12,46,19,46,25,46,32,46,38,46,45,46,51,
46,58,46,64,46,71,46,77,46,83,46,90,46,96,47,03,
47,9,47,15,47,22,47,28,47,35,47,41,47,47,47,54,
47,60,47,66,47,72,47,79,47,85,47,91,47,98,48,04,
48,10,48,16,48,23,48,29,48,35,48,41,48,47,48,54,
48,60,48,66,48,72,48,78,48,84,48,91,48,97,49,03,
49,9,49,15,49,21,49,27,49,33,49,40,49,46,49,52,
49,58,49,64,49,70,49,76,49,82,49,88,49,94,50,0,
50,06,50,12,50,18,50,24,50,30,50,36,50,42,50,48,
50,54,50,60,50,66,50,72,50,78,50,83,50,89,50,95,
51,01,51,07,51,13,51,19,51,25,51,31,51,36,51,42,
51,48,51,54,51,60,51,66,51,71,51,77,51,83,51,89,
51,95,52,0,52,06,52,12,52,18,52,23,52,29,52,35,
52,41,52,46,52,52,52,58,52,63,52,69,52,75,52,81,
52,86,52,92,52,98,53,03,53,9,53,15,53,20,53,26,
53,32,53,37,53,43,53,48,53,54,53,60,53,65,53,71,
53,76,53,82,53,88,53,93,53,99,54,04,54,10,54,15,
54,21,54,27,54,32,54,38,54,43,54,49,54,54,54,60,
54,65,54,71,54,76,54,82,54,87,54,93,54,98,55,03,
55,9,55,14,55,20,55,25,55,31,55,36,55,42,55,47
};//速度 2字节数据 第一字节表示整数,第二字节表示小数