Komunikacja RS 232

Pytania, kody i porady dotyczące nie tylko Bascom.
Awatar użytkownika
Pikczu
Posty: 392
Rejestracja: 17 sie 2015, 13:46
Lokalizacja: Dublin, Ireland
Kontakt:

Re: Komunikacja RS 232

Post autor: Pikczu » 18 maja 2021, 14:38

Żeby dobrze odbierało musi być bufor.
W zrozumieniu zagadnienia pomoże Ci przykład z folderu sample-> serial.
  1. '-----------------------------------------------------------------------------------------
  2. 'name                     : rs232buffer.bas
  3. 'copyright                : (c) 1995-2020, MCS Electronics
  4. 'purpose                  : example shows the difference between normal and buffered
  5. '                           serial INPUT
  6. 'micro                    : Mega48
  7. 'suited for demo          : yes
  8. 'commercial addon needed  : no
  9. '-----------------------------------------------------------------------------------------
  10.  
  11. $regfile = "m48def.dat"                                     ' specify the used micro
  12. $crystal = 8000000                                          ' used crystal frequency
  13. $baud = 19200                                               ' use baud rate
  14. $hwstack = 32                                               ' default use 32 for the hardware stack
  15. $swstack = 10                                               ' default use 10 for the SW stack
  16. $framesize = 40                                             ' default use 40 for the frame space
  17.  
  18. 'first compile and run this program with the line below remarked
  19. 'Config Serialin = Buffered , Size = 20
  20.  
  21.  
  22. Dim Nm As String * 1
  23.  
  24. 'the enabling of interrupts is not needed for the normal serial mode
  25. 'So the line below must be remarked to for the first test
  26. 'Enable Interrupts
  27.  
  28. Print "Start"
  29. Do
  30.    'get a char from the UART
  31.  
  32.    If Ischarwaiting() = 1 Then                              'was there a char?
  33.       Nm = Waitkey()
  34.       Print Nm                                              'print it
  35.    End If
  36.  
  37.    Wait 1                                                   'wait 1 second
  38. Loop
  39.  
  40. 'You will see that when you slowly enter characters in the terminal emulator
  41. 'they will be received/displayed.
  42. 'When you enter them fast you will see that you loose some chars
  43.  
  44. 'NOW remove the remarks from line 11 and 18
  45. 'and compile and program and run again
  46. 'This time the chars are received by an interrupt routine and are
  47. 'stored in a buffer. This way you will not loose characters providing that
  48. 'you empty the buffer
  49. 'So when you fast type abcdefg, they will be printed after each other with the
  50. '1 second delay
  51.  
  52. 'Using the CONFIG SERIAL=BUFFERED, SIZE = 10 for example will
  53. 'use some SRAM memory
  54. 'The following internal variables will be generated :
  55. '_Rs_head_ptr0   BYTE , a pointer to the location of the start of the buffer
  56. '_Rs_tail_ptr0   BYTE , a pointer to the location of tail of the buffer
  57. '_RS232INBUF0 BYTE ARRAY , the actual buffer with the size of SIZE
Jeśli angielski sprawia Ci trudności użyj google translate.
Następny krok to wklej swój cały kod.
ODPOWIEDZ