Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
const flash var_type var_name
const flash unsigned char my_char=123;
const flash int my_int=1234;
eeprom var_type var_name
eeprom unsigned char my_eeprom_char;
eeprom unsigned char my_eeprom_char =12;
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);
void main(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{
receive();
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
for (i=0; i<32; i++);
}
void send(void)
{ unsigned char test[]="Dies ist ein 433MHz Test !!!\n ";
rf12_txdata(test,32);
}
#include <mega8.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
#asm("cbi(RF_PORT, CS)");
for (i=0; i<16; i++)
{ if (wert&32768)
#asm("sbi(RF_PORT, SDI)");
else
#asm("cbi(RF_PORT, SDI)");
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
#asm("sbi(RF_PORT, SCK)");
#asm("nop");
#asm("nop");
#asm("cbi(RF_PORT, SCK)");
}
#asm("sbi(RF_PORT, CS)");
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ #asm("cbi(RF_PORT, SDI)");
#asm("cbi(RF_PORT, CS)");
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);
void main(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{
receive();
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
for (i=0; i<32; i++);
}
void send(void)
{ unsigned char test[]="Dies ist ein 433MHz Test !!!\n ";
rf12_txdata(test,32);
}
#include <mega8.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
#asm("cbi(RF_PORT, CS)");
for (i=0; i<16; i++)
{ if (wert&32768)
#asm("sbi(RF_PORT, SDI)");
else
#asm("cbi(RF_PORT, SDI)");
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
#asm("sbi(RF_PORT, SCK)");
#asm("nop");
#asm("nop");
#asm("cbi(RF_PORT, SCK)");
}
#asm("sbi(RF_PORT, CS)");
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ #asm("cbi(RF_PORT, SDI)");
#asm("cbi(RF_PORT, CS)");
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
#include <mega8.h>
#include <stdlib.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
unsigned char i;
void send(void);
void receive(void);
void main(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{
receive();
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
for (i=0; i<32; i++);
}
void send(void)
{ unsigned char test[]="Dies ist ein 433MHz Test !!!\n ";
rf12_txdata(test,32);
}
#include <mega8.h>
#include "global.h"
#include "rf12.h"
#define F_CPU 8000000UL
#include <delay.h>
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
#asm("cbi(RF_PORT, CS)");
for (i=0; i<16; i++)
{ if (wert&32768)
#asm("sbi(RF_PORT, SDI)");
else
#asm("cbi(RF_PORT, SDI)");
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
#asm("sbi(RF_PORT, SCK)");
#asm("nop");
#asm("nop");
#asm("cbi(RF_PORT, SCK)");
}
#asm("sbi(RF_PORT, CS)");
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ #asm("cbi(RF_PORT, SDI)");
#asm("cbi(RF_PORT, CS)");
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
#asm("cbi(RF_PORT, CS)");
#asm("sbi(RF_PORT, SDI)");
What is the point of posting three times the same thing?
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 12/26/2012
Author : PerTic@n
Company : If You Like This Software,Buy It
Comments:
Chip type : ATmega16L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <stdlib.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <delay.h>
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 3
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
}
#define F_CPU 8000000UL
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
PORTB.2=0;
for (i=0; i<16; i++)
{ if (wert&32768)
PORTB.3=1;
else
PORTB.3=0;
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
PORTB.5=1;
#asm("nop");
#asm("nop");
PORTB.5=0;
}
PORTB.2=1;
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ PORTB.3=0;
PORTB.2=0;
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
#define F_CPU 8000000UL
unsigned char i;
void send(void);
void receive(void);
void main2(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{
receive();
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
lcd_puts(test);
}
void send(void)
{ unsigned char test[]="Dies ist ein 433MHz Test !!!\n ";
rf12_txdata(test,32);
}
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 12/26/2012
Author : PerTic@n
Company : If You Like This Software,Buy It
Comments:
Chip type : ATmega16L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <stdlib.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <delay.h>
// Declare your global variables here
#include "rf12.h"
#define F_CPU 8000000UL
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
PORTB.2=0;
for (i=0; i<16; i++)
{ if (wert&32768)
PORTB.3=1;
else
PORTB.3=0;
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
PORTB.5=1;
#asm("nop");
#asm("nop");
PORTB.5=0;
}
PORTB.2=1;
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ PORTB.3=0;
PORTB.2=0;
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
void send(void);
void receive(void);
void main2(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{
receive();
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
lcd_puts(test);
}
void send(void)
{ unsigned char test[]="worked!!";
rf12_txdata(test,32);
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 3
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
main2();
}
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 12/26/2012
Author : PerTic@n
Company : If You Like This Software,Buy It
Comments:
Chip type : ATmega8L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <stdlib.h>
#include <delay.h>
// Declare your global variables here
#include "rf12.h"
// Declare your global variables here
#define F_CPU 8000000UL
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
unsigned char i;
unsigned short rf12_trans(unsigned short wert)
{
unsigned char i;
PORTB.2=0;
for (i=0; i<16; i++)
{ if (wert&32768)
PORTB.3=1;
else
PORTB.3=0;
wert<<=1;
if (RF_PIN&(1<<SDO))
wert|=1;
PORTB.5=1;
#asm("nop");
#asm("nop");
PORTB.5=0;
}
PORTB.2=1;
return wert;
}
void rf12_init(void)
{ unsigned char i;
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (i=0; i<50; i++)
delay_ms(10); // wait until POR done
rf12_trans(0xC0E0); // AVR CLK: 10MHz
rf12_trans(0x80D7); // Enable FIFO
rf12_trans(0xC2AB); // Data Filter: internal
rf12_trans(0xCA81); // Set FIFO mode
rf12_trans(0xE000); // disable wakeuptimer
rf12_trans(0xC800); // disable low duty cycle
rf12_trans(0xC4F7); // AFC settings: autotuning: -10kHz...+7,5kHz
}
void rf12_setbandwidth(unsigned char bandwidth, unsigned char gain, unsigned char drssi)
{
rf12_trans(0x9400|((bandwidth&7)<<5)|((gain&3)<<3)|(drssi&7));
}
void rf12_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf12_trans(0xA000|freq);
}
void rf12_setbaud(unsigned short baud)
{
if (baud<664)
baud=664;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf12_trans(0xC680|((43104/baud)-1)); // R=(344828/8)/Baud-1
else
rf12_trans(0xC600|((344828UL/baud)-1)); // R=344828/Baud-1
}
void rf12_setpower(unsigned char power, unsigned char mod)
{
rf12_trans(0x9800|(power&7)|((mod&15)<<4));
}
void rf12_ready(void)
{ PORTB.3=0;
PORTB.2=0;
#asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
}
void rf12_txdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x8238); // TX on
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB8AA);
rf12_ready();
rf12_trans(0xB82D);
rf12_ready();
rf12_trans(0xB8D4);
for (i=0; i<number; i++)
{ rf12_ready();
rf12_trans(0xB800|(*data++));
}
rf12_ready();
delay_us(10);
rf12_trans(0x8208); // TX off
}
void rf12_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i;
rf12_trans(0x82C8); // RX on
rf12_trans(0xCA81); // set FIFO mode
rf12_trans(0xCA83); // enable FIFO
for (i=0; i<number; i++)
{ rf12_ready();
*data++=rf12_trans(0xB000);
}
rf12_trans(0x8208); // RX off
}
void send(void);
void receive(void);
void main2(void)
{
rf12_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf12_setfreq(RF12FREQ(433.92)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstنrkung, DRSSI threshold: -79dBm
rf12_setbaud(19200); // 19200 baud
rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift
#asm("sei");
for (;;)
{ send();
for (i=0; i<100; i++)
delay_ms(10);
}
}
void receive(void)
{ unsigned char test[32];
rf12_rxdata(test,32);
}
void send(void)
{ unsigned char test[]="worked!!";
rf12_txdata(test,32);
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
main2();
}