Example of BASCOM program : (click here for download)
$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 32
$swstack = 8
$framesize = 16
Const Timervalue = 22 ' 0.025 sec (25msec) @9.6MHz/1024/8bit = 22
Const Minimum_interval = 40 ' 1sec
Const Default_interval = 80 ' 2sec
Const Disable_after = 1200 ' 30sec
Const Wiper_water_delay = 200 ' 5sec
Const Wiper_threshold = 500 ' 500ms (for waitms statement)
Dim Interval As Word
Dim Int_timer1 As Word
Dim Temptimer As Word
Switch Alias Pinb.0 ' switch for time-cycle wipers
Switch_water Alias Pinb.1 ' switch what activate windscreen water cleaners
Relay Alias Portb.3 ' relay for wiper motor
Config Portb.0 = Input
Config Portb.1 = Input
Config Portb.3 = Output
Config Timer0 = Timer , Prescale = 1024
Enable Interrupts
Enable Timer0
Timer0 = Timervalue ' reload Timer0 with interval (25msec)
On Timer0 Timer_int ' set Timer0 interrupt routine
Do
Main:
Gosub Wipe_coff ' turn off wiper motor
Debounce Switch , 1 , Start1 ' if wiper switch is turned on, start default interval
Debounce Switch_water , 1 ,
Wipe_water ' if windscreen clean switch is turned on, start motor
Loop
'-------------------------------------------------------------------------------
Start1:
Interval = Default_interval ' set default interval for wiper timer
Start2:
If Interval <
Minimum_interval Then Goto Wipe_cont ' if wiper interval < than min interval run motor in
continuosly mode
Wipe_start:
Wipe_loop:
Disable Timer0
Int_timer1 = Interval ' set timer to interval
Gosub Wipe_one
Enable Timer0 ' start/stop motor for one wiper cycle
Wipe_loop2:
If Int_timer1 = 0 Then ' if timer goes to 0 , reload timer with interval and make one
wiper cycle
Disable Timer0
Gosub Wipe_one
Int_timer1 = Interval
Enable Timer0
End If
Debounce Switch_water , 1 ,
Wipe_water_pre ' check for windscreen clean switch over wiper timer
Debounce Switch , 0 , Time_loop ' check for turn off wiper switch
Goto Wipe_loop2 ' make loop
'-------------------------------------------------------------------------------
Wipe_cont:
Gosub Wipe_con ' turn on motor - continuosly mode
Wipe_cont2:
Debounce Switch , 0 , Time_loop ' check for wiper switch, if opened go check new interval
Goto Wipe_cont2
'-------------------------------------------------------------------------------
Wipe_water_pre:
Temptimer = Interval ' save current
interval when windscreen clean sw is activated over wiper timer runnig
Wipe_water:
Set Relay ' turn on motor until windscreen clean switch is closed
Debounce Switch_water , 0 ,
Wipe_water1 ' when is opened start time delay for automatic after-clean
Goto Wipe_water
Wipe_water1:
Int_timer1 = Wiper_water_delay ' load timer with after-clean time value
Wipe_water2:
If Int_timer1 = 0 Then Goto Wipe_water3 ' if timer goes to 0 turn off motor
Goto Wipe_water2
Wipe_water3:
Reset Relay ' turn off wiper motor
If Temptimer <> 0 Then ' check for saved interval from wiper , if is set, reload timer
with old value
Disable Timer0
Int_timer1 = Temptimer ' and restart wiper timer
Temptimer = 0
Enable Timer0
Goto Start2
End If
Goto Main ' if saved timer not exist jump to main loop
'-------------------------------------------------------------------------------
Time_loop: ' time loop for get new wiper interval or reset timer when time
exceed 30sec
Gosub Wipe_coff
Disable Timer0
Int_timer1 = Disable_after ' load timer with maximum interval (30sec)
Enable Timer0
Time_loop2:
Debounce Switch , 1 , Time_loop3 ' check for wiper switch closed,if is closed set new interval
If Int_timer1 = 0 Then Goto Main ' if time
period is over and wiper switch is not closed, run program from begin
Debounce Switch_water , 1 ,
Wipe_water ' check for windscreen clean switch
Goto Time_loop2
Time_loop3:
Disable Timer0
Interval = Disable_after - Int_timer1 ' get new
interval for wiper
Enable Timer0
Goto Start2 ' run wiper program from begin but ignore setting of default
interval
'-------------------------------------------------------------------------------
Timer_int: ' Timer0 interrupt routine
Timer0 = Timervalue 'reload Timer0
If Int_timer1 = 0 Then Return ' if timer is not set do nothing
Int_timer1 = Int_timer1 - 1 ' else decrement it over each interrupt
Return
'-------------------------------------------------------------------------------
Wipe_one: ' routine for start/stop wiper motor
Set Relay ' start motor
Waitms Wiper_threshold ' wait 500ms, needed for activating self-motor automatic
Reset Relay ' turn off motor (motor automaticly return wipers to start
position)
Return
Wipe_con: ' activate wiper motor for continuosly mode
Set Relay
Return
Wipe_coff: ' turn off wiper motor
Reset Relay
Return
/Tomi - MCS Electronics