|
@@ -12,126 +12,43 @@
|
|
|
#include "bus.h"
|
|
|
#include "timer.h"
|
|
|
|
|
|
+
|
|
|
+
|
|
|
void init_interrupt()
|
|
|
{
|
|
|
MCUSR = 0;
|
|
|
wdt_disable();
|
|
|
- DDRB &= ~(1<<PB3); /* Set PB0 as input */
|
|
|
- PORTB |= (1<<PB3); /* Activate PULL UP resistor */
|
|
|
+ DDRB &= ~(1<<PB4); /* Set PB0 as input */
|
|
|
+ PORTB |= (1<<PB4); /* Activate PULL UP resistor */
|
|
|
|
|
|
- PCMSK |= (1 << PCINT3); /* Enable PCINT0 */
|
|
|
+ PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
|
|
|
GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
|
|
|
sei ();
|
|
|
+
|
|
|
}
|
|
|
int main()
|
|
|
{
|
|
|
- int wait=0, state=0;
|
|
|
unsigned long last=0;
|
|
|
+ unsigned long current_data = 0;
|
|
|
bus_t bus;
|
|
|
init();
|
|
|
init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
|
|
|
- //init_interrupt();
|
|
|
pinMode(PIN_IN, INPUT);
|
|
|
pinMode(PIN_LED, OUTPUT);
|
|
|
bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
|
|
|
- /*while(1)
|
|
|
- {
|
|
|
- if(!wait && read_pin(PIN_IN) )
|
|
|
- {
|
|
|
- unsigned long val;
|
|
|
- val=micros()-last;
|
|
|
- if(val<5000) continue;
|
|
|
- wait=1;
|
|
|
- last=micros();
|
|
|
- //bus_write_sync(&bus, &val, 4);
|
|
|
- state=(!state)?1:0;
|
|
|
- digitalWrite(PIN_LED, state);
|
|
|
- }
|
|
|
-
|
|
|
- if(!read_pin(PIN_IN)) wait=0;
|
|
|
- }*/
|
|
|
-
|
|
|
- pinMode(PIN_IN, INPUT);
|
|
|
- int i;
|
|
|
- /*for(i=0; i<3; i++)
|
|
|
- {
|
|
|
- digitalWrite(PIN_CLK, 0);
|
|
|
- micro_sleep(500000);
|
|
|
-
|
|
|
- digitalWrite(PIN_CLK, 1);
|
|
|
- micro_sleep(500000);
|
|
|
- digitalWrite(PIN_CLK, 0);
|
|
|
- }*/
|
|
|
- while(1)
|
|
|
- {
|
|
|
- bus_write_sync(&bus, "Salut", 5);
|
|
|
- delay(250);
|
|
|
- //digitalWrite(PIN_DATA, digitalRead(PIN_ACK));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * #include <stdio.h>
|
|
|
-#include <stdlib.h>
|
|
|
-#include <string.h>
|
|
|
-#include "io.h"
|
|
|
|
|
|
-#define PIN_DATA 0
|
|
|
-#define PIN_CLK 1
|
|
|
-#define PIN_ACK 2
|
|
|
-#define PIN_IN 3
|
|
|
-#define PIN_LED 4
|
|
|
-
|
|
|
-#include "bus.h"
|
|
|
-
|
|
|
-void init_interrupt()
|
|
|
-{
|
|
|
- MCUSR = 0;
|
|
|
- wdt_disable();
|
|
|
- DDRB &= ~(1<<PB3);
|
|
|
- PORTB |= (1<<PB3);
|
|
|
-
|
|
|
- PCMSK |= (1 << PCINT3);
|
|
|
- GIMSK |= (1 << PCIE);
|
|
|
- sei ();
|
|
|
-}
|
|
|
-
|
|
|
-bus_t bus;
|
|
|
-
|
|
|
-int main()
|
|
|
-{
|
|
|
- init();
|
|
|
- init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
|
|
|
- init_interrupt();
|
|
|
pinMode(PIN_IN, INPUT);
|
|
|
- pinMode(PIN_LED, OUTPUT);
|
|
|
- bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
|
|
|
while(1)
|
|
|
{
|
|
|
- //bus_send_thread(&bus);
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-unsigned long last=0;
|
|
|
-uint8_t ledstate=0;
|
|
|
-
|
|
|
-ISR (PCINT0_vect){
|
|
|
- uint8_t x = (PORTB&(1<<PB3))>>PB3;
|
|
|
- if(x)
|
|
|
- {
|
|
|
- uint32_t val=micros()-last;
|
|
|
- last=micros();
|
|
|
- bus_write(&bus, &val, 4);
|
|
|
- ledstate=(ledstate)?0:1;
|
|
|
- digitalWrite(PIN_LED, ledstate);
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-*/
|
|
|
|
|
|
|