Jaha, nu har jag gjort klart mottagar koden.
Jag väntar bara nu på lite grejer så jag kan gö klart mottagarkortet.
När jag kollar på databladet för mottagar modulen så förstår jag inte riktigt hur dem menar att man ska göra.
Ska man bara koppla uCn till + å - och en pinne på OUT?
Bladet:
http://www.elfa.se/pdf/75/07520596.pdf - sidan 5
Koden för mottagaren, använd den hur ni än vill och kom gärna med förbättringar om ni vill:
Kod: Markera allt
/*
This code is made for an ATtiny 45 at 1MHz.
It can be used and remade by anyone as long as is isn't in for product use then please speak to me first.
*/
#define F_CPU 1000000
#include <avr/interrupt.h>
#include <util/delay.h>
void interupt(void);
unsigned int ticks = 0;
unsigned int result = 0;
int main(void)
{
cli();
DDRB = (0<<0)|(1<<1); // Set PORTB.0 for input and PORTB.1 for output
PORTB |= (1<<0)|(0<<1); // Enable pullup on PORTB.0 and PORTB.1 low
// The interupt sequence
PCMSK = (1<<0);
GIFR = (1<<5)|(1<<6);
GIMSK = (1<<5)|(1<<6);
MCUCR = (1<<ISC01); // Trigger interupt on Falling Edge
// Initialize Timer0.
// Enable timer0 compare interrupt
TIMSK = (1<<OCIE0A);
// Sets the compare value
OCR0A = 100;
// Set Clear on Timer Compare (CTC) mode, No prescaler
TCCR0A = (1<<WGM01)|(0<<WGM00); // CTC mode
sei();
while(1)
{
}
return 0;
}
SIGNAL(SIG_PIN_CHANGE)
{
interupt(); // Run interupt() on interupt
}
SIGNAL(SIG_OUTPUT_COMPARE0A)
{
ticks++; // Increase ticks for time mesure
}
void interupt(void)
{
cli();
if (ticks != 0)
{
TCCR0B = 0; // Stop timer
result = (ticks / 10); // Mesure resault in ms (ticks is in 1/10ms)
MCUCR = (1<<ISC01); // Trigger interupt on Falling Edge
}
else
{
ticks = 0; // Reset ticks
result = 0; // Reset resault
MCUCR = (1<<ISC01)|(1<<ISC00); // Trigger interupt on Rising Edge
TCCR0B = (1<<CS00); // Start timer, no prescaler
}
if ((result <= 105) && (result >= 95)) // Set the time period on which it shall start in ms
{
PORTB |= (1<<1); // PORTB.1 high
_delay_ms(100);
_delay_ms(100);
_delay_ms(100);
PORTB &= ~(1<<1); // PORTB.1 low
for (int i = 0; i < 10; i++)
{
_delay_ms(100); // 1sec delay, we have already started the computer and we doesn't want to shut it down again
}
}
sei();
}
Koden är otestad så jag vet inte än om den fungerar.
//Emil