'****************************************************************
$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\Display_.inc"
$include "Subs\Hold_stepper.inc"
$include "Subs\Left_stepper.inc"
$include "Subs\Right_stepper.inc"
'$include "Subs\LCD_ST7920_seriell_declare.inc"
'$include "Subs\LCD_ST7920_seriell_sub.inc"
'****************************************************************
'KONFIGURACJA TIMER'ÓW
Config Timer0 = Timer , Prescale = 8
Config Timer1 = Timer , Prescale = 8
On Timer1 Przertimer1
Enable Timer1
Config Timer2 = Timer , Prescale = 8
On Timer2 Step_
Enable Timer2
'Config Timer1 = Pwm , Pwm = 8 , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_down , Prescale = 1
'Config Timer2 = Pwm , Compare_a_pwm = Clear_up , Compare_b_pwm = Clear_up , Prescale = 1024
'Enable Timer2
'****************************************************************
Enable Interrupts
'****************************************************************
' *** PINY ****
' LCD ST9720 ATMEGA LCD 12864ZW-10 ESD4K
' RS (4) - PORTD.7 SPI ---> SS
' R/W (5) - PORTB.0 SPI ---> MOSI
' EN (6) - PORTB.1 SPI ---> SCK
' PBS (15) -GROUND GND
' RST (17) - reset processor RESET
'****************************************************************
'KONFIGURACJA PORTÓW
Config portb.0 = Output : portb.0 = 1 'Laser ON/OFF
Config Portb.1 = output : portb.1 = 1 'Light ON/OFF '
Config portb.2 = Output : portb.2 = 1 'PWM Spindle Motor
Config Portb.3 = Output : portb.3 = 1 'Dir Spindle Motor
Config Portb.4 = Input : pinb.4 = 1 'Encoder Sw
Config Portb.5 = Output : Portb.5 = 0 'LED_LIVE
Config portd.2 = Output : portd.2 = 1 'Dir Stepper Motor
Config portd.3 = Output : portd.3 = 1 'Step Stepper Motor
Config portd.4 = Output : portd.4 = 1 'Enable Spindle Motor
Config portd.5 = Output : portd.5 = 1 'Enable Stepper Motor
Config portd.6 = Input : pind.6 = 1 'Sw start
Config Portc.0 = Input : pinc.0 = 1 'Sw up
Config portc.1 = Input : pinc.1 = 1 'Sw down
Config portc.2 = Input : pinc.2 = 1 'Encoder A
Config portc.3 = Input : pinc.3 = 1 'Encoder B
'****************************************************************
'ALIASY PORTÓW
PWM_spindle Alias Portb.2 'PWM Spindle Motor
Dir_spindle Alias portb.3 'Dir Spindle Motor
Sw_enc Alias pinb.4 'Encoder Sw
Led_live Alias Portb.5 'LED shows that the microcontroller did not hang
Dir_stepper Alias portd.2 'Dir Stepper Motor
Step_stepper Alias portd.3 'PWM Stepper Motor
Ena_spindle Alias portd.4 'Enable Spindle Motor
Ena_stepper Alias portd.5 'EnableStepper Motor
Sw_start Alias pind.6 'cycle start button
Sw_up Alias pinc.0 'upper limit switch
Sw_down Alias pinc.1 'lower limit switch
A_enc Alias pinc.2 'channel A encoder
B_enc alias pinc.3 'channel B encoder
Laser Alias Portc.4 'Laser ON/OFF
Light Alias Portc.5 'Light ON/OFF
'****************************************************************
'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
'****************************************************************
'ZMIENNE
Dim Enc_help As Byte
Dim Sw_enc_help As Byte
Dim Stepper_speed As Word
Dim Spindle_speed As Byte
'****************************************************************
Waitms 500
'****************************************************************
'USTAWIENIA POCZATKOWE
Stepper_speed = 0
'****************************************************************
'PĘTLA GŁÓWNA
'****************************************************************
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
Flaga10ms = 0
End If
If Flaga100ms = 1 Then 'co 100ms
If Sw_enc = 0 Then
Toggle Dir_stepper
End If
Flaga100ms = 0 'wyzeruj Flaga100ms
End If
If Flaga1s = 1 Then 'co 1 sekundę
Call Blink_
Print "DIR STEPPER " ; Dir_stepper
Print "ENABLE STEPPER " ; Ena_stepper
Print "STEP STEPPER " ; Timer2
If Sw_up = 0 Then
Print "WRZECIONO U GORY"
End If
If Sw_down = 0 Then
Print "WRZECIONO NA DOLE"
End If
If Sw_start = 0 Then
Print "START CYKLU"
End If
'Call Display_
Flaga1s = 0
End If
If Flaga2s = 1 Then 'co2s
Flaga2s = 0
End If
'****************************************************************
If Sw_up = 0 Then
Call Hold_stepper
End If
If Sw_start = 0 Then
Call Left_stepper
End If
If Sw_down = 0 Then
Call Right_stepper
End If
'****************************************************************
Loop
'****************************************************************
End
'****************************************************************
'PODPROGRAM PRZERWAŃ TIMER1
Przertimer1:
Timer1 = 45536 'wstawienie do Timer1 wartości 45536
Incr Timer_tikx10
If Timer_tikx10 = 1 Then
Set Flaga10ms
End If
Return
'****************************************************************
Step_:
Timer2 = Stepper_speed
Toggle Step_stepper
Return
'****************************************************************