51单片机PPM波的测试设计.doc

上传人:白大夫 文档编号:3244760 上传时间:2019-08-05 格式:DOC 页数:7 大小:30.50KB
返回 下载 相关 举报
51单片机PPM波的测试设计.doc_第1页
第1页 / 共7页
亲,该文档总共7页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《51单片机PPM波的测试设计.doc》由会员分享,可在线阅读,更多相关《51单片机PPM波的测试设计.doc(7页珍藏版)》请在三一文库上搜索。

1、51单片机PPM波的测试设计先说说PPM波,从图上可以看出周期为20ms,冠丽控实际是6通控,但预留两通没有使用。通道的高电平区间为0.7651.6ms 低电平时间为0.395ms引导波形的高电平 时间为10.165ms。我的单片机是 11.0592MHZ 这样算的话, 显示的值 应该是 706 到 1491 之间,中立位为 1100正好和理论值相符。这里在提点单片机相关的知识,51单片机是低电平触 发中断,我这里用的是while(int0=0)来等待高电平 的到来。不知道这样做是否合理,不过实践看来还是可以的。明说一点,程序中 LCD* 都在1602.h文件中,自己加个1602的头文件即可。

2、下面是程序的主要部分#include#include “1602.h”unsigned char channel=0,i=0;unsigned int xdata PPM_channel110,PPM_channel210,PPM_channel310,PPM_channel410,PPM_channel510,PPM_channel610;bit Timer0_OverFlowFlag=0;/定时器0的溢出标志,如果溢出,则有问题;unsigned char qian,bai,shi,ge;void DepartNum(unsigned int temp) ;unsigned int fil

3、ter(unsigned int *s); /这不函数的作用?void delay(unsigned int k)unsigned int i,j;for(i=0;ifor(j=0;j121;j+);void main(void)unsigned char *IniTIform;unsigned int temp;IniTIform=“PPM Decoding”;delay(500);LCD_init(8); /在1602.h中LCD_Write_String(3,0,IniTIform); /在1602.h中delay(800);TMOD=0x01; /TImer0 方式1ET0=1; /允

4、许timer0中断/初始化INT0IT0=1; /负跳变触发中断;EX0=1;/外中断 0中断允许EA=1; /总中断/ DelayMs(10000);while(1)temp=filter(PPM_channel1);/数组DepartNum(temp);LCD_Write_Char(0,0, ); /在1602.h中LCD_Write_Char(1,0,qian);LCD_Write_Char(2,0,bai);LCD_Write_Char(3,0,shi);LCD_Write_Char(4,0,ge);temp=filter(PPM_channel2);DepartNum(temp);L

5、CD_Write_Char(5,0, );LCD_Write_Char(6,0,qian);LCD_Write_Char(7,0,bai);LCD_Write_Char(8,0,shi);LCD_Write_Char(9,0,ge);temp=filter(PPM_channel3);DepartNum(temp);LCD_Write_Char(10,0, );LCD_Write_Char(11,0,qian);LCD_Write_Char(12,0,bai);LCD_Write_Char(13,0,shi);LCD_Write_Char(14,0,ge);temp=filter(PPM_ch

6、annel4);DepartNum(temp);LCD_Write_Char(0,1, );LCD_Write_Char(1,1,qian);LCD_Write_Char(2,1,bai);LCD_Write_Char(3,1,shi);LCD_Write_Char(4,1,ge);temp=filter(PPM_channel5);DepartNum(temp);LCD_Write_Char(5,1, );LCD_Write_Char(6,1,qian);LCD_Write_Char(7,1,bai);LCD_Write_Char(8,1,shi);LCD_Write_Char(9,1,ge

7、);temp=filter(PPM_channel6);DepartNum(temp);LCD_Write_Char(10,1, );LCD_Write_Char(11,1,qian);LCD_Write_Char(12,1,bai);LCD_Write_Char(13,1,shi);LCD_Write_Char(14,1,ge);/*用于显示的数位分解函数,把数据转化为ASCII码入口参数是要显示的数据*/void DepartNum(unsigned int temp)qian=temp/1000+0x30;bai=temp%1000/100+0x30;shi=temp%100/10+0x

8、30;ge= temp%10+0x30;void ISIR_INT0(void) interrupt 0 /interrupt 0 指明是外部中断0; 主要在中断函数这一块。unsigned int PPM_temp=0;if(TR0)TR0=0;/停止计数; /TR0置1时,T1开始工作;TR0置0时,T1停止工作PPM_temp=TH0;PPM_temp=(PPM_temp8)“TL0;while(INT0=0); /等待到高电平TH0=0;TL0=0;TR0=1;/给TH0和TL0赋初值后重新启动定时器elsewhile(INT0=0); /等待到高电平TH0=0;/如果是第一次启动中断

9、,则启动timer0TL0=0;TR0=1; /启动计时器if(PPM_temp3000| Timer0_OverFlowFlag)/判断引导区channel=0;Timer0_OverFlowFlag=0;i+;if(i=10) i=0;switch(channel) /当第一次启动里,channel的值为0 ;case 1: PPM_channel1i=PPM_temp; break;case 2: PPM_channel2i=PPM_temp; break;case 3: PPM_channel3i=PPM_temp; break;case 4: PPM_channel4i=PPM_te

10、mp; break;case 5: PPM_channel5i=PPM_temp; break;case 6: PPM_channel6i=PPM_temp; break;case 7: break;case 8: break;default:break;channel+;void ISIR_Timer0(void) interrupt 1 /interrupt 1 指明是定时器中断0;Timer0_OverFlowFlag=1; /timer0最大值是65536us,理论上不会溢出,如果溢出则出错,重新从通道1开始unsigned int filter(unsigned int *s) /这个函数是先排序后进行求平均值 (直接求平均值即可)。unsigned char k,j;unsigned int sum=0;/*unsigned int temp;for(k=0;k9;k+)for(j=k+1;j10;j+)if(sksj)temp=sk;sk=sj;sj=temp;*/到这里是形成一个从小到在的数组for(k=1;k9;k+)/这里既然求平均值 ,为何还要排列大小 呢?sum+=sk;/我觉得这个方法完全没有必要。sum=sum/8;return sum;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1