123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #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<<PB3); /* Set PB0 as input */
- PORTB |= (1<<PB3); /* Activate PULL UP resistor */
- PCMSK |= (1 << PCINT3); /* Enable PCINT0 */
- GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
- sei ();
- }
- int main()
- {
- int wait=0, state=0;
- unsigned long last=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);
- }
- }
- 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);
- }
- }
- */
|