Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '--------------------------------------------------------------------------------
- 'name : LIIP9.bas
- 'micro : Mega324pa
- 'suited for demo : yes
- 'commercial addon needed : yes
- '--------------------------------------------------------------------------------
- $regfile = "m324padef.dat"
- $crystal = 3579545
- $hwstack = 40
- $swstack = 16
- $framesize = 32
- '___________________________________________
- 'Ðîçä³ë îá'ÿâëåííÿ çì³ííèõ
- '___________________________________________
- 'Êîíô³ãóðóâàííÿ çîí
- Config Adc = Single , Prescaler = Auto
- Dim Z(8) As Byte
- Dim I As Byte
- Dim Serialcharwaiting As Byte
- Dim Serialchar As Byte
- '___________________________________________
- 'Êîíô³ãóðóâàííÿ s12v
- Config Portc.4 = Output
- S12v Alias Portc.4
- S12v = 1
- '___________________________________________
- 'Êîíô³ãóðóâàííÿ bell
- Config Portc.5 = Output
- 'Bell Alias Portc.5
- '___________________________________________
- 'Êîíô³ãóðóâàííÿ led
- Config Portd.5 = Output
- Led_red Alias Portd.5
- Led_red = 1
- '___________________________________________
- 'Êîíô³ãóðóâàííÿ ðåëå
- Config Portc.3 = Output
- Rel_1 Alias Portc.3
- Config Portc.2 = Output
- Rel_2 Alias Portc.2
- Declare Sub Getline(s As String) '÷òåíèå äàííûõ èç áóôåðà
- Declare Sub Del_buffer() 'î÷èñòêà áóôåðà
- Dim R As Byte
- Dim S As String * 1
- Dim B As Byte
- Dim num As Byte
- Enable Interrupts
- Config Servos = 1 , Servo1 = Portc.5 , Reload = 15
- Servo(1) = 23
- 'Wait 10
- Do
- ' Start Adc
- ' Wait 1
- ' Z(1) = Getadc(7)
- ' Z(2) = Getadc(6)
- ' Z(3) = Getadc(5)
- ' Z(4) = Getadc(4)
- ' Z(5) = Getadc(3)
- ' Z(6) = Getadc(2)
- ' Z(7) = Getadc(1)
- ' Z(8) = Getadc(0)
- ' Stop Adc
- ' Print Z(1) ; " " ; Z(2) ; " " ; Z(3) ; " " ; Z(4) ; " " ; Z(5) ; " " ; Z(6) ; " " ; Z(7) ; " " ; Z(8)
- ' For I = 1 To 8
- ' Print "z" ; I ; "=" ; Z(i)
- ' Waitms 10
- ' Toggle Led_red
- ' Next
- ' For I = 1 To 150
- ' Servo(1) = I
- ' Print "z" ; I ; "=" ; Z(i)
- ' Waitms 100
- ' Next
- 'Servo(1) = 0
- 'Wait 1
- 'Servo(1) = 150
- 'Wait 1
- 'Servo(1) = 170
- 'Wait 1
- 'Servo(1) = 200
- 'Wait 1
- 'Servo(1) = 230
- 'Wait 1
- 'Servo(1) = 256
- 'Wait 1
- 'For I = 90 To 23 Step -1
- ' Servo(1) = I
- ' Print I
- 'Waitms 10
- 'Next
- 'Wait 3
- 'For I = 23 To 90
- ' Servo(1) = I
- ' Print I
- 'Waitms 10
- 'Next
- 'Wait 3
- 'For I = 0 To 100
- ' Servo(1) = I
- 'Waitms 1000
- 'Next
- 'For I = 100 To 0 Step -1
- ' Servo(1) = I
- 'Waitms 1000
- 'Next
- 'Print "hi"'
- R = Ischarwaiting() 'ïðîâåðêà íàëè÷èÿ êîìàíäû â áóôåðå UART
- If R = 1 Then 'åñëè â áóôåðå ÷òî-òî åñòü ïåðåìåííîé R ïðèñâîèòñÿ çíà÷åíèå 1
- Getline S
- num = Val(S) 'âûòàñêèâàåì ñîäåðæèìîå áóôåðà â ïåðåìåííóþ S
- 'If S = "25" Then 'åñëè òàì ñèìâîë "À"
- 'Print "25"
- if num = 23 Then
- rel_2 = 0
- Print "red_toggled_off"
- else
- Servo(1) = num
- end if
- if num = 22 then
- rel_2 = 1
- Print "red_toggled_on"
- else
- Servo(1) = num
- end if
- if num = 55 then
- rel_1 = 1
- Print "red_toggled_on"
- else
- Servo(1) = num
- end if
- if num = 50 then
- rel_1 = 0
- Print "red_toggled_off"
- else
- Servo(1) = num
- end if 'è âêëþ÷èì ñâåòîäèîä
- ' Elseif S = "90" Then 'åñëè òàì ñèìâîë "Â"
- 'Print "90" 'ñîîáùèì î âûêëþ÷åíèè
- ' Servo(1) = 90 'âûêëþ÷àåì ñâåòîäèîä
- ' End If
- Print num
- Del_buffer 'åñëè â áóôåðå ÷òî-òî äðóãîå î÷èùàåì åãî
- End If
- waitms 2000
- Loop
- End
- Sub Getline(s As String)
- S = ""
- Do
- B = Inkey() 'áåðåì ñèìâîë èç áóôåðà â ôîðìàòå ASCII
- Select Case B
- Case 0 : Exit Do 'åñëè äàëüøå áóôåð ïóñò - âûõîäèì èç öèêëà
- Case 10 : If S <> "" Then Exit Do 'êîíåö ñòðîêè, çíà÷èò âûõîäèì èç öèêëà
- Case Else : If B > 31 Then S = S + Chr(b) 'ñîñòàâëÿåì ñòðîêó
- End Select
- Loop
- End Sub
- 'î÷èñòêà áóôåðà UART
- '===================
- Sub Del_buffer()
- Do
- B = Inkey() 'êëàäåì â ïåðåìåííóþ "Â" äàííûå èç áóôåðà
- Loop Until B = 0 'âûõîäèì èç öèêëà êîãäà â ïåðåìåííóþ ïîïàäåò 0 (áóôåð ïóñò)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement