'--------Title-------- ' File......count1.pbp ' Started....5/9/08 ' Microcontroller used: Microchip Technology PIC16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Program illuminates 8 LEDs to count in binary from ' 1 to 255. '-------------Comments------------ ' Schematic uses 470 ohm current limiting resistors ' connected to each LED. The current through each LED ' is about 6 mA. When all 8 LEDs are on, the total ' current sourced by PORTB is about 50mA, within the ' 100 mA maximum current limit that a PORT can source. '---------PIC Connections--------- ' 16F88 Pin Wiring ' --------- ---------- ' RB0 LED1 ' RB1 LED2 ' RB2 LED3 ' RB3 LED4 ' RB4 LED5 ' RB5 LED6 ' RB6 LED7 ' RB7 LED8 ' See schematic for the other usual PIC connections '------------Variables------------ c0 var byte ' BYTE to store counter variable, c0 '----------Initialization--------- TRISB = %00000000 ' Set PORTB pins as outputs PORTB = %00000000 ' Set PORTB pins LOW(0 volts) ANSEL = 0 ' Configure all pins to digital ' operation since not using ADC ' (Analog to Digital Converter) OSCCON = $60 ' Sets the internal oscillator in the ' 16F88 to 4 MHz '------------Main Code------------ for c0 = 1 to 255 ' Count from 1 to 255 PORTB = c0 ' Illuminate LEDs to display binary ' number. For example, when c0 = 4 ' the binary number for 4 is %00000100. ' This command sets PORTB to %00000100, ' bringing RB2 HIGH which turns on the ' LED connected to RB2. All of the ' pins are set LOW leaving their ' respective LEDs off. pause 200 ' Pause 200 ms next c0 end