123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "io.h"
- #define PIN_DATA 1
- #define PIN_CLK 2
- #define PIN_ACK 0
- #define PIN_IN 4
- #define PIN_LED 3
- #include "bus.h"
- #include "timer.h"
- void init_interrupt()
- {
- MCUSR = 0;
- wdt_disable();
- DDRB &= ~(1<<PB4); /* Set PB0 as input */
- PORTB |= (1<<PB4); /* Activate PULL UP resistor */
- PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
- GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
- sei ();
-
- }
- int main()
- {
- unsigned long last=0;
- unsigned long current_data = 0;
- bus_t bus;
- init();
- init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
- pinMode(PIN_IN, INPUT);
- pinMode(PIN_LED, OUTPUT);
- bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
- pinMode(PIN_IN, INPUT);
- while(1)
- {
- while(digitalRead(PIN_IN)) delay(1);
- while(!digitalRead(PIN_IN)) delay(1);
- current_data=micros()-last;
- if(current_data<10000) continue;
- last=micros();
- bus_write_sync(&bus, ¤t_data, 4);
- }
- }
|