Bascomexample (E)
Bascomexample (E)
These following programs are based on Bascom Basic , Bascom is basic compiler for AVR and 8051. MCS-Electronics company offer demo version on, http://www.mcselec.com/index.php?option=com_ docman&task=cat_view&gid=98&Itemid=54 The limit of machine code memory is 2K for demo version Bascom . All the following 10 programs can be compiled with demo version Bascom.
Author: chiping Tsao www.letry.com.tw Ex. 3 LED on , off, on, off (0.2 second/each)
Do P1.3 = 0 Waitms 200 P1.3 = 1 Waitms 200 Loop End
Figure 1 Ex. 1
P1.3 = 0 Wait 2 P1.3 = 1 End
Exercise 1 to 5 Ex. 5 LED shine 2 seconds LED on I second , off , on 2 seconds, off, on 3 seconds, off, on 4 seconds, off, on 5 seconds ,off
Dim N As Byte For N = 1 To 5 P1.3 = 0 Wait N P1.3 = 1 Wait 1 Next N End
Figure 2 Ex. 6
Exercise 6,7
This program is the same as exercise 6 Ex. 8 The motor stop if IR detects something.
Ex. 7 LED flashs until infrared sensor detects object, Do P1.3 = 0 Wait 1 P1.3 = 1 Wait 1 Loop Until P1.5 = 1 End
Figure 4 Ex. 9
Exercise 9 ,10 Ex. 10 obstacle Do If P1.2 = 1 Then P1.3 = 1 P1.5 = 1 Wait 2 P1.5 = 0 Wait 1 P1.3 = 0 End If If P1.4 = 1 Then P1.3= 1 P1.5 = 1 Wait 2 P1.3 = 0 Wait 1 P1.5 = 0 End If Loop End Backward 2 seconds then turn if IR detects
Avoid obstacle
The left motor reverses if right IR detects obstacle The right motor reverses if left IR detects obstacle Do If P1.2 = 1 Then P1.3 = 1 Else P1.3 = 0 End If If P1.4 = 1 Then P1.5 = 1 Else P1.5 = 0 End If Loop End