Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include "uart.h"
  2. #include "adc.h"
  3. #define F_CPU 14745600UL
  4. #include <avr/io.h>
  5. #include <util/delay.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8.  
  9. #define BUFF_SIZE 300
  10. #define VT_HI 140
  11. #define VT_LO 110
  12.  
  13. uint8_t buff_0[BUFF_SIZE];
  14. uint8_t buff_1[BUFF_SIZE];
  15.  
  16. void send_buffer(uint8_t *buffer){
  17. int i;
  18. for (i = 0; i<BUFF_SIZE;i++){
  19. uart_send_byte(buffer[i]);
  20. }
  21. }
  22.  
  23.  
  24.  
  25. void UART_SendOscData(uint8_t* buff_0, uint8_t* buff_1, uint16_t buff_size){
  26.  
  27. uint8_t low = buff_size & 0xff;
  28. uint8_t high = (buff_size >> 8);
  29.  
  30. uart_send_byte(0xA0);
  31. uart_send_byte(0xA3);
  32. uart_send_byte(0xB0);
  33. uart_send_byte(0xB3);
  34. uart_send_byte(high);
  35. uart_send_byte(low);
  36. send_buffer(buff_0);
  37. send_buffer(buff_1);
  38. uart_send_byte(0x00);
  39. uart_send_byte(0x00);
  40.  
  41. }
  42.  
  43. void negative_trigger(int channel){
  44.  
  45. int i = 0;
  46.  
  47. //uint8_t channel_0_value = read_adc(0);
  48.  
  49. while ( read_adc(channel) < VT_HI){
  50. continue;
  51. }
  52.  
  53. while ( read_adc(channel) > VT_LO){
  54. continue;
  55. }
  56.  
  57. while (i < BUFF_SIZE)
  58. {
  59. buff_0[i] = read_adc(0);
  60. buff_1[i] = read_adc(1);
  61. i++;
  62. }
  63. UART_SendOscData(buff_0,buff_1,BUFF_SIZE);
  64.  
  65. }
  66.  
  67. void pozitive_trigger(int channel){
  68.  
  69. int i = 0;
  70.  
  71. //uint8_t channel_0_value = read_adc(0);
  72.  
  73. while ( read_adc(channel) > VT_LO){
  74. continue;
  75. }
  76.  
  77. while ( read_adc(channel) < VT_HI){
  78. continue;
  79. }
  80.  
  81. while (i < BUFF_SIZE)
  82. {
  83. buff_0[i] = read_adc(0);
  84. buff_1[i] = read_adc(1);
  85. i++;
  86. }
  87. UART_SendOscData(buff_0,buff_1,BUFF_SIZE);
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94. int main()
  95. {
  96.  
  97. uart_init();
  98. //char ch = 'a';
  99. //char str[50];
  100. //int i = 0;
  101. //uint32_t val;
  102. adc_init();
  103. //uint32_t converted_adch;
  104.  
  105.  
  106.  
  107.  
  108. while (1)
  109. {
  110. negative_trigger(1);
  111. }
  112.  
  113.  
  114.  
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement