'--------Title-------- ' File......count2.pbp ' Started....5/9/08 ' Microcontroller used: Microchip Technology PIC16F88 ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' Program displays 8-bit counter variable in decimal, ' hexadecimal, and binary numbering systems. ' Momentary switch pauses count. '-----Background Information------ ' Three numbering systems used in PicBasic Pro: ' Name Base Symbol ' ----- ---- ------ ' Binary Base 2 % ' Decimal Base 10 No Symbol ' Hexadecimal Base 16 $ ' ' For example, the decimal number 255 is written as ' as %11111111 in binary and $FF in hexadecimal. '---------PIC Connections--------- ' 16F88 Pin Wiring ' --------- ---------- ' RA0 LCD pin 11(DB4) ' RA1 LCD pin 12(DB5) ' RA2 LCD pin 13(DB6) ' RA3 LCD pin 14(DB7) ' RA4 LCD Register Select(RS) ' RB0 Momentary Switch to +5 V and ' 10K Pull-Down Resistor to Ground ' RB3 LCD Enable(E) ' Vdd +5 V ' Vss Ground ' MCLR 4.7K Resistor to +5 V '---------LCD Connections--------- ' LCD Pin Wiring ' --------- ---------- ' 1 Ground(Vss) ' 2 + 5v(Vdd) ' 3 Center of 20K Pot(Contrast) ' 4 RA4(Register Select,RS) ' 5 Ground(Read/Write,R/W) ' 6 RB3(Enable) ' 7 No Connection(DB0) ' 8 No Connection(DB1) ' 9 No Connection(DB2) ' 10 No Connection(DB3) ' 11 RA0(DB4) ' 12 RA1(DB5) ' 13 RA2(DB6) ' 14 RA3(DB7) '------------Variables------------ c0 var byte ' BYTE to store counter variable, c0 '----------Initialization--------- 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------------ pause 1000 ' Pause 1 second to allow LCD to setup for c0 = 0 to 255 ' Count from 0 to 255 if PORTB.0 = 1 then c0 = c0 - 1 ' Repeats same count, c0 as long as ' switch remains pressed. lcdout $fe,1,"DEC=", dec c0, " HEX=", HEX c0 ' Clears LCD screen, displays the decimal ' value of c0, DEC c0, and hexadecimal ' value of c0, HEX c0 lcdout $fe,$c0,"BIN=", BIn c0 ' Display binary value of c0, BIN c0, ' on the second line of the LCD screen pause 300 ' Pause 300 ms next c0 end