📄 an_008.asm
字号:
;*****************************************************************************
; APPLICATION NOTE AN008
; Oversampling and data decision for the CC400/CC900
;
; File : AN_008.asm
;
; Microcontroller:
; Microchip PIC16F87x or compatible
; Can be adapted to all mid-range
; PIC controllers with enough program
; memory by changing I/O definitions
;
; Author : Code originally written by Kjell Tore Heien
; Modified by Karl H. Torvmark
;
; Contact : Chipcon AS +47 22 95 85 44
; support@chipcon.com
;
; Version : 1.2 - 2001-08-14
;
;*****************************************************************************
;*****************************************************************************
; DESCRIPTION
; General:
; This code oversamples the output signal from a
; CC400/CC900 RF-transceiver. The output signal is coded
; in Manchester format, the MCU converts to NRZ format by
; taking 8 samples/bit. Signal decision is based on the
; majority of these samples, so noise will be filtered out.
;
; The MCU can also be used to transmision. The MCU reads NRZ
; signals, sending it to the transceiver in Manchester format.
;
; The configuration of CCX00 is done by the MCU, with three
; possible modes, Transceive(TX), Receive (RX) and Power Down (PD)
; In PowerDown mode, both the transceiver and MCU are powered
; down (sleep)
;
; The code needs to be changed to fit the application. The values
; for the configuration registers in CCX00 must be calculated in
; SmartRF Studio for the actual parameters and copied into the code.
; (A_RX_H_val to H_PD_L_val)
;
; Also some timing variables must be changed to match the data
; rate (TIMING_RX, TIMING_TX, Rate_RX and Rate_TX).
; See application note for formulas and values.
;
; Resources:
; Program memory : 428 words
; I/O pins : Port B pins 0,1,2,4 and 5
; Port C pins 0,1,2,3 and 4
; Peripherals : TMR0
;
;
; Mode configuration:
;
; *********************************************************
; * PIN * MODE *
; ************************* *
; * PD * RX_TX * *
; *********************************************************
; * 0 * 0 * Transmit mode (TX) *
; * 0 * 1 * Receive mode (RX) *
; * 1 * X (Don't care) * Power-down mode (PD) *
; *********************************************************
;
; Timing in TX mode:
; _ _ _ _ _ _ _ _ _
; CLK_OUT _/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
;
; DATA_IN pin (NRZ) | b1| b2| b3| b4| b5| b6| b7| b8| b9|
; DATA_IN pin read R R R R R R R R R R
; _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
; DIO pin (Manchester) |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
;
; Timing in RX mode:
; _______ _______ _______ _______ _____
; DIO pin (Manchester) |_______|_______|_______|_______|_____
; Sample S S S S S S S S S S S S S S S S S S S
; _______ _______
; CLOCK_OUT pin ________/ \_______/ \_____
; _______________ _______________ _____
; DATA_OUT pin |_______________|_______________|_____
;
; | Bit 1 | Bit 2 | Bit 3 ...
;
;
;*****************************************************************************
;*****************************************************************************
; This part gives names to predefined MCU registers
; Overview of ports:
;
; PORT: PORTB - User interface
; pin 0 CLK_OUT - Clock out
; pin 1 DATA_IN - Data in (TX mode)
; pin 2 DATA_OUT - Data out (RX mode)
; pin 3 unused -
; pin 4 PD - System configuration (PD(1))
; pin 5 RX_TX - System configuration (RX(1)/TX(0))
; pin 6 unused -
; pin 7 unused -
;
; PORT: PORTC - Communication with CC700/CC900
; pin 0 PDATA - Configuration pin
; pin 1 CLOCK - Configuration pin
; pin 2 STROBE - Configuration pin
; pin 3 DIO - Bi-directional data pin
; pin 4 SYNC - Synchronisation status
; pin 5 unused -
; pin 6 unused -
; pin 7 unused -
;*****************************************************************************
#define OPTION_REG 0x01
#define TMR0 0x01
#define PCL 0x02
#define STATUS 0x03
#define CARRY 0
#define Z 2
#define RP0 5
#define RP1 6
#define PORTB 0x06
#define CLK_OUT 0
#define DATA_IN 1
#define DATA_OUT 2
#define PD 4
#define RX_TX 5
#define PORTC 0x07
#define PDATA 0
#define CLOCK 1
#define STROBE 2
#define DIO 3
#define TRISB 0x06
#define TRISC 0x07
#define INTCON 0x0B
#define RBIF 0
#define INTF 1
#define T0IF 2
#define RBIE 3
#define T0IE 5
#define GIE 7
;*****************************************************************************
; This part gives names to variables and status registers
; mapped in the general purpose registers
;*****************************************************************************
#define X 0x20
#define A 0x22
#define An1 0x23
#define An2 0x24
#define A_LIMIT 0x25
#define A_LIMIT2 0x2F
#define R 0x26
#define COUNT 0x27
#define COUNT_LIMIT 0x28
#define CONTROL 0x29
#define R_ENABLE 0
#define SYNC 1
#define CONF_LOOP 2
#define TEMP 0x2A
#define TEMP1 0x2B
#define TEMP2 0x2C
#define INPUT 0x2D
#define DI 0
#define MODE 0x2E
#define RXTX 0
#define NUMBER 1
#define READ 2
#define CONFIG_REG 0x40
#define TABLE_PT 0x41
#define REG_COUNTER 0x42
#define BIT_COUNTER 0x43
#define BIT_ERRORS 0x44
;*****************************************************************************
; Status flags in registers are defined as follows :
;
; CONTROL (address 0x29)
; Bit number Flag
; 0 R_ENABLE
; 1 SYNC
; 2 CONF_LOOP
; 3 unused
; 4 unused
; 5 unused
; 6 unused
; 7 unused
;
; INPUT (address 0x2D)
; Bit number Flag
; 0 DI
; 1 unused
; 2 unused
; 3 unused
; 4 unused
; 5 unused
; 6 unused
; 7 unused
;
; MODE (address 0x2E)
; Bit number Flag
; 0 RXTX
; 1 NUMBER
; 2 READ
; 3 unused
; 4 unused
; 5 unused
; 6 unused
; 7 unused
;
;*****************************************************************************
;*****************************************************************************
; Configurations value for CC700/CC900, given by SmartRF Studio
; These values must be changed to match the application.
; The 3 most significant bits of A_RX_H_val contain the address of register A
; in the CC700/CC900. The rest of A_RX_H_val contains the 5 bits in
; register A for RX mode. A_RX_L_val contains the 8 least significant bits of
; register A (Similar for register B-H).
;*****************************************************************************
;*****************************************************************************
; Default values:
;
; Chip used : CC400
;
; X-tal frequency : 12.000000 MHz
; X-tal accuracy : 50 ppm
; RF frequency : 433.920000
; IF Stage : 200 kHz
; Frequency sep. : 10 kHz
; Data rate : 1.2 kbit/s
; Power amp. class: Class B
; RF output power : 10 dBm
; Receiver mode : Optimum sensitivity
; LOCK indicator : Continous
; VCO current : 000 (Maximum)
;*****************************************************************************
A_RX_H_val EQU 0x00
A_RX_L_val EQU 0x2A
B_RX_H_val EQU 0x23
B_RX_L_val EQU 0x0B
C_RX_H_val EQU 0x41
C_RX_L_val EQU 0x41
D_RX_H_val EQU 0x67
D_RX_L_val EQU 0x71
E_RX_H_val EQU 0x8A
E_RX_L_val EQU 0x00
F_RX_H_val EQU 0xB8
F_RX_L_val EQU 0x03
G_RX_H_val EQU 0xD2
G_RX_L_val EQU 0x4C
H_RX_H_val EQU 0xE4
H_RX_L_val EQU 0x50
A_TX_H_val EQU 0x08
A_TX_L_val EQU 0x2A
B_TX_H_val EQU 0x23
B_TX_L_val EQU 0x0B
C_TX_H_val EQU 0x41
C_TX_L_val EQU 0x41
D_TX_H_val EQU 0x67
D_TX_L_val EQU 0xA4
E_TX_H_val EQU 0x8A
E_TX_L_val EQU 0x14
F_TX_H_val EQU 0xB8
F_TX_L_val EQU 0x03
G_TX_H_val EQU 0xD2
G_TX_L_val EQU 0x4C
H_TX_H_val EQU 0xE8
H_TX_L_val EQU 0x60
A_PD_H_val EQU 0x18
A_PD_L_val EQU 0x2A
B_PD_H_val EQU 0x23
B_PD_L_val EQU 0x0B
C_PD_H_val EQU 0x41
C_PD_L_val EQU 0x51
D_PD_H_val EQU 0x67
D_PD_L_val EQU 0x71
E_PD_H_val EQU 0x8A
E_PD_L_val EQU 0x00
F_PD_H_val EQU 0xB8
F_PD_L_val EQU 0x03
G_PD_H_val EQU 0xD2
G_PD_L_val EQU 0x4C
H_PD_H_val EQU 0xE8
H_PD_L_val EQU 0x60
;*****************************************************************************
; These constants must not be changed
;*****************************************************************************
TABLE_PT_val EQU 0x00
SAMPLE_HALF EQU 0x03
SAMPLE_ALL EQU 0x07
;*****************************************************************************
; These values must be changed when using different combinations of bit-rates
; and MCU clock frequencies. Sets the period of the internal TMR0 interrupt,
; used in both RX- and TX mode.
;*****************************************************************************
;*****************************************************************************
;* Fosc = 20 MHz *
;*****************************************************************************
;* Data rate * TIMING_RX * Rate_RX * Error * TIMING_TX * Rate_TX * Error *
;*****************************************************************************
;* 9.6 kbps * 0xE5# * 0xD0 * 0.160% * 0x84 * 0xD0 * 0.224% *
;* 4.8 kbps * 0xC5 * 0xD0 * 0.160% * 0x02 * 0xD0 * 0.032% *
;* 2.4 kbps * 0x84 * 0xD0 * 0.160% * 0xFF * 0xD1 * 0.064% *
;* 1.2 kbps * 0x02 * 0xD0 * 0.160% * 0x7F * 0xD3 * 0.304% *
;* 600 bps * 0xFF * 0xD1 * 0.160% * 0x7E * 0xD4 * 0.152% *
;* 300 bps * 0xFD * 0xD2 * 0.032% * 0x7E * 0xD5 * 0.004% *
;*****************************************************************************
; # Use one NOP instruction in end_interrupt_RX, otherwise remove it.
;
; For other combinations of MCU clock frequencies and data-rates, see
; application note for values and formulas.
;
;*****************************************************************************
; Default values
; 20 MHz MCU clock, 1.2 kbps data rate
;*****************************************************************************
TIMING_RX EQU 0x02
TIMING_TX EQU 0x7F
Rate_RX EQU 0xD0
Rate_TX EQU 0xD3
;*****************************************************************************
; These timing values values can be changed to optimize synchronisation and
; data decision for a given application
;
; A_LIMIT_val - Decision limit, if A is smaller than the
; value, signal is 0, else signal is 1
; A_LIMIT_val2 - Decision limit while synchronising, if
; A is smaller than the value, signal is
; 0, else signal is 1 (Must be >=5)
; COUNT_LIMIT_val - Decides how long the synchronisation
; part should be. The value indicates how
; many 1's (A=>A_LIMIT_val2) the MCU must
; receive before it is synchronised (Should be >=4)
; A_SYNC_LIMIT_hi,
; A_SYNC_LIMIT_lo - If A>lo and A<hi for SYNC_LOSS_LIMIT bits, the
; receiver declares loss of synchronisation
; BIT_ERROR_LIMIT_val
; - How many low-quality bits are
; accepted before sync is lost
; (Should be >=2)
;*****************************************************************************
A_LIMIT_val EQU 0x04
A_LIMIT_val2 EQU 0x05
COUNT_LIMIT_val EQU 0X0A
A_SYNC_LIMIT_hi EQU 0x05
A_SYNC_LIMIT_lo EQU 0x03
BIT_ERROR_LIMIT_val EQU 0x02
;*****************************************************************************
;*****************************************************************************
;******************* PROGRAM START *******************************************
;*****************************************************************************
;*****************************************************************************
ORG 0x00 ; Location of reset vector
reset: GOTO main ; After reset, go to main program
ORG 0X04 ; Location of interrupt vector
interrupt: GOTO ServiceInterrupt ; If interrupt->go to ServiceInterrupt
ORG 0x50
;*****************************************************************************
; Main program
;*****************************************************************************
main:
BCF STATUS, RP0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -