La programmation
La programmation se fait en basic avec le logiciel BASCOM AVR (version d'évaluation). Le fichier HEX n'occupe que 2 Ko. ce logiciel est disponible sur le site de MCS electronics.
Le microcontrôleur se programme aisément en Icsp, j'utilise un programmateur USB pour AVR de Mikroelectronika, voir la page de programmation.
Le programme utilise l'entrée de comparaison PB1 et règle le registre. Les servos sont mis en rotation avec 2 vitesses différentes en fonction de la source de lumière. Le robot avance en louvoyant. Si un interrupteur est actionné ( obstacle ), le programme exécute une routine d'évitement.
' Robot chercheur de lumière
' JMD 19/01/2026
$regfile = "2313DEF.dat"
Dim T As Integer
Ddrb.0 = 0 'Comparateur Diode Pin
Ddrb.1 = 0 'Comparateur référence
Ddrb.2 = 1 'Led 1
Ddrb.3 = 1
Ddrb.4 = 1 'Led 2
Ddrd.0 = 1 'Servo 1
Ddrd.1 = 1 'Servo 2
Ddrd.4 = 0 'Inter 1
Ddrd.5 = 0 'Inter 2
For T = 0 To 4
Portb.2 = 0
Portb.3 = 1
Waitms 300
Portb.3 = 0
Portb.2 = 1
Sound Portb.4 , 50 , 4000
Waitms 300
Next T
Config Servos = 2 , Servo1 = Portd.0 , Servo2 = Portd.1 , Reload = 10
Enable Interrupts
$crystal = 8000000
Portd.4 = 1
Portd.5 = 1
' Servo (1) = 80, Servo(2)=170 Marche avant
Do
If Pind.5 = 0 Then Gosub Retourd
If Pind.4 = 0 Then Gosub Retourg
If Acsr.5 = 1 Then ' Bit 5 Registre comparateur
Servo(1) = 80
Servo(2) = 170
Portb.2 = 1
Portb.3 = 0
Waitms 50
Servo(1) = 170
Servo(2) = 170
Waitms 20
Else
Servo(1) = 80
Servo(2) = 170
Portb.2 = 0
Portb.3 = 1
Waitms 50
Servo(2) = 80
Servo(1) = 80
Waitms 20
End If
Loop
Retourd:
Servo(1) = 170
Servo(2) = 80
Sound Portb.4 , 100 , 250
Waitms 300
Servo(1) = 80
Portb.2 = 1
Portb.3 = 0
Waitms 250
Return
Retourg:
Servo(1) = 170
Servo(2) = 80
Sound Portb.4 , 100 , 250
Waitms 300
Servo(2) = 170
Portb.2 = 1
Portb.3 = 0
Waitms 250
Return
|