'---------------Title-------------- ' File......active_high.pbp ' Started....7/12/09 ' Microcontroller used: Microchip Technology 16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' PIC turns on an LED when a switch is pressed. ' The switch is wired as an active high. '----------Related Lesson---------- ' active_high.pbp is used in the lesson Source and Sink Outputs / ' Active High and Low Inputs at: ' http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii19_active_high_active_low.pdf '----------PIC Connections--------- ' 16F88 Pin Wiring ' --------- ---------- ' RB0 150 Ohm resistor to LED to GND ' RB1 Active high switch ' RB4 4.7K Resistor to +5 V ' RB5 Ground ' RB14 +5 V '------------Variables------------ switch1 var PORTB.1 ' Labels PORTB.1 as switch1 '-----------Initialization--------- TRISB = %11111110 ' Sets up RB0 pin of PORTB as an output ' and pins RB7-RB1 of PORTB as inputs OSCCON = $60 ' Sets the internal oscillator in the ' 16F88 to 4 MHz '-------------Main Code------------ start: IF switch1 = 1 Then led_on ' If the switch on PORTB.1 is pushed, ' PORTB.1 becomes HIGH (+5 volts) and ' the comparison is true, so the program ' jumps to the label led_on. LOW 0 ' When the comparison is false, the program ' proceeds to the statement after the ' IF..THEN command, in our case, LOW 0. ' This makes pin RB0 output LOW(0 volts) pause 1 ' Pause 1 ms GoTo start ' Jump to loop label led_on: high 0 ' Makes pin RB0 output HIGH(+5 volts) pause 1 ' Pause 1 ms GoTo start ' Jump to loop label End