Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

pin_programming.c 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <avr/io.h>
  2. #include <stdint.h>
  3. #include <util/delay.h>
  4. #include "pin_programming.h"
  5. /* Pin definitions */
  6. #define PIN_PROG_1_DDR DDRB
  7. #define PIN_PROG_1_PORT PORTB
  8. #define PIN_PROG_1_PIN PB6
  9. #define PIN_PROG_1_PORTIN PINB
  10. #define PIN_PROG_2_DDR DDRB
  11. #define PIN_PROG_2_PORT PORTB
  12. #define PIN_PROG_2_PIN PB7
  13. #define PIN_PROG_2_PORTIN PINB
  14. #define PIN_PROG_3_DDR DDRD
  15. #define PIN_PROG_3_PORT PORTD
  16. #define PIN_PROG_3_PIN PD4
  17. #define PIN_PROG_3_PORTIN PIND
  18. void Configure_Pin_Programming_Pins(void)
  19. {
  20. /* Set pins as input */
  21. PIN_PROG_1_DDR &= ~(1 << PIN_PROG_1_PIN);
  22. PIN_PROG_2_DDR &= ~(1 << PIN_PROG_2_PIN);
  23. PIN_PROG_3_DDR &= ~(1 << PIN_PROG_3_PIN);
  24. /* Enable pull-ups */
  25. PIN_PROG_1_PORT |= (1 << PIN_PROG_1_PIN);
  26. PIN_PROG_2_PORT |= (1 << PIN_PROG_2_PIN);
  27. PIN_PROG_3_PORT |= (1 << PIN_PROG_3_PIN);
  28. _delay_us(20);
  29. }
  30. uint8_t Get_Own_Identifier(void)
  31. {
  32. /* The upper four bits of the ID are the module ID while the lower four bits are the serial
  33. * number set by the pin programming.
  34. * Switch 3 corresponds to bit 0
  35. * Switch 2 corresponds to bit 1
  36. * Switch 1 corresponds to bit 2
  37. */
  38. uint8_t id = (MODULE_ID_SENSOR << 4);
  39. id |= ((((PIN_PROG_3_PORTIN & (1 << PIN_PROG_3_PIN)) == 0) << 0) | \
  40. (((PIN_PROG_2_PORTIN & (1 << PIN_PROG_2_PIN)) == 0) << 1) | \
  41. (((PIN_PROG_1_PORTIN & (1 << PIN_PROG_1_PIN)) == 0) << 2));
  42. return id;
  43. }