What's New In SX/B 1.51 7/24/2006 ------------------------------------------------------------------------------- New Definition PIN [INPUT OUTPUT PULLUP NOPULLUP CMOS TTL SCHMITT NOSCHMITT INTR_RISE INTR_FALL] Defines a hardware pin and sets options for the pin. PIN is preferred over using VAR to define pins. PIN also supports whole byte and the pseudo-word ports. OUTPUT - Sets up the pin as an output INPUT - Sets up the pin as an input (default) PULLUP/NOPULLUP - Enable/disables ~20K pullup resistors for the pin (NOPULLUP is default) CMOS/TLL - Sets the pin voltage toggle threshold to Vdd/2 or 1.4V. (1.4V is default) SCHMITT/NOSCHMITT - Enables/disable schmitt trigger for the pin INTR_RISE/INTR_FALL - Enables pin interrupt for rising/falling edge (port B only) Examples: LED PIN RC.0 OUTPUT Switch PIN RC.1 INPUT CMOS ISwitch PIN RB.0 INPUT PULLUP INTR_FALL LEDS PIN RC OUTPUT ' Sets all RC bits to output ------------------------------------------------------------------------------- Conditional Compiling: '{$DEFINE name} '{$UNDEFINE name} '{$IFDEF name} '{$IFNDEF name} '{$ELSE} '{$ENDIF} Conditional compiling allows you have different versions or options in one SX/B program. For example lets say you have a program and sometimes you want to use RB for LED outputs and sometimes you want to use RC. '{$DEFINE USE_RB} ' Remove this line to use RC '{$IFDEF USE_RB} LEDS PIN RB '{$ELSE} LEDS PIN RC '{$ENDIF} ------------------------------------------------------------------------------- New commands: NOP Simply inserts a NOP [ Wow Terry that was a tough one ;) ] ANALOGIN InPin, OutPin, Value[, Prime] Reads an analog input voltage using the continuous calibration method All you need is 2 10K resistors and a 0.01uF capacitor(for 4MHz) or 0.001(for 50MHz) You can experiment with different resistor and/or capacitor values. Don't use resistor values below 220 ohms to protect the SX output pin. The variable Value will get set to the analog voltage at the input with 255 = Supply voltage. So if you get a reading of 127 and the supply voltage is 5 volts, then the input voltage is about 2.5 volts. Note that the input pin needs to be set to CMOS input threshold. By default the sx sets all pins to TTL threshold. The TTL theshold is 1.4Volts. That will make the full scale reading of 255 = 2.8 volts regardless of the supply voltage. The method needs to "prime" the capacitor to get a stable reading. By default the prime value is 1. If you get unstable readings either use a smaller cap value or increase the prime value. Prime must be a constant from 0 to 255. However larger prime values will increase the time it takes to get a reading. The time required to get a reading is 3825*(1+Prime)/Frequency. So with the default prime value of 1, if the clock is 4MHz it will take 3825*2/4000000 seconds or about 1.91 milliseconds to get a reading. For faster clocks either use a smaller cap value or a larger prime value. Note that this circuit has a fairly low input impedence. If you use a pot or resistor divider to create the analog voltage the ANALOGIN command may not reach the limits (0 or 255). A simple test using the 10K pots on the PDB yielded values from 0 to 241. The following is an example program: ------------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 InPin PIN RA.0 INPUT CMOS OutPin PIN RA.1 OUTPUT ' Analog Voltage >---/\/\/\-------+----+------------ SX Read Pin (RA.0) ' 10K | | ' ----- +--/\/\/\---- SX Write Pin (RA.1) ' ----- 10K ' 0.01uF / \ ' | ' | ' GND a VAR Byte PROGRAM Start NOSTARTUP Start: ANALOGIN InPin, OutPin, a, 2 WATCH a BREAK GOTO Start END ------------------------------------------------------------------------------- Fixes: "IF a1(1).7 = 0 THEN" caused an assembly error "a1(1).7 = ~a1(1).7" caused an assembly error "SHIFTOUT MSBFIRST \9..\16" bits not rotated correctly Incorrect error message when a duplicate variable name is used "ON GOTO | GOSUB" "GOTO" and "GOSUB" had to be uppercase "ON GOSUB" error when using defined subroutines