Παρατίθεται ο κώδικας σε Bascom που τρέχει ο μΕ ATMEGA16 για το αυτόματο τρύπημα πλακετών.
'servo
$regfile = "m16def.dat"
$crystal = 8000000
Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Porta.3 = Input
Config Porta.4 = Input
Config Porta.5 = Input
Config Portd.0 = Input
Config Portd.2 = Input
Dim I As Integer
Dim Neutral_position As Integer
Dim Drill_start As Integer
Dim Drill_end As Integer
Dim Drill_speed As Integer
Dim Drill_speed_temp As Single
Dim Temp1 As Single
Dim Temp As Integer
Dim Drill_start_rom As Eram Integer At 14 , Drill_end_rom As Eram Integer At 16 , Drill_speed_rom As Eram Integer At 18
On Int0 Neutral
Config Int0 = Falling
Portd.7 = 1
Waitms 200
Neutral_position = 250
Drill_start = Drill_start_rom
Drill_end = Drill_end_rom
Drill_speed = Drill_speed_rom
Enable Interrupts
Enable Int0
Portd.6 = 0
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Waitms 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Wait 500
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Wait 500
Porta.0 = 0
Porta.1 = 0
Porta.2 = 0
Wait 500
If Pina.5 = 1 Then
Porta.0 = 1
Wait 1
While Pina.5 = 0
If Pina.4 = 1 Then
Drill_start = Drill_start + 1
End If
If Pina.3 = 1 Then
Drill_start = Drill_start - 1
End If
If Drill_start < 375 Then
Drill_start = 375
End If
If Drill_start > 500 Then
Drill_start = 500
End If
Pulseout Portd , 6 , Drill_start
Waitms 18
Wend
Drill_start_rom = Drill_start
Porta.0 = 0
Wait 1
End If
If Pina.5 = 1 Then
Porta.1 = 1
Wait 1
While Pina.5 = 0
If Pina.4 = 1 Then
Drill_end = Drill_end + 1
End If
If Pina.3 = 1 Then
Drill_end = Drill_end - 1
End If
If Drill_end < 380 Then
Drill_end = 380
End If
If Drill_end > 510 Then
Drill_end = 510
End If
Pulseout Portd , 6 , Drill_end
Waitms 18
Wend
Drill_end_rom = Drill_end
Porta.1 = 0
Wait 1
End If
If Pina.5 = 1 Then
Porta.2 = 1
Wait 1
Temp1 = Drill_start
While Pina.5 = 0
If Pina.4 = 1 Then
Drill_speed = Drill_speed + 1
End If
If Pina.3 = 1 Then
Drill_speed = Drill_speed - 1
End If
If Drill_speed < 1 Then
Drill_speed = 0
End If
If Drill_speed > 100 Then
Drill_speed = 100
End If
Drill_speed_temp = Drill_speed / 40
Temp1 = Temp1 + Drill_speed_temp
Temp = Round(temp1)
Pulseout Portd , 6 , Temp
If Temp > Drill_end Then
Temp = Drill_start
Temp1 = Temp
End If
Waitms 18
Wend
Drill_speed_rom = Drill_speed
Wait 1
Porta.2 = 0
End If
Begin:
Do
Portd.6 = 0
While Pind.0 = 0
Pulseout Portd , 6 , Drill_start
Waitms 18
Wend
Temp1 = Drill_start
Portd.6 = 0
Do
Drill_speed_temp = Drill_speed / 40
Temp1 = Temp1 + Drill_speed_temp
Temp = Round(temp1)
Pulseout Portd , 6 , Temp
Waitms 17
Loop Until Temp > Drill_end
Loop
End
Neutral:
Disable Interrupts
Disable Int0
Portd.6 = 0
I = 0
Do
Pulseout Portd , 6 , Neutral_position
Waitms 18
I = I + 1
Loop Until I = 50
Portd.7 = 0
Wait 5
Return
Η pulseout εντολή δημιουργεί τους παλμούς που οδηγούν το servo. Η υπορουτίνα neutral είναι υπεύθυνη για την απομάκρυνση του τρυπανιού από την επιφάνεια όταν μετακινηθεί ο διακόπτης σε θέση Off.
73 de SV1IXP
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου