'--------Title-------- ' File......switch1.pbp ' Started....6/1/05 ' Microcontroller used: Microchip Technology 16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Turn on/off LED's with button switch. '----------Related Lesson---------- ' switch1.pbp is used in the lesson PIC PROGRAMMING 3 SERVOS at: ' http://cornerstonerobotics.org/curriculum/lessons_year2/erii13_pic_programming3_servos.pdf ' switch1.pbp is also used in the ' lesson ACTIVE HIGH ACTIVE LOW at: ' http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii19_active_high_active_low.pdf '----New PicBasic Pro Commands----- ' The PicBasic Pro Compiler Manual is on line at: ' http://www.microengineeringlabs.com/resources/index.htm#Manuals ' IF...THEN ' IF comparison THEN label ' When the comparison in an IF..THEN command is true, ' the program will jump to the label after THEN. ' When the comparison is false, the program will ' continue to the statement after the IF..THEN command. ' Look around page 91 in the PicBasic Pro Compiler Manual '--------Revision History-------- ' 3/1/06: Clean-up comments & change labels ' 11/17/07: Change PIC MCU from 16F84A to 16F88 ' 11/17/07: Add 16F88 oscillator initialization '------------Variables------------ switch1 var PORTB.0 'Labels PORTB.0 as switch1 '----------Initialization--------- TRISB = %00000001 ' Sets up pin B0 of PORTB as an input ' and pins B1-B7 as outputs PORTB = %00000010 ' Sets pin RB1 to HIGH (+5 volts), ' all other PORTB pins to LOW (0 volts) OSCCON = $60 ' Sets the internal oscillator in the ' 16F88 to 4 MHz '--------Main Code-------- loop: IF switch1 = 1 Then led2 ' If the switch on PORTB.0 is pushed, ' PORTB.0 becomes HIGH (+5 volts) and ' the comparison is true, so the program ' jumps to the label led2. high 1 ' When the comparison is false, the program ' proceeds to the statement after the ' IF..THEN command, in our case, HIGH 1. ' This makes pin RB1 output HIGH(+5 volts) low 2 ' Makes pin RB2 output LOW(0 volts) pause 1 ' Pause 1 ms GoTo loop ' Jump to loop label led2: low 1 ' Makes pin RB1 output LOW(0 volts) high 2 ' Makes pin RB2 output HIGH(+5 volts) pause 1 ' Pause 1 ms GoTo loop ' Jump to loop label End