Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '--------------------------------------------------------------------------------
  2.  
  3. 'name                     : LIIP9.bas
  4.  
  5. 'micro                    : Mega324pa
  6.  
  7. 'suited for demo          : yes
  8.  
  9. 'commercial addon needed  : yes
  10.  
  11. '--------------------------------------------------------------------------------
  12.  
  13. $regfile = "m324padef.dat"
  14. $crystal = 3579545
  15. $hwstack = 40
  16. $swstack = 16
  17. $framesize = 32
  18.  
  19. '___________________________________________
  20. 'Ðîçä³ë îá'ÿâëåííÿ çì³ííèõ
  21.  
  22.  
  23. '___________________________________________
  24. 'Êîíô³ãóðóâàííÿ çîí
  25. Config Adc = Single , Prescaler = Auto
  26. Dim Z(8) As Byte
  27. Dim I As Byte
  28. Dim Serialcharwaiting As Byte
  29. Dim Serialchar As Byte
  30.  
  31. '___________________________________________
  32. 'Êîíô³ãóðóâàííÿ s12v
  33. Config Portc.4 = Output
  34. S12v Alias Portc.4
  35. S12v = 1
  36. '___________________________________________
  37. 'Êîíô³ãóðóâàííÿ bell
  38. Config Portc.5 = Output
  39. 'Bell Alias Portc.5
  40.  
  41. '___________________________________________
  42. 'Êîíô³ãóðóâàííÿ led
  43. Config Portd.5 = Output
  44. Led_red Alias Portd.5
  45. Led_red = 1
  46.  
  47.  
  48. '___________________________________________
  49. 'Êîíô³ãóðóâàííÿ ðåëå
  50. Config Portc.3 = Output
  51. Rel_1 Alias Portc.3
  52. Config Portc.2 = Output
  53. Rel_2 Alias Portc.2
  54.  
  55. Declare Sub Getline(s As String)            '÷òåíèå äàííûõ èç áóôåðà
  56. Declare Sub Del_buffer()                    'î÷èñòêà áóôåðà
  57.  
  58. Dim R As Byte
  59. Dim S As String * 1
  60. Dim B As Byte
  61. Dim num As Byte
  62.  
  63. Enable Interrupts
  64.  
  65. Config Servos = 1 , Servo1 = Portc.5 , Reload = 15
  66. Servo(1) = 23
  67. 'Wait 10
  68. Do
  69.  
  70. '   Start Adc
  71. '   Wait 1
  72. '   Z(1) = Getadc(7)
  73. '   Z(2) = Getadc(6)
  74. '   Z(3) = Getadc(5)
  75. '   Z(4) = Getadc(4)
  76. '   Z(5) = Getadc(3)
  77. '   Z(6) = Getadc(2)
  78. '   Z(7) = Getadc(1)
  79. '   Z(8) = Getadc(0)
  80. '   Stop Adc
  81. '   Print Z(1) ; " " ; Z(2) ; " " ; Z(3) ; " " ; Z(4) ; " " ; Z(5) ; " " ; Z(6) ; " " ; Z(7) ; " " ; Z(8)
  82. '   For I = 1 To 8
  83. '      Print "z" ; I ; "=" ; Z(i)
  84. '      Waitms 10
  85. '      Toggle Led_red
  86. '   Next
  87. '   For I = 1 To 150
  88. '   Servo(1) = I
  89. '      Print "z" ; I ; "=" ; Z(i)
  90. '      Waitms 100
  91. '   Next
  92. 'Servo(1) = 0
  93. 'Wait 1
  94. 'Servo(1) = 150
  95. 'Wait 1
  96. 'Servo(1) = 170
  97. 'Wait 1
  98. 'Servo(1) = 200
  99. 'Wait 1
  100. 'Servo(1) = 230
  101. 'Wait 1
  102. 'Servo(1) = 256
  103. 'Wait 1
  104. 'For I = 90 To 23 Step -1
  105. '    Servo(1) = I
  106. '    Print I
  107. 'Waitms 10
  108. 'Next
  109. 'Wait 3
  110. 'For I = 23 To 90
  111. '    Servo(1) = I
  112. '    Print I
  113. 'Waitms 10
  114. 'Next
  115. 'Wait 3
  116. 'For I = 0 To 100
  117.  
  118. ' Servo(1) = I
  119.  
  120. 'Waitms 1000
  121.  
  122. 'Next
  123.  
  124.  
  125.  
  126. 'For I = 100 To 0 Step -1
  127.  
  128. '  Servo(1) = I
  129.  
  130. 'Waitms 1000
  131. 'Next
  132. 'Print "hi"'
  133.  
  134.  
  135.  
  136. R = Ischarwaiting()     'ïðîâåðêà íàëè÷èÿ êîìàíäû â áóôåðå UART
  137.  If R = 1 Then          'åñëè â áóôåðå ÷òî-òî åñòü ïåðåìåííîé R ïðèñâîèòñÿ çíà÷åíèå 1
  138.   Getline S
  139.     num = Val(S)                    'âûòàñêèâàåì ñîäåðæèìîå áóôåðà â ïåðåìåííóþ S
  140.    'If S = "25" Then                                        'åñëè òàì ñèìâîë "À"
  141.     'Print "25"
  142.     if num = 23 Then
  143.      rel_2 = 0
  144.     Print "red_toggled_off"
  145.     else
  146.     Servo(1) = num
  147.     end if
  148.  
  149.     if num = 22 then
  150.     rel_2 = 1
  151.     Print "red_toggled_on"
  152.     else
  153.     Servo(1) = num
  154.     end if
  155.  
  156.     if num = 55 then
  157.     rel_1 = 1
  158.     Print "red_toggled_on"
  159.     else
  160.     Servo(1) = num
  161.     end if
  162.  
  163.     if num = 50 then
  164.     rel_1 = 0
  165.     Print "red_toggled_off"
  166.     else
  167.     Servo(1) = num
  168.     end if                                     'è âêëþ÷èì ñâåòîäèîä
  169.   ' Elseif S = "90" Then                                     'åñëè òàì ñèìâîë "Â"
  170.     'Print "90"                                              'ñîîáùèì î âûêëþ÷åíèè
  171. '    Servo(1) = 90                                           'âûêëþ÷àåì ñâåòîäèîä
  172.   ' End If
  173.   Print num
  174.   Del_buffer            'åñëè â áóôåðå ÷òî-òî äðóãîå î÷èùàåì åãî
  175.  End If
  176.  
  177.  
  178.  
  179. waitms 2000
  180.  
  181. Loop
  182. End
  183.  
  184. Sub Getline(s As String)
  185. S = ""
  186. Do
  187.  B = Inkey()                                                'áåðåì ñèìâîë èç áóôåðà â ôîðìàòå ASCII
  188.  Select Case B
  189.   Case 0 : Exit Do                        'åñëè äàëüøå áóôåð ïóñò - âûõîäèì èç öèêëà
  190.   Case 10 : If S <> "" Then Exit Do       'êîíåö ñòðîêè, çíà÷èò âûõîäèì èç öèêëà
  191.   Case Else : If B > 31 Then S = S + Chr(b)    'ñîñòàâëÿåì ñòðîêó
  192.  End Select
  193. Loop
  194. End Sub
  195.  
  196. 'î÷èñòêà áóôåðà UART
  197. '===================
  198. Sub Del_buffer()
  199.  Do
  200.  B = Inkey()               'êëàäåì â ïåðåìåííóþ "Â" äàííûå èç áóôåðà
  201.  Loop Until B = 0          'âûõîäèì èç öèêëà êîãäà â ïåðåìåííóþ ïîïàäåò 0 (áóôåð ïóñò)
  202. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement