' for use with 16F88 pic device ' PICBASIC to count numbers (0 - 9999) to 4 digit LED display ' ' Bringing A.4 low will advance count. Use through opto @ Device PIC16F88, HS_osc, Wdt_Off, Pwrt_On, Bod_On, Lvp_Off, Cpd_Off, Protect_Off ,MCLR_OFF INCLUDE "modedefs.bas" DEFINE OSC 20 ANSEL = %00000000 'make all digital ADCON0 = 0 'turn off adc CMCON = 7 'turn off comparator trisb = 0 ' make all portb digital trisa = %00010000 ' make a.4 input and all others digital B1 var byte B0 VAR BYTE W1 VAR WORD W2 Var Word clearcounter: w2 = 0 getcount: w1 = w2 gosub display4 if porta.4 = 0 then takecount goto getcount takecount: if porta.4 = 0 then takecount w2 = w2 +1 if W2 > 9999 then w2 = 9999 endif goto getcount display4: B0 = W1 / 1000 ' Find number of thousands W1 = W1 // 1000 ' Remove thousands from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 8 ' Turn on fourth digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 / 100 ' Find number of hundreds W1 = W1 // 100 ' Remove hundreds from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED Poke PORTA, 4 ' Turn on third digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 / 10 ' Find number of tens W1 = W1 // 10 ' Remove tens from W1 GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 1 ' Turn on second digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting B0 = W1 ' Get number of ones GoSub bin2seg ' Convert number to segments PORTB = B0 ' Send segments to LED PORTA = 2 ' Turn on first digit Pause 1 ' Leave it on 1 ms PORTA = 0 ' Turn off digit to prevent ghosting return ' Convert binary number in B0 to segments for LED bin2seg: LookUp B0,[34,123,22,26,75,138,194,59,2,11],B0 Return End