heater3.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * heater3.h
  3. *
  4. * Created: 25.06.2019 12:29:07
  5. * Author: naa
  6. */
  7. #ifndef HEATER3_H_
  8. #define HEATER3_H_
  9. #include <avr/io.h>
  10. #include <avr/interrupt.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include <string.h>
  15. #define TX_LENGTH 16
  16. #define TWI_FREQ 500000
  17. #define BAUD_RATE 38400
  18. #define U2X0_SET 1
  19. #define ADC_MEAS1 0
  20. #define ADC_MEAS2 1
  21. #define ADC_CUR1 2
  22. #define ADC_CUR2 3
  23. #define LEDPORT PORTC
  24. #define LED1 PORTC2
  25. #define LED2 PORTC3
  26. #define GATEPORT PORTC
  27. #define GATE1 PORTC6
  28. #define GATE2 PORTC7
  29. #define V12POWER PORTC4
  30. #define OCP1 PORTD2
  31. #define OCP2 PORTD3
  32. #define BTNPIN PIND
  33. #define BTN1 PORTD4
  34. #define BTN2 PORTD5
  35. #define BTN3 PORTD6
  36. #define BTN4 PORTD7
  37. #define CH0 0
  38. #define CH1 1
  39. #define MAXADDR 0x06
  40. #define START_BYTE 0x55
  41. #define CURR_MAX 2500
  42. #define DISP_OFF 0
  43. #define DISP_MAIN 1
  44. #define DISP_DBG 2
  45. #define DISP_VER 3
  46. typedef union {
  47. uint8_t byte[4];
  48. uint16_t word[2];
  49. uint32_t dword;
  50. } btw32_t;
  51. typedef union {
  52. uint8_t byte[2];
  53. uint16_t word;
  54. } btw16_t;
  55. typedef enum { CIRC_OPEN, CIRC_SHORT, CIRC_MOSFET, CIRC_RES_DIODE, CIRC_RES, CIRC_DIODE } circ_t;
  56. typedef struct {
  57. uint8_t channel : 1;
  58. uint8_t onoff : 1;
  59. uint8_t heating : 1;
  60. uint8_t ocp : 1;
  61. uint8_t calib : 2;
  62. circ_t circuit : 3;
  63. uint8_t couple : 3;
  64. } status_str;
  65. typedef struct {
  66. volatile status_str status;
  67. uint8_t preset;
  68. int8_t tintr;
  69. int16_t tcouple;
  70. int16_t tmeas;
  71. uint16_t tmeas_raw;
  72. uint16_t tset;
  73. uint16_t tset_raw;
  74. uint16_t current;
  75. uint8_t gain;
  76. uint8_t shift;
  77. uint8_t drive;
  78. } heater_str;
  79. typedef enum { CMD_RESET, CMD_REQ, CMD_CHONOFF, CMD_SETTEMP, CMD_SETRANGE, CMD_SETVDRIVE, CMD_SWPRESET, CMD_LOADDATA, CMD_HEATING, CMD_CALIBRATION } cmd_t;
  80. typedef enum { REQ_RST, REQ_ACK, REQ_NACK, REQ_MAINDATA, REQ_DEBUGDATA, REQ_PRESETTABLE, REQ_PRESETDATA } txreq_t;
  81. typedef enum { CAL_OFF, CAL_AUTO, CAL_MANUAL } cal_t;
  82. typedef struct {
  83. char start;
  84. uint8_t len;
  85. cmd_t command;
  86. uint8_t data[160];
  87. uint8_t checksum;
  88. } comdata_str;
  89. typedef struct {
  90. uint8_t set;
  91. uint8_t blink_cnt;
  92. uint8_t pressed;
  93. } menu_str;
  94. typedef struct {
  95. uint16_t temp;
  96. uint16_t adcdata;
  97. } record_str;
  98. typedef struct {
  99. uint8_t number;
  100. char header[12];
  101. uint8_t gain;
  102. uint8_t shift;
  103. uint8_t drive;
  104. record_str curve[16];
  105. } preset_str;
  106. typedef struct {
  107. uint16_t oc : 1;
  108. uint16_t scg : 1;
  109. uint16_t scv : 1;
  110. uint16_t : 1;
  111. uint16_t intt_frac : 4;
  112. uint16_t intt_int : 8;
  113. uint16_t fault : 1;
  114. uint16_t : 1;
  115. uint16_t tct_frac : 2;
  116. uint16_t tct_int : 12;
  117. } max31855_t;
  118. typedef struct {
  119. uint8_t pressed : 1;
  120. uint8_t released : 1;
  121. uint8_t holded : 1;
  122. uint8_t holdcnt : 5;
  123. uint8_t code : 4;
  124. uint8_t prev_code : 4;
  125. } btn_t;
  126. int lcd_putchar(char c, FILE *stream);
  127. int uart_putchar(char c, FILE *stream);
  128. void ProcessCommand();
  129. #endif /* HEATER3_H_ */