94 lines
1.9 KiB
C
94 lines
1.9 KiB
C
/*
|
|
* Reciver.c
|
|
*
|
|
* Created: 25.03.2013 21:03:07
|
|
* Author: netz
|
|
*/
|
|
|
|
#define F_CPU 8000000
|
|
|
|
#define LEFT 600
|
|
#define RIGHT 202
|
|
#define STEP 8
|
|
|
|
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include <util/delay.h>
|
|
#include "rf12.h"
|
|
|
|
volatile int servopos = 0;
|
|
|
|
void turn() {
|
|
DDRB |= (1<<PB0);
|
|
PORTB |= (1<<PB0);
|
|
_delay_ms(20);
|
|
PORTB &= ~(1<<PB0);
|
|
servopos = RIGHT;
|
|
_delay_ms(700);
|
|
servopos = 0;
|
|
_delay_ms(700);
|
|
}
|
|
|
|
void recive() {
|
|
unsigned char text[2];
|
|
text[0] = 0;
|
|
text[1] = 0;
|
|
rf12_rxdata(text,2);
|
|
if(text[0] == 55 && text[1] == 99) {
|
|
turn();
|
|
}
|
|
}
|
|
|
|
void send() {
|
|
unsigned char text[1] = {0x01};
|
|
rf12_txdata(text,1);
|
|
_delay_ms(100);
|
|
}
|
|
|
|
void init_timer() {
|
|
// Timer/Counter 0 initialization
|
|
// Clock source: System Clock
|
|
// Clock value: 7,813 kHz
|
|
// Mode: Normal top=0xFF
|
|
// OC0 output: Disconnected
|
|
// Timer Period: 21,504 ms
|
|
TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (1<<CS02) | (0<<CS01) | (1<<CS00);
|
|
TCNT0=0x58;
|
|
OCR0=0x00;
|
|
// Timer(s)/Counter(s) Interrupt(s) initialization
|
|
TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (1<<TOIE0);
|
|
}
|
|
|
|
ISR(TIMER0_OVF_vect) {
|
|
// Reinitialize Timer 0 value
|
|
TCNT0=0x58;
|
|
|
|
DDRB |= (1<<PB1);
|
|
PORTB |= (1<<PB1);
|
|
_delay_us(LEFT);
|
|
for(int i=0;i<servopos;i++) {
|
|
_delay_us(STEP);
|
|
}
|
|
PORTB &= ~(1<<PB1);
|
|
}
|
|
|
|
int 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(1, 0, 7); // 400kHz Bandbreite, 0dB Verstärkung, DRSSI threshold: -61dBm
|
|
rf12_setbaud(9600); // 19200 baud
|
|
rf12_setpower(0, 6); // 1mW Ausgangsleistung, 120kHz Frequenzshift
|
|
init_timer();
|
|
sei();
|
|
|
|
while(1)
|
|
{
|
|
recive();
|
|
//_delay_ms(200);
|
|
/*PORTB |= (1<<PB0);
|
|
send();
|
|
PORTB &= ~(1<<PB0);
|
|
_delay_ms(900);*/
|
|
}
|
|
} |