⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adsbin.c

📁 ADS-B接收机DIY全套资料
💻 C
📖 第 1 页 / 共 3 页
字号:
/*********************************************************************
 * FileName:        adsbin.c
 * Dependencies:    See INCLUDES section below
 * Processor:       PIC18
 * Compiler:        C18 2.30.01+
 * Company:         sprut
 * Copyright:       2007-2010 Joerg Bredendiek (sprut)
 *
 *
 ********************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */



/** I N C L U D E S **********************************************************/
#include <p18cxxx.h>
#include <usart.h>
#include "system\typedefs.h"
#include "system\usb\usb.h"
#include "io_cfg.h"             // I/O pin mapping

#include "delays.h"
//#include "system\interrupt\interrupt.h"
#include "user\user.h"
#include "user\adsbin.h"


/** V A R I A B L E S ********************************************************/
#pragma udata


/** D E C L A R A T I O N S **************************************************/
#pragma code


// AAA0 ... AAA6 ...AAA11 ... AAA13

// Warten und finden eines Datenblocks
// wenn er gefunden wird, dann 
//		Einschreiben in adsb[0..13]
//		56Bit:Lang=0 / 112Bit:Lang=1
//		Rueckkehr  mit w=0
// wenn er NICHT gefunden wird, dann 
//		Rueckkehr  mit w=1
// Anzahl der Suchschleifen: adsbLoopH-adsbLoopL
// 25600 Schleifen in 15 ms => 0.6 us pro Schleife ~ 7 Befehle
//
// das ist eine der unelegantesten routinen die denkbar ist
// aber sie funktioniert
// never touch a running system!
char adsb_in(void)
{
	_asm
	BCF		INTCON, GIEH, A
	BCF		PORTC, 1, A				// HDR_OUT
	BRA		Start_Hdr


// Fehler im Datenblock
Error_Data:
// Einstieg: 
// Fehler im Header
Error_Hdr:
	DECFSZ	adsbLoopL, F, 1		// 255 erfolglose Leseversuche, outer loop
	BRA		Start_Hdr			// neuer Versuch		kurze Schleife: 7 Zyklen = 0.5833 us
	DECFSZ	adsbLoopH, F, 1
	BRA		Start_Hdr			// neuer Versuch		lange Schleife: 9 Zyklen = 0.75 us,  Durchschnitt = 0.58398 us
	BSF		INTCON, GIEH, A
	MOVLW	1					// true,  Fehler, nichts empfangen
	RETURN	0			



// Einlesen : ist das ein Header  ?
Start_Hdr:
	BTFSC	PORTC, 0, A		// 1
	BTFSS	PORTC, 0, A		// 0,166 us lang 
	BRA		Error_Hdr	
	NOP	
	NOP	
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSC	PORTC, 0, A		// 1
	BTFSS	PORTC, 0, A
	BRA		_Skip_Pulse		// es wurde erst der 2. Puls gefunden, deshalb vorspringen	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP		

	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
_Skip_Pulse:
    // ab hier kann man auch die TOA bestimmen
	movf	TMR0L,W,A		//NOP		0xFD6 RAM location in Access RAM (BSR register is ignored)
	movwf	Time0,1			//NOP		RAM bank is specified by BSR register
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	movf	TMR0H,W,A		//NOP		0xFD7 RAM location in Access RAM (BSR register is ignored)
	movwf	Time1,1			//NOP		RAM bank is specified by BSR register
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSC	PORTC, 0, A		// 1
	BTFSS	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP
		
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSC	PORTC, 0, A		// 1
	BTFSS	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	NOP		
	NOP	
	
	BTFSS	PORTC, 0, A		// 0
	BTFSC	PORTC, 0, A
	BRA		Error_Hdr	
	NOP		
	BCF		PORTC, 2, A		// altes frame nun ungueltig
	BSF		PORTC, 1, A

// es folgt der Datenblock
// 5 Bit Format-Number
//Lang = 0
// DF00		00000	56 bit
// DF04		00100	56 bit
// DF05		00101	56 bit
// DF11		01011	56 bit
// Lang = 1
// DF16		10000	112 bit
// DF17		10001	112 bit
// DF19		10011	112 bit
// DF20		10100	112 bit
// DF21		10101	112 bit
// DF22		10110	112 bit
// DF24		11000	112 bit
//
// das erste Bit unterscheidet zwischen 56 und 112 bit

	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	CLRF	Lang, 1					// 56 oder 112 bit noch unbekannt
	BTFSC	AAA0, 0, 1				// Test 56 oder 112 Bit ?
	INCF	Lang, F, 1				// 112 Bit : Lang = 1	
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BZ	Error_Data					// Fehler im Datenblock
	NOP		
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT02_ok	
	BRA	Error_Data	
BIT02_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT03_ok	
	BRA	Error_Data	
BIT03_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT04_ok	
	BRA	Error_Data	
BIT04_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT05_ok	
	BRA	Error_Data	
BIT05_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT06_ok	
	BRA	Error_Data	
BIT06_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT07_ok	
	BRA	Error_Data	
BIT07_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA0, F, 1
	NOP		
	NOP		
	NOP		
	BSF	ADCON0, 1, A
	MOVF	PORTC, W, A
	XORWF	AAA0, W, 1
	ANDLW	0x01	
	BNZ		BIT08_ok	
	BRA	Error_Data	
BIT08_ok:
	NOP		

// byte 2
	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT09_ok	
	BRA	Error_Data	
BIT09_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT10_ok	
	BRA	Error_Data	
BIT10_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT11_ok	
	BRA	Error_Data	
BIT11_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT12_ok	
	BRA	Error_Data	
BIT12_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT13_ok	
	BRA	Error_Data	
BIT13_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT14_ok	
	BRA	Error_Data	
BIT14_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT15_ok	
	BRA	Error_Data	
BIT15_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA1, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA1, W, 1
	ANDLW	0x01	
	BNZ		BIT16_ok	
	BRA	Error_Data	
BIT16_ok:
	NOP	

// byte 3	
	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT17_ok	
	BRA	Error_Data	
BIT17_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT18_ok	
	BRA	Error_Data	
BIT18_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT19_ok	
	BRA	Error_Data	
BIT19_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT20_ok	
	BRA	Error_Data	
BIT20_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT21_ok	
	BRA	Error_Data	
BIT21_ok:
	NOP	
	
	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT22_ok	
	BRA	Error_Data	
BIT22_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT23_ok	
	BRA	Error_Data	
BIT23_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA2, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA2, W, 1
	ANDLW	0x01	
	BNZ		BIT24_ok	
	BRA	Error_Data	
BIT24_ok:
	NOP		

//byte 4
	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT25_ok	
	BRA	Error_Data	
BIT25_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT26_ok	
	BRA	Error_Data	
BIT26_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT27_ok	
	BRA	Error_Data	
BIT27_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT28_ok	
	BRA	Error_Data	
BIT28_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT29_ok	
	BRA	Error_Data	
BIT29_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT30_ok	
	BRA	Error_Data	
BIT30_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT31_ok	
	BRA	Error_Data	
BIT31_ok:
	NOP		

	RRCF	PORTC, W, A
	RLCF	AAA3, F, 1
	NOP		
	NOP		
	NOP		
	NOP		
	MOVF	PORTC, W, A
	XORWF	AAA3, W, 1
	ANDLW	0x01	
	BNZ		BIT32_ok	
	BRA	Error_Data	
BIT32_ok:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -