Qbasic, Quickbasic/RAM program

Advertisement


Question
I have no clue on how to do this RAM program.
Write a program that lets the LED turn on one a time (15 leds) in chronological order and then go backwards. Therefore 15 locations need to be wirtten to and read from. the program must run in a loop.
a sample how the ram works
Out 890, 9 XOR 11
Out 890, 13 XOR 11
Out 890, 9 XOR 11
Out 888, 2^0
Out 890,8 XOR 11
Out 890, 9 XOR 11
Out 890, 11 XOR 11
Out 890, 9 XOR 11


Answer
Hi, Jon,

I haven't tinkered with this sort of thing (LEDs...probably through the parallel port?), but I think I can guide you in the right direction

Right now, I'm assuming that the code given lights up 1 of the LEDs.

So, I'm going to assume this:
1. the first 3 OUT 890 statments prepare the LED
2. the out 888 selects the particular LED you want
3. The remaining OUT statements reset the system for the next LED

If this is true, this will probably work:

declare sub toggleLED( n as integer )

dim i as integer
' Turn on LEDs
for i = 1 to 15
 toggleLED( i )
next i
' Turn off LEDs in reverse
for i = 15 to 1 STEP -1
 toggleLED( i )
next i
end 0

sub toggleLED( n as integer )
 DIM id AS INTEGER
 id = n - 1
 Out 890, 9 XOR 11
 Out 890, 13 XOR 11
 Out 890, 9 XOR 11
 Out 888, 2^( id )
 Out 890,8 XOR 11
 Out 890, 9 XOR 11
 Out 890, 11 XOR 11
 Out 890, 9 XOR 11
end sub

CAUTION: before you test that code out, have your teacher double check it.  With an improper OUT statement, it can either buffer up the parallel port, or the whole computer.  It is very important to double check all any OUT statement code.

If that doesn't help you out, on this section of allexperts, Don may be able to help you more - I'm pretty sure he's had more experience in this area than myself.

Hope that points you in the right direction,
-Alex

Qbasic, Quickbasic

All Answers


Answers by Expert:


Ask Experts

Volunteer


Alex Barry

Expertise

I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

Experience

I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future. Currently, I am only active on the QB64.net forums, but I appear on occasion on FreeBASIC.net's forums as well.

Education/Credentials
Highschool - 2007

©2012 About.com, a part of The New York Times Company. All rights reserved.