Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple BASIC example

Status
Not open for further replies.

Nigel Goodwin

Super Moderator
Most Helpful Member
I've mentioned a few times that I wrote a simple BASIC compiler as part of WinPicProg, and while I was looking for some assembly code for another thread (16F1827 - clearing GPR's), I came across a practical example.

Fairly 'famously' at Matlock Bath (near where I work) they do yearly Illuminations, including rowing boats on the river - these are decorated extensively, pirate ships, space ships. all kinds of things, and a large part of it is the lighting, flashing, sequencing etc. Generally it was done using those old motor driver cams with micro-switches.

Anyway, a guy at work used to enter, and he asked if I could build him something 'better' to control his lights - so I built a simple PIC16F628 feeding 8 driver transistors with open collectors, which switched bulbs fed from the 12V car battery used for power.

Then as at the time I was playing with my BASIC compiler, I wrote the code using that, rather than bothering with assembler.

This code is actually the second version, from 2005, the first was from 2003, the only difference was in the number of steps and sequencing to match his requirements for that years model.

As is obvious, it took VERY little time to write, and it's VERY simple to modify to meet his requirements each year.

Device 16F628
Freq=4

Data 4, 200, 2, 200, 1, 200, 2, 200, 4, 200, 2, 200, 1, 200, 2, 200, 4, 200, 2, 200 ,1 Data 200, 2, 200 ,4, 200

Data 2, 200, 1, 200, 2, 200, 4, 200, 5, 200, 2, 200, 5, 200, 2, 200, 5, 200, 2, 200 ,5 Data 200, 2, 200 ,5, 200

Dim A, CL, B
Define PortB=%00000000
Loop:
For CL=1 To 52
Read A
Read B
B=B*10
OutB(A)
DelayMS(B)
Next CL
Restore 0
Goto Loop
Stop
End
 
If anyone would like to try Basic on PIC microcontrollers, allow me to recommend Swordfish Basic. It runs on PIC18F series micros and compiles fast, efficient code. It's similar to using Visual Basic 6.

Swordfish SE (Special Edition) is the free trial version with such generous limits that many people never upgrade to the paid version.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top