'---------------Title-------------- ' File......pbp_vb_led1.pbp ' Started....1/20/09 ' Microcontroller used: Microchip Technology PIC16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Visual Basic.NET program controls PIC16F88 to turn on ' and off an LED. '----------Related Lesson---------- ' pbp_vb_led1.pbp is used in the lesson Visual Basic 1 at: ' http://cornerstonerobotics.org/curriculum/lessons_year2/erii_visual_basic1.pdf '--Visual Basic 2008 Express Edition-- ' To download VB 2008 Express Edition, see: ' http://www.microsoft.com/express/download/ '--------Visual Basic Code--------- ' For the VB.NET code that interfaces with this PBP program, ' see: http://www.cornerstonerobotics.org/code/vb_led1.pdf '-----New PicBasic Pro Command----- ' BRANCH Index,[Label{,Label...}] ' ' The PicBasic Pro Compiler Manual is on line at: ' http://www.melabs.com/support/index.htm then under the ' Compiler Documentation: click on PICBASIC PRO Compiler ' Manual and then look at about page 47 in the manual. '-----------Connections----------- ' 16F88 Pin Function Name Given Wiring ' In Program ' --------- ------------ ---------- ---------- ' ' RB0 LED1 LED1 ' RB2 Receiver Pin PICSI MAX232 Pin 9 ' RB5 Transmit Pin PICSO MAX232 Pin 10 ' ' See the schematic for the PIC power and MCLR connections ' MAX232 Pin Datasheet Function and Wiring ' Designation ' --------- --------- ------------------------------------ ' ' Pin 7 T2OUT Receive Data to Male RS232 DB9 Pin 2 ' Pin 8 R2IN Transmit Data from Male RS232 DB9 Pin 3 ' Pin 9 R2OUT Receive Data to PIC RB2 ' Pin 10 T2IN Transmit Data from PIC RB5 ' ' See schematic at: http://www.cornerstonerobotics.org/schematics/pic_vb_serin2_LED.pdf '------------Variables------------ MODE var word ' WORD for MODE value PinState var byte ' BYTE to hold incoming value of PinState LED1 var PORTB.0 ' Defines PORTB.0 name as LED1 PICSI var PORTB.2 ' Defines PORTB.2 name as PICSI PICSO var PORTB.5 ' Defines PORTB.5 name as PICSO '----------Initialization--------- define OSC 8 ' Defines oscillator setting at 8 MHz. ' For SERIN2, an oscillator speed faster ' than 4MHZ may be required for reliable ' operation at 9600 baud and above. ANSEL = 0 ' Changes analog bits to digital. OSCCON = $70 ' Sets the internal oscillator in the ' 16F88 OSCCON register to 8 MHz '------------Main Code------------ mode = 84 ' Sets RX/TX speed to 84 (9600 baud) ' MODE = 188 (4800 baud) ' MODE = 396 (2400 baud) ' See appendix in PicBasic Pro manual ' for other MODE examples. Main: serin2 PICSI, Mode, [PinState] ' PIC receives PinState input from VB ' through the serial port. ' Format: SERIN2 Pin, Mode, [Item1] ' Pin = PICSI(RB2), declared in variables ' Mode = 84 (9600 baud rate) ' [Item1} = [PinState] Branch PinState,[GoLow,GoHigh] ' If PinState = 0 Then go to GoLOW ' If PinState = 0 Then go to GoHIGH Goto Main GoLOW: LOW LED1 ' Set The LED1(RB0) LOW Goto Main GoHIGH: HIGH LED1 ' Set The LED1(RB0) HIGH Goto Main End