0% found this document useful (0 votes)
47 views3 pages

Bascomexample (E)

This document provides 10 programming examples for controlling LEDs and motors using an infrared sensor with the Bascom Basic compiler. The examples demonstrate turning an LED on and off in various patterns, flashing an LED until an object is detected by the infrared sensor, and stopping or reversing a motor if the infrared sensor detects an object. All of the examples can be compiled using the demo version of the Bascom Basic compiler, which has a 2k memory limit for machine code.

Uploaded by

Marco Ant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Bascomexample (E)

This document provides 10 programming examples for controlling LEDs and motors using an infrared sensor with the Bascom Basic compiler. The examples demonstrate turning an LED on and off in various patterns, flashing an LED until an object is detected by the infrared sensor, and stopping or reversing a motor if the infrared sensor detects an object. All of the examples can be compiled using the demo version of the Bascom Basic compiler, which has a 2k memory limit for machine code.

Uploaded by

Marco Ant
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BASIC +89C2051-12 + Letry robot

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

Ex. 4 LED on..off..on..off.. (5 cycles)


Dim N As Byte For N = 1 To 5 P1.3 = 0 Wait 1 P1.3 = 1 Wait 1 Next N 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

Ex. 2 LED on , off , on , off .(1 second/each)


Do P1.3 = 0 Wait 1 P1.3 = 1 Wait 1 Loop End

Figure 2 Ex. 6

Exercise 6,7

LED shine if Infrared sensor detects object. Figure 3 Exercise 8

Do If P1.5 = 1 Then P1.3 = 0 Else P1.3 = 1 End If Loop End

This program is the same as exercise 6 Ex. 8 The motor stop if IR detects something.

Do If P1.5 = 1 Then P1.3 = 0 Else P1.3 = 1 End If Loop End

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

You might also like