|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Rookie Programmer has question about the default code
Hey guys, I'm taking a look at the code, and I've got a small question. On this part:
Code:
'========== MAIN PROGRAM ===================================================== '============================================================================= '---------- Input & Output Declarations -------------------------------------- Output COMB Input COMA Input COMC Output 7 'define Basic Run LED on RC => out7 Output 8 'define Robot Feedback LED => out8 => PWM1 Green Output 9 'define Robot Feedback LED => out9 => PWM1 Red Output 10 'define Robot Feedback LED => out10 => PWM2 Green Output 11 'define Robot Feedback LED => out11 => PWM2 Red Output 12 'define Robot Feedback LED => out12 => Relay1 Red Output 13 'define Robot Feedback LED => out13 => Relay1 Green Output 14 'define Robot Feedback LED => out14 => Relay2 Red Output 15 'define Robot Feedback LED => out15 => Relay2 Green '---------- Initialize Inputs & Outputs -------------------------------------- Out7 = 1 'Basic Run LED on RC Out8 = 0 'PWM1 LED - Green Out9 = 0 'PWM1 LED - Red Out10 = 0 'PWM2 LED - Green Out11 = 0 'PWM2 LED - Red Out12 = 0 'Relay1 LED - Red Out13 = 0 'Relay1 LED - Green Out14 = 0 'Relay2 LED - Red Out15 = 0 'Relay2 LED - Green |
|
#2
|
|||||
|
|||||
|
I am not the programmer on my team and I have never worked with BASIC stamps, just with Atmel AVRs, which are programmed in assembler, but most microcontrollers have a similar syntax, so here is my explanation:
On microcontrollers, most of the ports (except, for example, for the analog ones) can be either input or output. To tell the controller how you would like to access the port, whether as input or output, you have to define it in teh initialization statements. This can obviously be done by writing 'Output' followed by the port number. From there on, you cann access it by the internal aliases out[port number]. Take this as a temporay help, I bet that someone who knows the BASIC Stamp really well is going to post a reply sometime later this day. Good luck! |
|
#3
|
||||||
|
||||||
|
You should download the Parallax manual (V2.0 is worth getting if you have the older manual -- much clearer in my opinion).
Output is a Pbasic command that makes a pin an output on a Stamp2. What it REALLY does is set a bit in the DIRS word. There are 3 words that you should get to know if you are using Stamp2's a lot (not so much if you only use them for FIRST, but it is still good to know). DIRS is a word that sets the direction of data flow of the I/O pins 0-15 INS is a word that reflects the status of the voltage on the I/O pins 0-15. OUTS is a word that determines the output value of the I/O pins, if DIRS is set to the output state (which I can't recall whether it is a 1 or a 0 off the top of my head). Actually, the Stamp2 can only TRY to set the values to match OUTS, if something else is trying to make it something else, then it is a tug of war and the best man wins. With perhaps one of the battlers broken or wounded ;-) Anyway, Output X sets bit X of DIRS to output status. OUT1 is simply an alias for bit1 of OUTS. It is exactly the same as OUTS.bit1 Hope this helps. Joe J. |
|
#4
|
||||
|
||||
|
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How long does it take you to load the default code? | vegasmcse | Robotics Education and Curriculum | 10 | 03-11-2003 21:41 |
| robot goes haywire with the one joystick default code | Miles | Programming | 7 | 24-01-2003 14:58 |
| Default Robot Code | lvhsrobotics | Programming | 2 | 10-01-2003 16:55 |
| 2003 PBasic default code from Innovation First | ttedrow | Programming | 0 | 06-01-2003 11:18 |
| default code | archiver | 2001 | 2 | 23-06-2002 22:53 |