Tel: Fax:

Similar documents
NOTICE: 1, the timing for Start, Stop, ACK, NACK, write and read is same as I2C

ECE Homework #10

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

RF4431 wireless transceiver module

RF67 Communication Example

User Manual of NRF24L01 Breakout Board

RF4432 wireless transceiver module

Hardware interface and protocol of data exchange with mobile beacon via USB, UART and SPI interfaces.

Speed Control of a DC Motor using Digital Control

Timer1 Capture Mode:

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

CMT2119A & CMT2219A Communication Example

RF01 programming guide

Interrupts on PIC18F252 Part 2

More Fun with Timer Interrupts

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

RF69 Communication Example

RFIC TX/RX Configuration

Protocol of data exchange with modem via USB interface Version

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

PL1167. Low Power High Performance Single Chip 2.4GHz Transceiver. Product Description: Key Features: Applications: Pin Configuration:

Building a wireless sensor network with use of RFM 12 modules - data exchange between nodes

MM Update for A3222Q56

Chapter 11: Interrupt On Change

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

nrf 24E1 Figure 1: Wireless 2.4GHz mouse/keyboard application

EM RF Transceiver. - Framer and Digital Interface Control

C:\CYGNAL\Examples\C8051F02x\C\Edu_Board_Source_Code\Magcard.c

LoRa Communication Example

#include <stdio.h> // // Global CONSTANTS

EE 354 September 16, 2016 C Sample Programs

ESP8266 Application Note Firmware Download Protocol

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017

Demo Kit User Manual

* File: 8x8_matrix_vinyl.c. * Author: Phil Glazzard. * Created on 16 August 2016, 17:59. /* This design drives five 8x8 common cathode LED matrices

Serial Peripheral Interface (SPI)

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

// Karl's MS G4 Transmitter Code // Nordic packet: NO_FFTS, FFT_SIZE, 32 Floating Pt. Magnitude Sums

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Freescale Semiconductor, I

Developer Notes INSTEON Thermostat v012. Developer Notes. INSTEON Thermostat. Revision History

DCB1M - Transceiver for Powerline Communication

TPMC810. Isolated 2x CAN Bus. Version 1.1. User Manual. Issue June 2009

Embit Binary Interface - WMBus Specific Documentation. embit s.r.l.

Serial Communication

CMT2300A FIFO and Packet Format Usage Guideline

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

C:\Documents and Settings\Administrateur\Mes documents\projets Keil\DisplayTech\main.c

Microcontroller Overview

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

Example of Asyncronous Serial Comms on a PIC16F877

LORD MANUAL. Wireless Sensor Networks LXRS Data Communications Protocol

SA818 Programming Manual

Serial Peripheral Interface (SPI) Last updated 8/7/18

Chapter 6 Serial EEPROM by John Leung

Interrupts. Embedded Systems Interfacing. 08 September 2011

RF Trans-controller ZULU. RF Transceiver combined with. Upto 2km Range Operates from V Dimensions: 25 x 11mm. Features. Transceiver Features

SURE. electronics. Demo Board for LCD Character Module User's Guide Sure Electronics Inc. DE-LD007_Ver1.0

Assembly Language Instructions

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.


Development Hardware. Target Board and In-circuit Debugger

Embedded System Design

Source Codes for DRA818U/DRA818V

Keywords: CRC, CRC-7, cyclic redundancy check, industrial output, PLC, programmable logic controller, C code, CRC generation, microprocessor, switch

Programming Guide I2C Bus

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Lecture (03) PIC16F84 (2)

LCD. Configuration and Programming

Logosol Joystick Node LS-731

RS232.C An Interrupt driven Asyncronous Serial Port

ECE Microcontrollers. Serial Peripheral Interface (SPI) & NRF24 Radio

PIC-I/O Multifunction I/O Controller

PIC16C7X 11.0 SYNCHRONOUS SERIAL PORT (SSP) MODULE SSP Module Overview. Applicable Devices

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Specification E2 Interface

TPMC Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014

Two Wire Interface (TWI) also commonly called I2C

AN127 FLASH PROGRAMMING VIA THE C2 INTERFACE. Relevant Devices. Introduction. C2 Interface

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

UM2173. Getting started with the S2-LP Sigfox firmware. User manual. Introduction

// and verify that there is a sine wave with frequency <FREQUENCY> and


Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

F28335 I2C MODULE v1.1

DATA SHEET MN63Y1210A. Part No. Package Code No. SSOP016-P-0225E

Application Note One Wire Digital Output. 1 Introduction. 2 Electrical Parameters for One Wire Interface. 3 Start and Data Transmission

MIDI.C December 8, 2002 Page 1

IP-48DAC channel 16-bit Digital/Analog Converter With memory Industry Pack Module PROGRAMMING MANUAL Version 1.

Using the USB and Serial Interfaces

Conto D2 COMMUNICATION PROTOCOL CONTENTS 1.0 INTRODUCTION

HI 3593 ARINC V Dual Receiver, Single Transmitter with SPI Application Note AN 161 June 13, 2012

AND8386/D. Bootloading BelaSigna 250 Using the I 2 C Interface APPLICATION NOTE

CAN / RS485. Product Description. Technical Reference Note. Interface Adapter. Special Features

UM2149. Getting started with the S2-LP development kits. User manual. Introduction

Introduction to Ethernet and lab3.3

Transcription:

/****************************************************************************** Title: RFM22 transmitter demo program Current version: V1.2 Function: Package send Demo Processor PIC16F690 DIP-20 Clock: internal 8M. Operate frequency: 434MHz Data rate: 2.4kbps modulation: FSK deviation: 45K bandwidth: 94.8K frame mode: PH + FIFO payload 0x30, 0x31...0x3f, 0x78(chksum) Author : Simon.Yang Company: HopeRF microelectroni Contact: +86-0755-82973806 Date: 2010-07-14 The example is only for your reference. ******************************************************************************/ #include<pic.h> typedef unsigned char uchar; typedef unsigned int uint; const uchar tx_buf[17] = 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x78; // ch8 is 140 #define RF22_PWRSTATE_READY 01 #define RF22_PWRSTATE_TX 0x09 1

#define RF22_PACKET_SENT_INTERRUPT 04 #define RF22_PWRSTATE_POWERDOWN 00 RF22 TX Program V1.2 #define nirq RA2 #define nsel RC6 #define SDO RC7 #define SDI RB4 #define LED_RED RB5 #define SCK RB6 #define TXEN RA4 #define RXEN RA5 uchar count_50hz; uchar ItStatus1, ItStatus2; typedef struct uchar reach_1s : 1; FlagType; FlagType Flag; uchar read_8bit_data(void); void to_tx_mode(void); void to_ready_mode(void); void send_8bit_data(uchar i); void send_read_address(uchar i); void spi_write(uchar address, uchar data); void RF22_init_parameter(void); void delay_50ms(void); void delay_5ms(void); void delay_1ms(void); void port_init(void); void power_on_delay(void); uchar spi_read(uchar address); void Write0( void ); void Write1( void ); void timer2_init(void); void Write8bitcommand(uchar command); void to_sleep_mode(void); CONFIG(0x3F04); //***************************************************************************** 2

void main() uchar i,j,chksum; OSCCON = 0X70; // 8M crystal WDTCON = 0X00; power_on_delay(); port_init(); timer2_init(); count_50hz = 0; Flag.reach_1s = 0; INTCON = 0xc0; // enable interrupt RF22_init_parameter(); while(1) //to_sleep_mode(); //enter sleep mode if(flag.reach_1s) Flag.reach_1s = 0; to_tx_mode(); // TRANSIMITTE DATA //***************************************************************************** void Write0( void ) SDI=0; SCK=1; void Write1( void ) Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com 3

SDI=1; SCK=1; void Write8bitcommand(uchar command) // keep sel to low uchar n=8; nsel = 1; nsel=0; while(n--) if(command&0x80) Write1(); else Write0(); command = command << 1; void delay_50ms(void) uchar j; for(j = 0; j<10; j++) delay_5ms(); void delay_5ms(void) int i; for(i = 0; i<650; i++) // 85*5 ; void delay_1ms(void) 4

uchar i; for(i = 0; i<130; i++) ; void timer2_init(void) T2CON = 0x7f; // timer2 on and 16 pre, postscale PR2 = 156; // 50hZ, 4m/4/16/16/50 TMR2IE = 1; void interrupt ISR_timer(void) uchar i; if(tmr2if) count_50hz++; if(count_50hz==50) // REACH 1S count_50hz=0; Flag.reach_1s = 1; TMR2IF=0; void port_init(void) ANSEL = 0; ANSELH = 0; WPUA = 0; // NO PULL UP IOCA = 0; // NO INTERRUPT ON CHANGE TRISA = 0x0f; // all ra0-- ra3 input, RA4,5 OUTPUT TRISB = 0x80; // rb7 input WPUB = 0x00; // no pull up TRISC = 0b10101111; // pc7,5,3,2,1,0 input RC4=0; LED_RED = 0; TXEN = RXEN = 0; 5

void power_on_delay(void) uint i; for(i = 0; i<1000; i++) delay_1ms(); uchar spi_read(uchar address) uchar result; send_read_address(address); result = read_8bit_data(); nsel = 1; return(result); void RF22_init_parameter(void) ItStatus1 = spi_read(0x03); // read status, clear interrupt ItStatus2 = spi_read(0x04); spi_write(0x06, 0x00); // no wakeup up, lbd, spi_write(0x07, RF22_PWRSTATE_READY); // disable lbd, wakeup timer, use internal 32768,xton = 1; in ready mode spi_write(0x09, 0x7f); // c = 12.5p spi_write(0x0a, 0x05); spi_write(0x0b, 0xf4); // gpio0 for received data output spi_write(0x0c, 0xef); // gpio 1 for clk output spi_write(0x0d, 0xfd); // gpio 2 micro-controller clk output spi_write(0x0e, 0x00); // gpio 0, 1,2 NO OTHER FUNCTION. spi_write(0x70, 0x20); // disable manchest //case RATE_24K: // 2.4k spi_write(0x6e, 0x13); spi_write(0x6f, 0xa9); //PH+FIFO spi_write(0x30, 0x8c); // enable packet handler, msb first, enable crc, // 0x31 only readable spi_write(0x32, 0xff); // 0x32address enable for headere byte 0, 1,2,3, receive header check 6

for byte 0, 1,2,3 spi_write(0x33, 0x42); // header 3, 2, 1,0 used for head length, fixed packet length, synchronize word length 3, 2, spi_write(0x34, 64); // 64 nibble = 32byte preamble spi_write(0x36, 0x2d); // synchronize word spi_write(0x37, 0xd4); spi_write(0x38, 0x00); spi_write(0x39, 0x00); spi_write(0x3a, 's'); // tx header spi_write(0x3b, 'o'); spi_write(0x3c, 'n'); spi_write(0x3d, 'g'); spi_write(0x3e, 17); // total tx 17 byte // 0x52, 53, 54, 55 set to default // 0x56 ---------0x6c?????????????????????????? spi_write(0x6d, 0x0f); // set power max power spi_write(0x79, 0x0); // no hopping spi_write(0x7a, 0x0); // no hopping spi_write(0x71, 0x22); // Gfsk, fd[8] =0, no invert for Tx/Rx data, fifo mode, txclk -->gpio spi_write(0x72, 0x38); // frequency deviation setting to 45k = 72*625 spi_write(0x73, 0x0); spi_write(0x74, 0x0); // no offset //band 434 spi_write(0x75, 0x53); // hbsel = 0, sbsel =1???, fb = 19 spi_write(0x76, 0x64); // 25600= 0x6400 for 434Mhz spi_write(0x77, 0x00); void spi_write(uchar address, uchar data) address = 0x80; Write8bitcommand(address); send_8bit_data(data); nsel = 1; void send_read_address(uchar i) i &= 0x7f; 7

Write8bitcommand(i); void send_8bit_data(uchar i) uchar n = 8; while(n--) if(i&0x80) Write1(); else Write0(); i = i << 1; uchar read_8bit_data(void) uchar Result, i; RF22 TX Program V1.2 Result=0; for(i=0;i<8;i++) //read fifo data byte Result=Result<<1; SCK=1; if(sdo) Result =1; return(result); void to_tx_mode(void) uchar i; to_ready_mode(); 8

//delay_50ms(); RXEN = 0; TXEN = 1; spi_write(0x08, 0x03); // disable AUTO TX MODE, enble multi packet clear fifo spi_write(0x08, 0x00); // disable AUTO TX MODE, enble multi packet, clear fifo // ph +fifo mode spi_write(0x34, 64); // 64 nibble = 32byte preamble spi_write(0x3e, 17); // total tx 17 byte for (i = 0; i<17; i++) spi_write(0x7f, tx_buf[i]); spi_write(0x05, RF22_PACKET_SENT_INTERRUPT); ItStatus1 = spi_read(0x03); //read the Interrupt Status1 register ItStatus2 = spi_read(0x04); spi_write(0x07, RF22_PWRSTATE_TX); // to tx mode while(nirq); to_ready_mode(); RXEN = 0; TXEN = 0; LED_RED= 1; delay_50ms(); LED_RED= 0; void to_ready_mode(void) ItStatus1 = spi_read(0x03); ItStatus2 = spi_read(0x04); spi_write(0x07, RF22_PWRSTATE_READY); void to_sleep_mode(void) TXEN = RXEN = 0; LED_RED = 0; spi_write(0x07, RF22_PWRSTATE_READY); ItStatus1 = spi_read(0x03); //read the Interrupt Status1 register ItStatus2 = spi_read(0x04); spi_write(0x07, RF22_PWRSTATE_POWERDOWN); while(1) 9

; RF22 TX Program V1.2 Tel: +86-755-82973805 Fax: +86-755-82973550 E-mail: sales@hoperf.com 10