;Program: LED_1.BAS

;This program continuosly reads the input on two pins and flashes an 
;LED on D4 at four different speeds depending on the inputs on D0 
;and D1. 

;copyright Locksley Haynes Morgan State University Oct. 3, 1997

;******TICKIT Library and Device declarations**********************
DEF tic62_b
LIB fbasic.lib
LIB constrin.lib

;******Define input and output pins********************************
DEF LED_PIN pin_D4      ;output pin to LED in series with 330 Ohms
DEF IN_ONE  pin_D1      ;DATA1 pin for the input.  
DEF IN_ZERO  pin_D0     ;DATA0 pin for the input

;Use 10K pullup resistors to +5V on inputs.

;*******************************Main function***********************
FUNC none main
  LOCAL word speed 0w   ;The speed for flashing the LED
  LOCAL byte input 0b   ;The user input 
BEGIN
   
   REP    ;Continuosly read in speed and flash.

     =(input, and( pin_in( IN_ONE ), 1b))         ;read pin_D1
     =(input, <<(input))                              ;make space for
LSB
     =(input, or(input, and(pin_in( IN_ZERO ), 1b)))   ;read pin_D0
     =(speed, to_word(input)) 
     =(speed, /(0d1000w,+(speed, 1w)))  ;calculate speed
  
     pin_high(LED_PIN)        ;blink LED
     delay(speed)
     pin_low(LED_PIN)
     delay(speed)
   LOOP
ENDFUN
  
;********************************************************************