假定從8位AD中讀取數據(如果是更高位的AD可定義數據類型為int),子程序為get_ad(); 1、限幅濾波法(又稱程序判斷濾波法) A、方法: 根據經驗判斷,確定兩次采樣允許的最大偏差值(設為A) 每次檢測到新值時判斷: 如果本次值與上次值之差<=A,則本次值有效 如果本次值與上次值之差>A,則本次值無效,放棄本次值,用上次值代替本次值 B、優點: 能有效克服因偶然因素引起的脈沖干擾 C、缺點 無法抑制那種周期性的干擾 平滑度差 /* A值可根據實際情況調整 value為有效值,new_value為當前采樣值 濾波程序返回有效的實際值 */ #define A 10 char value; char filter() { char new_value; new_value = get_ad(); if ( ( new_value - value > A ) || ( value - new_value > A ) return value; return new_value; } 2、中位值濾波法 A、方法: 連續采樣N次(N取奇數) 把N次采樣值按大小排列 取中間值為本次有效值 B、優點: 能有效克服因偶然因素引起的波動干擾 對溫度、液位的變化緩慢的被測參數有良好的濾波效果 C、缺點: 對流量、速度等快速變化的參數不宜 /* N值可根據實際情況調整 排序采用冒泡法*/
上傳時間: 2014-12-26
上傳用戶:nanshan
All inputs of the C16x family have Schmitt-Trigger input characteristics. These Schmitt-Triggers are intended to always provide proper internal low and high levels, even if anundefined voltage level (between TTL-VIL and TTL-VIH) is externally applied to the pin.The hysteresis of these inputs, however, is very small, and can not be properly used in anapplication to suppress signal noise, and to shape slow rising/falling input transitions.Thus, it must be taken care that rising/falling input signals pass the undefined area of theTTL-specification between VIL and VIH with a sufficient rise/fall time, as generally usualand specified for TTL components (e.g. 74LS series: gates 1V/us, clock inputs 20V/us).The effect of the implemented Schmitt-Trigger is that even if the input signal remains inthe undefined area, well defined low/high levels are generated internally. Note that allinput signals are evaluated at specific sample points (depending on the input and theperipheral function connected to it), at that signal transitions are detected if twoconsecutive samples show different levels. Thus, only the current level of an input signalat these sample points is relevant, that means, the necessary rise/fall times of the inputsignal is only dependant on the sample rate, that is the distance in time between twoconsecutive evaluation time points. If an input signal, for instance, is sampled throughsoftware every 10us, it is irrelevant, which input level would be seen between thesamples. Thus, it would be allowable for the signal to take 10us to pass through theundefined area. Due to the sample rate of 10us, it is assured that only one sample canoccur while the signal is within the undefined area, and no incorrect transition will bedetected. For inputs which are connected to a peripheral function, e.g. capture inputs, thesample rate is determined by the clock cycle of the peripheral unit. In the case of theCAPCOM unit this means a sample rate of 400ns @ 20MHz CPU clock. This requiresinput signals to pass through the undefined area within these 400ns in order to avoidmultiple capture events.For input signals, which do not provide the required rise/fall times, external circuitry mustbe used to shape the signal transitions.In the attached diagram, the effect of the sample rate is shown. The numbers 1 to 5 in thediagram represent possible sample points. Waveform a) shows the result if the inputsignal transition time through the undefined TTL-level area is less than the time distancebetween the sample points (sampling at 1, 2, 3, and 4). Waveform b) can be the result ifthe sampling is performed more than once within the undefined area (sampling at 1, 2, 5,3, and 4).Sample points:1. Evaluation of the signal clearly results in a low level2. Either a low or a high level can be sampled here. If low is sampled, no transition willbe detected. If the sample results in a high level, a transition is detected, and anappropriate action (e.g. capture) might take place.3. Evaluation here clearly results in a high level. If the previous sample 2) had alreadydetected a high, there is no change. If the previous sample 2) showed a low, atransition from low to high is detected now.
上傳時間: 2013-10-23
上傳用戶:copu
串行編程器源程序(Keil C語言)//FID=01:AT89C2051系列編程器//實現編程的讀,寫,擦等細節//AT89C2051的特殊處:給XTAL一個脈沖,地址計數加1;P1的引腳排列與AT89C51相反,需要用函數轉換#include <e51pro.h> #define C2051_P3_7 P1_0#define C2051_P1 P0//注意引腳排列相反#define C2051_P3_0 P1_1#define C2051_P3_1 P1_2#define C2051_XTAL P1_4#define C2051_P3_2 P1_5#define C2051_P3_3 P1_6#define C2051_P3_4 P1_7#define C2051_P3_5 P3_5 void InitPro01()//編程前的準備工作{ SetVpp0V(); P0=0xff; P1=0xff; C2051_P3_5=1; C2051_XTAL=0; Delay_ms(20); nAddress=0x0000; SetVpp5V();} void ProOver01()//編程結束后的工作,設置合適的引腳電平{ SetVpp5V(); P0=0xff; P1=0xff; C2051_P3_5=1; C2051_XTAL=1;} BYTE GetData()//從P0口獲得數據{ B_0=P0_7; B_1=P0_6; B_2=P0_5; B_3=P0_4; B_4=P0_3; B_5=P0_2; B_6=P0_1; B_7=P0_0; return B;} void SetData(BYTE DataByte)//轉換并設置P0口的數據{ B=DataByte; P0_0=B_7; P0_1=B_6; P0_2=B_5; P0_3=B_4; P0_4=B_3; P0_5=B_2; P0_6=B_1; P0_7=B_0;} void ReadSign01()//讀特征字{ InitPro01(); Delay_ms(1);//----------------------------------------------------------------------------- //根據器件的DataSheet,設置相應的編程控制信號 C2051_P3_3=0; C2051_P3_4=0; C2051_P3_5=0; C2051_P3_7=0; Delay_ms(20); ComBuf[2]=GetData(); C2051_XTAL=1; C2051_XTAL=0; Delay_us(20); ComBuf[3]=GetData(); ComBuf[4]=0xff;//----------------------------------------------------------------------------- ProOver01();} void Erase01()//擦除器件{ InitPro01();//----------------------------------------------------------------------------- //根據器件的DataSheet,設置相應的編程控制信號 C2051_P3_3=1; C2051_P3_4=0; C2051_P3_5=0; C2051_P3_7=0; Delay_ms(1); SetVpp12V(); Delay_ms(1); C2051_P3_2=0; Delay_ms(10); C2051_P3_2=1; Delay_ms(1);//----------------------------------------------------------------------------- ProOver01();} BOOL Write01(BYTE Data)//寫器件{//----------------------------------------------------------------------------- //根據器件的DataSheet,設置相應的編程控制信號 //寫一個單元 C2051_P3_3=0; C2051_P3_4=1; C2051_P3_5=1; C2051_P3_7=1; SetData(Data); SetVpp12V(); Delay_us(20); C2051_P3_2=0; Delay_us(20); C2051_P3_2=1; Delay_us(20); SetVpp5V(); Delay_us(20); C2051_P3_4=0; Delay_ms(2); nTimeOut=0; P0=0xff; nTimeOut=0; while(!GetData()==Data)//效驗:循環讀,直到讀出與寫入的數相同 { nTimeOut++; if(nTimeOut>1000)//超時了 { return 0; } } C2051_XTAL=1; C2051_XTAL=0;//一個脈沖指向下一個單元//----------------------------------------------------------------------------- return 1;} BYTE Read01()//讀器件{ BYTE Data;//----------------------------------------------------------------------------- //根據器件的DataSheet,設置相應的編程控制信號 //讀一個單元 C2051_P3_3=0; C2051_P3_4=0; C2051_P3_5=1; C2051_P3_7=1; Data=GetData(); C2051_XTAL=1; C2051_XTAL=0;//一個脈沖指向下一個單元//----------------------------------------------------------------------------- return Data;} void Lock01()//寫鎖定位{ InitPro01();//先設置成編程狀態//----------------------------------------------------------------------------- //根據器件的DataSheet,設置相應的編程控制信號 if(ComBuf[2]>=1)//ComBuf[2]為鎖定位 { C2051_P3_3=1; C2051_P3_4=1; C2051_P3_5=1; C2051_P3_7=1; Delay_us(20); SetVpp12V(); Delay_us(20); C2051_P3_2=0; Delay_us(20); C2051_P3_2=1; Delay_us(20); SetVpp5V(); } if(ComBuf[2]>=2) { C2051_P3_3=1; C2051_P3_4=1; C2051_P3_5=0; C2051_P3_7=0; Delay_us(20); SetVpp12V(); Delay_us(20); C2051_P3_2=0; Delay_us(20); C2051_P3_2=1; Delay_us(20); SetVpp5V(); }//----------------------------------------------------------------------------- ProOver01();} void PreparePro01()//設置pw中的函數指針,讓主程序可以調用上面的函數{ pw.fpInitPro=InitPro01; pw.fpReadSign=ReadSign01; pw.fpErase=Erase01; pw.fpWrite=Write01; pw.fpRead=Read01; pw.fpLock=Lock01; pw.fpProOver=ProOver01;}
上傳時間: 2013-11-12
上傳用戶:gut1234567
1、程序的基本格式先介紹二條偽指令:EQU ——標號賦值偽指令ORG ——地址定義偽指令PIC16C5X在RESET后指令計算器PC被置為全“1”,所以PIC16C5X幾種型號芯片的復位地址為:PIC16C54/55:1FFHPIC16C56:3FFHPIC16C57/58:7FFH一般來說,PIC的源程序并沒有要求統一的格式,大家可以根據自己的風格來編寫。但這里我們推薦一種清晰明了的格式TITLE This is ⋯⋯ ;程序標題;--------------------------------------;名稱定義和變量定義;--------------------------------------F0 EQU 0RTCC EQU 1PC EQU 2STATUS EQU 3FSR EQU 4RA EQU 5RB EQU 6RC EQU 7┋PIC16C54 EQU 1FFH ;芯片復位地址PIC16C56 EQU 3FFHPIC16C57 EQU 7FFH;-----------------------------------------ORG PIC16C54 GOTO MAIN ;在復位地址處轉入主程序ORG 0 ;在0000H開始存放程序;-----------------------------------------;子程序區;-----------------------------------------DELAY MOVLW 255┋RETLW 0;------------------------------------------;主程序區;------------------------------------------MAINMOVLW B‘00000000’TRIS RB ;RB已由偽指令定義為6,即B口┋LOOPBSF RB,7 CALL DELAYBCF RB,7 CALL DELAY┋GOTO LOOP;-------------------------------------------END ;程序結束注:MAIN標號一定要處在0頁面內。2、程序設計基礎
上傳時間: 2013-11-14
上傳用戶:cjf0304
C++完美演繹 經典算法 如 /* 頭文件:my_Include.h */ #include <stdio.h> /* 展開C語言的內建函數指令 */ #define PI 3.1415926 /* 宏常量,在稍后章節再詳解 */ #define circle(radius) (PI*radius*radius) /* 宏函數,圓的面積 */ /* 將比較數值大小的函數寫在自編include文件內 */ int show_big_or_small (int a,int b,int c) { int tmp if (a>b) { tmp = a a = b b = tmp } if (b>c) { tmp = b b = c c = tmp } if (a>b) { tmp = a a = b b = tmp } printf("由小至大排序之后的結果:%d %d %d\n", a, b, c) } 程序執行結果: 由小至大排序之后的結果:1 2 3 可將內建函數的include文件展開在自編的include文件中 圓圈的面積是=201.0619264
標簽: my_Include include define 3.141
上傳時間: 2014-01-17
上傳用戶:epson850
mp3設計程序資料,采用c語言編寫。 README file for yampp-3 source code 2001-05-27 This is the current state of the yampp-3 source code, 2001-05-27. This code is intended to run on Rev. B of the yampp-3 PCB, but can ofcourse be used on compatible systems as well. It still uses the "old" song selection system as the yampp-2. However, the disk handling routines has improved a lot and the obviosly, the new VS1001 handling has been put in. The codesize is almost at it s maximum at 1F40 bytes. A .ROM file is included if you don t have the compiler set up. For now, the documentation is in the code
上傳時間: 2015-04-13
上傳用戶:小碼農lz
接收pop3 Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message Dim message, response As String Dim msg As New Pop3Message msg.bytes = rhs.bytes msg.number = rhs.number message = "RETR " + rhs.number.ToString + vbCrLf write(message) response = Respond() If response.Substring(0, 3) <> "+OK" Then Throw New Pop3Exception(response) End If MsgBox(msg) msg.retrieved = True While (1 = 1) response = Respond() If response = "." + vbCrLf Then Exit While Else msg.message += response End If End While Return msg End Function
標簽: Pop3Message Function Retrieve response
上傳時間: 2013-12-28
上傳用戶:fnhhs
DELPHI basicCtrl+NUM 直接將光標跳到NUM處,NUM是用Ctrl+Shift+NUM設置的標號。 NUM不能用小鍵盤。 Ctrl+Home 將光標移至文件頭。 Ctrl+End 將光標移至文件尾。 Ctrl+B Buffer List窗口。 Ctrl+I 同Tab鍵。 Ctrl+M 同Enter鍵。 Ctrl+N 同Enter鍵,但光標位置保持不變。 Ctrl+T 刪除光標右邊的一個單詞。 Ctrl+Y 刪除光標所在行。 Ctrl+Shift+↑ 光標在函數體內時,將光標快速移至當前函數聲明處。 Ctrl+Shift+↓ 光標在函數聲明行時,將光標快速移至函數定義處。 Ctrl+Shift+C 聲明一個過程或函數后,直接生成過程或函數的名稱、begin、end Ctrl+Shift+E 光標在Edit窗口和Explorer窗口間切換。 Ctrl+Shift+G 插入GUID。 Ctrl+Shift+J 彈出Delphi語句提示窗口,選擇所需語句將自動完成一條語句。 Ctrl+Shift+T 在光標行加入To-Do注釋。 Ctrl+Shift+Y 刪除光標之后至本行末尾之間的文本。 Ctrl+F3 Call Stack窗口。 Ctrl+F4 等于File菜單中的Close項。
上傳時間: 2014-11-26
上傳用戶:kr770906
This code detects memory leaks in embedded VC++ almost the same way crtdbg does in VC++. At the end of program execution it will display in the debug window if there were any memory leaks and how the memory looks so you can identify where your memory leak occurred. It will display in the debug window a message saying no memory leaks detected if there are no memory leaks. Similar to what crtdbg.h does in VC++. The code detects memory leaks generated with calls to new and delete operators in C++. The code doesn t detect memory leaks generated with C functions: malloc, calloc, free, but that can be done in the future. Let me know and I will program it.
標簽: the embedded detects almost
上傳時間: 2015-05-07
上傳用戶:comua
人民幣大寫金額轉換程序(修正版v0.0.3) =================================== 1.使用方法: ------------- 將Cash_RMB.dcu放入Delphi安裝目錄下的Lib中,在uses中加入Cash_RMB, 即可引用CashRMB方法. function CashRMB(CashAmount: Double): String 如: procedure TForm1.Button1Click(Sender: TObject) begin QRLabel1.Caption := CashRMB(Table1.FieldByName( 金額 ).AsFloat) end 結果將傳回人民幣金額大寫字符串. 如果 CashAmount = 0 或數值溢出(超出萬億位),結果返回空串. 2.說明: -------- A.本轉換程序最大程度只支持到萬億元(位)的金額數值轉換操作.如果你的 轉換數值超出此極限,你可以在調用前先行判斷數據的合法性,如果沒有作預 先判斷,轉換過程中將引發本單元中自帶的錯誤處理例程. b.該轉換結果符合標準金額大寫書寫格式,零角零分等字樣不存在于最終的 轉換結果中. c.本轉換程序自帶數據溢出等數據非法及轉換錯誤等處理例程. d.本程序適用于32位的Delphi版本.
上傳時間: 2013-12-31
上傳用戶:hebmuljb