'---------------Title-------------- ' File......16F877A_count1.pbp ' Started....5/9/08 ' Microcontroller used: Microchip Technology PIC16F877A ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Program illuminates 8 LEDs to count in binary from ' %00000000 (0 in decimal) to %11111111 (255 in decinmal). '-------------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 ' See schematic at: ' http://www.cornerstonerobotics.org/schematics/pic16f877a_count1.pdf '------------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) ADCON1 = %00000110 ' Changes PORTE and PORTA analog bits to ' digital operation since not using ADC ' (Analog to Digital Converter) '------------Main Code------------ start: for c0 = 0 to 255 ' Count from 0 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 ' Goes to next c0 Pause 3000 ' Pauses 3 seconds displaying the binary ' number %11111111, then starts over goto start end