'****************************************************************
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 128
$baud = 115200
$eepleave
Config Submode = New
'****************************************************************
'KONFIGURACJA PORTU COM
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 128
Config Serialout = Buffered , Size = 128
Enable Serial
'****************************************************************
'Debug Off
Debug On
'****************************************************************
$include "Subs\Blink_.inc"
$include "Subs\Read_adc.inc"
$include "Subs\Rotate_left.inc"
$include "Subs\Rotate_right.inc"
$include "Subs\Rotate_stop.inc"
'****************************************************************
'KONFIGURACJA TIMER'OW
'Config Timer0 = Pwm , Compare_A_Pwm = Clear_up , Compare_B_Pwm = Clear_up , Prescale = 1024 'motor travel
Config TIMER2 = Pwm , Compare_B_Pwm = Clear_up , Prescale = 1024 'motor rotation
Config Timer1 = Timer , Prescale = 8
On Timer1 Przer_timer1
'Start Timer2
Enable Timer1
'****************************************************************
'KONFIGURACJA PORTOW
Config Portb.3 = Output : portb.3 = 0 'PWM rotation Motor OC2A
Config portd.3 = Output : portd.3 = 0 'PWM rotation Motor OC2B
Config Portd.6 = Output : portd.6 = 1 'PWM travel Motor OC0A
Config Portd.5 = Output : portd.5 = 1 'PWM travel Motor OC0B
Config Portb.5 = Output : Portb.5 = 0 'LED_LIVE
Config Portc.2 = Input : pinc.2 = 1 'Sw rotate left
Config portc.3 = Input : pinc.3 = 1 'Sw rotate right
Config portc.6 = Input : pinb.0 = 1 'Sw travel left
Config portd.7 = Input : pind.7 = 1 'Sw travel right
Config Portd.2 = Input : Pind.2 = 1 'limit left travel
Config Portd.4 = Input : Pind.4 = 1 'limit right travel
'****************************************************************
'ADC0 poti PWM rotation Motor
'ADC1 poti PWM travel Motor
Config ADC = Single , Prescaler = Auto , Reference = Avcc
'Start ADC
'****************************************************************
'ALIASY PORTOW
PWM_rot_left Alias Portb.3 'PWM rotation Motor OC2A
PWM_rot_right Alias Portd.3 'PWM rotation Motor OC2B
PWM_trav_left Alias Portd.6 'PWM travel Motor OC0A
PWM_trav_right Alias Portd.5 'PWM travel Motor OC0B
Led_live Alias Portb.5 'LED shows that the microcontroller did not hang
Sw_rot_left Alias Pinc.2 'Sw rotate left
Sw_rot_right Alias Pinc.3 'Sw rotate right
Sw_trav_left Alias Pinb.0 'Sw travel left
Sw_trav_right Alias Pind.7 'Sw travel right
Limit_left_trv Alias pind.2 'limit left travel
Limit_right_trv Alias pind.4 'limit right travel
'****************************************************************
'ZMIENNE CZASU
Dim Timer_tikx10 As Byte 'variable counting timer overflow
Dim Timertikx100 As Byte
Dim Timertikx200 As Byte
Dim Timer_tik_flag As Byte
Flaga10ms Alias Timer_tik_flag.0
Flaga100ms Alias Timer_tik_flag.1
Flaga500ms Alias Timer_tik_flag.2
Flaga1s Alias Timer_tik_flag.3
Flaga2s Alias Timer_tik_flag.4
Flaga2_5s Alias Timer_tik_flag.5
'zostaly jeszce trzy wolne flagi
' a uzylem tylko jednego bajtu
' Paweł - pikczu
Dim Timer0_tik_flag As Byte
Flaga4ms Alias Timer0_tik_flag.6
'****************************************************************
'STALE
'****************************************************************
'ZMIENNE
Dim ADC_Read As Word
Dim Sw_cnt As Byte
Dim Lock As Byte
Dim ADC_rotate As Word
Dim PWM_rotate As Word
'****************************************************************
Enable Interrupts
'****************************************************************
Waitms 500
Cls
'****************************************************************
'USTAWIENIA POCZATKOWE 'INITIAL SETTINGS
Stop timer2
'Portb.3 = 0 'dla testu
'****************************************************************
Cls
Print "PROGRAM TESTOWY"
Print "NAPĘDU LASERA"
Print "KRZYŻOWEGO"
Waitms 250
'****************************************************************
'PETLA GLOWNA 'MAIN LOOP
'****************************************************************
Do
'****************************************************************
If Timer_tikx10 >= 10 Then 'jesli uplynelo 100ms to
Flaga100ms = 1 'ustaw flage uplynelo 100ms
Incr Timertikx100
Timer_tikx10 = 0 ''zeruj liczenie
End If
If Timertikx100 >= 10 Then 'jesli uplynela sekunda
Flaga1s = 1 'ustaw flage sekundy
Incr Timertikx200
Timertikx100 = 0 'zeruj liczenie
End If
If Timertikx200 >= 2 Then
Flaga2s = 1
Timertikx200 = 0
End If
'****************************************************************
If Flaga10ms = 1 Then
If Sw_rot_left = 0 Then
Call Rotate_left
End If
If Sw_rot_right = 0 Then
Call Rotate_right
End If
If Sw_rot_left = 1 And Sw_rot_right = 1 Then
Call Rotate_stop
End If
'****************************************************************
Flaga10ms = 0
End If
'***************************************************************
If Flaga100ms = 1 Then 'co 100ms
Call Read_adc
Flaga100ms = 0 'wyzeruj Flaga100ms
End If
'****************************************************************
If Flaga1s = 1 Then 'co 1 sekundę
Call Blink_
Print "ADC_rotate " ; ADC_rotate
Print "PWM2B " ; PWM2b
Print "PWM_rotate " ; PWM_rotate
Print "---------------------------------------"
If Sw_rot_left = 0 Then
Print "OBR_LEWO"
End If
If Sw_rot_right = 0 Then
Print "OBR_PRAWO"
End If
If Sw_rot_left = 0 And Sw_rot_right = 0 Then
Print "STOP"
End If
Flaga1s = 0
End If
'****************************************************************
If Flaga2s = 1 Then 'co2s
Flaga2s = 0
End If
'****************************************************************
PWM_rotate = ADC_rotate / 4
'**************************************************************
Loop
End
'****************************************************************
'PODPROGRAM PRZERWAŃ TIMER1
Przer_timer1:
Timer1 = 45536 'wstawienie do Timer1 wartości 45536
Incr Timer_tikx10
If Timer_tikx10 = 1 Then
Set Flaga10ms
End If
Return
'****************************************************************