主程序,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 * *引脚定义: *MPXV7002DP OUT>PC0(AD0) *DISP DP>PB D1-6>PD2-7 *COM RX>PD0 TX>PD1 *KEY MODE>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 ------------------------------------------------------------*/
enum{ 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};//显示段码表,内容为0-F 全灭unsigned char dis_select[6] = {0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char dis_buf[6];
PROGMEM const unsigned char speed_tab[1024]={ 0,0,2,45,3,47,4,25,4,91,5,49,6,1,6,49, 6,94,7,36,7,76,8,14,8,50,8,85,9,18,9,50, 9,82,10,12,10,41,10,70,10,97,11,24,11,51,11,77, 12,2,12,27,12,51,12,75,12,98,13,21,13,44,13,66, 13,88,14,10,14,31,14,52,14,72,14,93,15,13,15,32, 15,52,15,71,15,90,16,9,16,28,16,46,16,64,16,82, 17,0,17,18,17,35,17,52,17,69,17,86,18,3,18,20, 18,36,18,53,18,69,18,85,19,1,19,17,19,32,19,48, 19,63,19,78,19,94,20,9,20,23,20,38,20,53,20,68, 20,82,20,97,21,11,21,25,21,39,21,53,21,67,21,81, 21,95,22,8,22,22,22,36,22,49,22,62,22,76,22,89, 23,2,23,15,23,28,23,41,23,54,23,66,23,79,23,92, 24,4,24,17,24,29,24,42,24,54,24,66,24,78,24,90, 25,02,25,14,25,26,25,38,25,50,25,62,25,74,25,85, 25,97,26,8,26,20,26,31,26,43,26,54,26,66,26,77, 26,88,26,99,27,10,27,21,27,32,27,43,27,54,27,65, 27,76,27,87,27,98,28,9,28,19,28,30,28,41,28,51, 28,62,28,72,28,83,28,93,29,3,29,14,29,24,29,34, 29,45,29,55,29,65,29,75,29,85,29,95,30,05,30,15, 30,25,30,35,30,45,30,55,30,65,30,75,30,84,30,94, 31,4,31,14,31,23,31,33,31,42,31,52,31,62,31,71, 31,81,31,90,31,99,32,9,32,18,32,28,32,37,32,46, 32,55,32,65,32,74,32,83,32,92,33,01,33,10,33,20, 33,29,33,38,33,47,33,56,33,65,33,73,33,82,33,91, 34,0,34,9,34,18,34,27,34,35,34,44,34,53,34,62, 34,70,34,79,34,88,34,96,35,5,35,13,35,22,35,30, 35,39,35,47,35,56,35,64,35,73,35,81,35,90,35,98, 36,06,36,15,36,23,36,31,36,40,36,48,36,56,36,64, 36,73,36,81,36,89,36,97,37,05,37,13,37,21,37,30, 37,38,37,46,37,54,37,62,37,70,37,78,37,86,37,94, 38,1,38,9,38,17,38,25,38,33,38,41,38,49,38,57, 38,64,38,72,38,80,38,88,38,95,39,3,39,11,39,18, 39,26,39,34,39,41,39,49,39,57,39,64,39,72,39,79, 39,87,39,95,40,02,40,10,40,17,40,25,40,32,40,40, 40,47,40,54,40,62,40,69,40,77,40,84,40,91,40,99, 41,6,41,13,41,21,41,28,41,35,41,43,41,50,41,57, 41,64,41,72,41,79,41,86,41,93,42,0,42,7,42,15, 42,22,42,29,42,36,42,43,42,50,42,57,42,64,42,71, 42,78,42,85,42,92,42,99,43,06,43,13,43,20,43,27, 43,34,43,41,43,48,43,55,43,62,43,69,43,76,43,83, 43,90,43,96,44,3,44,10,44,17,44,24,44,31,44,37, 44,44,44,51,44,58,44,64,44,71,44,78,44,85,44,91, 44,98,45,5,45,11,45,18,45,25,45,31,45,38,45,45, 45,51,45,58,45,64,45,71,45,78,45,84,45,91,45,97, 46,4,46,10,46,17,46,23,46,30,46,36,46,43,46,49, 46,56,46,62,46,69,46,75,46,82,46,88,46,94,47,1, 47,07,47,14,47,20,47,26,47,33,47,39,47,46,47,52, 47,58,47,65,47,71,47,77,47,83,47,90,47,96,48,2, 48,9,48,15,48,21,48,27,48,34,48,40,48,46,48,52, 48,58,48,65,48,71,48,77,48,83,48,89,48,95,49,02, 49,8,49,14,49,20,49,26,49,32,49,38,49,44,49,50, 49,57,49,63,49,69,49,75,49,81,49,87,49,93,49,99, 50,05,50,11,50,17,50,23,50,29,50,35,50,41,50,47, 50,53,50,59,50,65,50,71,50,77,50,82,50,88,50,94, 51,00,51,06,51,12,51,18,51,24,51,30,51,36,51,41, 51,47,51,53,51,59,51,65,51,71,51,76,51,82,51,88, 51,94,52,00,52,05,52,11,52,17,52,23,52,28,52,34, 52,40,52,46,52,51,52,57,52,63,52,69,52,74,52,80, 52,86,52,91,52,97,53,03,53,8,53,14,53,20,53,25, 53,31,53,37,53,42,53,48,53,54,53,59,53,65,53,71, 53,76,53,82,53,87,53,93,53,98,54,04,54,10,54,15, 54,21,54,26,54,32,54,37,54,43,54,48,54,54,54,59, 54,65,54,70,54,76,54,81,54,87,54,92,54,98,55,3, 55,9,55,14,55,20,55,25,55,31,55,36,55,42,55,47
};//速度 2字节数据 第一字节表示整数,第二字节表示小数,单位米每秒
/* * 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 * *引脚定义: *MPXV7002DP OUT>PC0(AD0) *DISP DP>PB D1-6>PD2-7 *COM RX>PD0 TX>PD1 *KEY MODE>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 ------------------------------------------------------------*/
enum{ 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};//显示段码表,内容为0-F 全灭unsigned char dis_select[6] = {0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char dis_buf[6];
PROGMEM const unsigned char speed_tab[1024]={ 0,0,2,45,3,47,4,25,4,91,5,49,6,1,6,49, 6,94,7,36,7,76,8,14,8,50,8,85,9,18,9,50, 9,82,10,12,10,41,10,70,10,97,11,24,11,51,11,77, 12,2,12,27,12,51,12,75,12,98,13,21,13,44,13,66, 13,88,14,10,14,31,14,52,14,72,14,93,15,13,15,32, 15,52,15,71,15,90,16,9,16,28,16,46,16,64,16,82, 17,0,17,18,17,35,17,52,17,69,17,86,18,3,18,20, 18,36,18,53,18,69,18,85,19,1,19,17,19,32,19,48, 19,63,19,78,19,94,20,9,20,23,20,38,20,53,20,68, 20,82,20,97,21,11,21,25,21,39,21,53,21,67,21,81, 21,95,22,8,22,22,22,36,22,49,22,62,22,76,22,89, 23,2,23,15,23,28,23,41,23,54,23,66,23,79,23,92, 24,4,24,17,24,29,24,42,24,54,24,66,24,78,24,90, 25,02,25,14,25,26,25,38,25,50,25,62,25,74,25,85, 25,97,26,8,26,20,26,31,26,43,26,54,26,66,26,77, 26,88,26,99,27,10,27,21,27,32,27,43,27,54,27,65, 27,76,27,87,27,98,28,9,28,19,28,30,28,41,28,51, 28,62,28,72,28,83,28,93,29,3,29,14,29,24,29,34, 29,45,29,55,29,65,29,75,29,85,29,95,30,05,30,15, 30,25,30,35,30,45,30,55,30,65,30,75,30,84,30,94, 31,4,31,14,31,23,31,33,31,42,31,52,31,62,31,71, 31,81,31,90,31,99,32,9,32,18,32,28,32,37,32,46, 32,55,32,65,32,74,32,83,32,92,33,01,33,10,33,20, 33,29,33,38,33,47,33,56,33,65,33,73,33,82,33,91, 34,0,34,9,34,18,34,27,34,35,34,44,34,53,34,62, 34,70,34,79,34,88,34,96,35,5,35,13,35,22,35,30, 35,39,35,47,35,56,35,64,35,73,35,81,35,90,35,98, 36,06,36,15,36,23,36,31,36,40,36,48,36,56,36,64, 36,73,36,81,36,89,36,97,37,05,37,13,37,21,37,30, 37,38,37,46,37,54,37,62,37,70,37,78,37,86,37,94, 38,1,38,9,38,17,38,25,38,33,38,41,38,49,38,57, 38,64,38,72,38,80,38,88,38,95,39,3,39,11,39,18, 39,26,39,34,39,41,39,49,39,57,39,64,39,72,39,79, 39,87,39,95,40,02,40,10,40,17,40,25,40,32,40,40, 40,47,40,54,40,62,40,69,40,77,40,84,40,91,40,99, 41,6,41,13,41,21,41,28,41,35,41,43,41,50,41,57, 41,64,41,72,41,79,41,86,41,93,42,0,42,7,42,15, 42,22,42,29,42,36,42,43,42,50,42,57,42,64,42,71, 42,78,42,85,42,92,42,99,43,06,43,13,43,20,43,27, 43,34,43,41,43,48,43,55,43,62,43,69,43,76,43,83, 43,90,43,96,44,3,44,10,44,17,44,24,44,31,44,37, 44,44,44,51,44,58,44,64,44,71,44,78,44,85,44,91, 44,98,45,5,45,11,45,18,45,25,45,31,45,38,45,45, 45,51,45,58,45,64,45,71,45,78,45,84,45,91,45,97, 46,4,46,10,46,17,46,23,46,30,46,36,46,43,46,49, 46,56,46,62,46,69,46,75,46,82,46,88,46,94,47,1, 47,07,47,14,47,20,47,26,47,33,47,39,47,46,47,52, 47,58,47,65,47,71,47,77,47,83,47,90,47,96,48,2, 48,9,48,15,48,21,48,27,48,34,48,40,48,46,48,52, 48,58,48,65,48,71,48,77,48,83,48,89,48,95,49,02, 49,8,49,14,49,20,49,26,49,32,49,38,49,44,49,50, 49,57,49,63,49,69,49,75,49,81,49,87,49,93,49,99, 50,05,50,11,50,17,50,23,50,29,50,35,50,41,50,47, 50,53,50,59,50,65,50,71,50,77,50,82,50,88,50,94, 51,00,51,06,51,12,51,18,51,24,51,30,51,36,51,41, 51,47,51,53,51,59,51,65,51,71,51,76,51,82,51,88, 51,94,52,00,52,05,52,11,52,17,52,23,52,28,52,34, 52,40,52,46,52,51,52,57,52,63,52,69,52,74,52,80, 52,86,52,91,52,97,53,03,53,8,53,14,53,20,53,25, 53,31,53,37,53,42,53,48,53,54,53,59,53,65,53,71, 53,76,53,82,53,87,53,93,53,98,54,04,54,10,54,15, 54,21,54,26,54,32,54,37,54,43,54,48,54,54,54,59, 54,65,54,70,54,76,54,81,54,87,54,92,54,98,55,3, 55,9,55,14,55,20,55,25,55,31,55,36,55,42,55,47
};//速度 2字节数据 第一字节表示整数,第二字节表示小数,单位米每秒