Advertisement
Guest User

Untitled

a guest
May 21st, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $regfile = "m8def.dat"
  2. $crystal = 1000000
  3.  
  4. Config Portb = &B011111111 : Portb = &B00000000
  5. Config Portc = &B00000000 : Portc = &B00000000
  6. Config Portd = &B11111101
  7.  
  8. Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
  9.  
  10. Config Pind.1 = Input
  11. Config Portd.7 = Output                                     'mostek
  12. Config Portd.6 = Output                                     'mostek
  13. Config Portd.5 = Output                                     'mostek
  14. Config Portd.4 = Output                                     'mostek
  15.  
  16.  
  17. Mset1b Alias Portd.4
  18. Mset1a Alias Portd.5
  19.  
  20. Mset2a Alias Portd.6
  21. Mset2b Alias Portd.7
  22.  
  23. Dioda_zielona Alias Portd.2
  24. Dioda_czerwona Alias Portd.3
  25. Przycisk Alias Pind.1
  26.  
  27. Dim Tcrt1 As Word                                           'prawy czujnik linii (patrzac na tyl robota)
  28. Dim Tcrt2 As Word
  29.  
  30. Dim V1 As Byte
  31. Dim V2 As Byte
  32.  
  33. Pwm1a = 0                                                   'silnik prawy (patrząc na tyl robota) - wypelnienie PWM
  34. Pwm1b = 0
  35.  
  36. Dim Flag As Byte
  37. Set Dioda_czerwona
  38. Set Dioda_zielona
  39.  
  40.    Do
  41.       Waitms 200
  42.       If Przycisk = 0 Then
  43.  
  44.          Flag = 1
  45.          Set Dioda_zielona
  46.       End If
  47.       If Flag = 1 Then
  48.          Set Dioda_czerwona
  49.         Gosub Odczytadc
  50.  
  51.         Set Mset1a : Reset Mset1b
  52.         Set Mset2a : Reset Mset2b
  53.  
  54.         Pwm1a = V1
  55.         Pwm1b = V2
  56.  
  57.         Waitms 500
  58.       End If
  59.       Reset Dioda_zielona
  60.       Reset Dioda_czerwona
  61.    Loop
  62.  
  63. End
  64.  
  65.  
  66. Odczytadc:
  67.    Start Adc
  68.  
  69.    Tcrt1 = Getadc(2)                                        'PC.2
  70.    Tcrt2 = Getadc(3)
  71.    If Tcrt1 > 255 Then
  72.       V1 = 255
  73.    Else
  74.       V1 = Tcrt1
  75.    End If
  76.    If Tcrt2 > 255 Then
  77.       V2 = 255
  78.    Else
  79.       V2 = Tcrt2
  80.    End If                                                    'PC.3
  81.  
  82.    Stop Adc
  83. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement