dear arniepj

i have try what u had told me...looks like its works but why my LED keep blinking when its countdown the numbers and the countdown doesnt start at 15sec but it start randomly sometime its start at 3 sometime 10...

here's the code:
' include .bas file
Include "MODEDEFS.bas"
INCLUDE "LCDbar_INC.bas"

'************************************************* ***************

define OSC 4

' Define LCD connections
DEFINE LCD_DREG PORTC ' LCD Data Port
DEFINE LCD_DBIT 0 ' Starting Data Bit
DEFINE LCD_RSREG PORTD ' Register Select Port
DEFINE LCD_RSBIT 0 ' Register Select Bit
DEFINE LCD_EREG PORTD ' Enable Port
DEFINE LCD_EBIT 1 ' Enable Bit
DEFINE LCD_BITS 4 ' Data Bus Size
DEFINE LCD_LINES 2 ' Number of Lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command Delay time in uS was 2000
DEFINE LCD_DATAUS 50 ' Data Delay time in uS was 50

'************************************************* ***************

' Allocate variables
a var byte

Loop1 VAR word
Loop2 VAR word
Delay VAR word
countD Var Word
second var byte
ticks var byte
update var byte
i var byte
LED var PORTB.7
@ device WDT_OFF

'************************************************* ***************

second = 0
ticks = 0
update = 1

'************************************************* ***************

OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
INTCON = $c0 ' Enable TMR0 interrupts
On Interrupt Goto tickint

TRISA = %11111111
ADCON1 = %00000000 ' Set PortA 0, 1, 3 to A/D inputs
Pause 100 ' Wait for LCD to start

Goto main ' Skip subroutines

'************************************************* ***************

main:
low PORTB
Lcdout $fe,1 ' Clear LCD screen
Lcdout "Range" ' Display Hello
Lcdout $fe,$c0+6 ' Clear LCD screen
Lcdout "Controller"
Pause 5000 ' Wait .5 second
Lcdout $fe,1
Lcdout $fe,$c9 ' Clear LCD screen
Lcdout "Ver 1.0"
Pause 5000 ' Wait .5 second
Delay = 110
LCDOUT $FE,1,"LOADING"
Pause 1000
FOR Loop1 = 0 to 100
;syntax-BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Loop1, 2, 0, 16, 100, lines
GOSUB ShowValue
PAUSE Delay
NEXT Loop1
PAUSE 2000

'************************************************* ***************

mainloop:
Gosub geta ' Get A value
Delay = 35
Lcdout $fe,1,"a = " ' Send to LCD
FOR Loop1 = a to a
;syntax-BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Loop1, 2, 0, 16, 30, lines
GOSUB Show_a
PAUSE Delay
NEXT Loop1

if (a<15) then gosub mainloop2
if (a>14) then mainloop

FOR Loop1 = a to a STEP -1
@ BARgraph _Loop1, 2, 0, 16, 30, lines
GOSUB Show_a
PAUSE Delay
NEXT Loop1

Goto mainloop ' Do it forever

'************************************************* ***************

geta: ADCIN 0, a ' Read channel 0 to adval
pause 15
a = a / 9 + 2
return

'************************************************* ***************

mainloop2:
Gosub geta

if (a<15) then decmin
if (a>14) then mainloop

chkup: If update = 1 Then
LCDOUT $fe,1,$c0," countdown : ", dec second
update = 0 ' Screen updated
Endif
Goto mainloop2 ' Do it all forever

decmin: second = second - 1 ' Decrement minutes
If second >= 15 Then
second = 14
Endif
pause 900
Goto debounce

debounce: ' Debounce and delay for 250ms
For i = 1 to 25
Pause 10 ' 10ms at a time so no interrupts are lost
Next i
update = 1 ' Set to update screen
Goto chkup

'************************************************* ***************

' Interrupt routine to handle each timer tick
disable ' Disable interrupts during interrupt handler
tickint:
ticks = ticks + 1 ' Count pieces of seconds
If ticks < 61 Then tiexit ' 61 ticks/second (16.384ms per tick)

' One second elasped - update time
ticks = 0
second = second + 1
If second >= 15 Then
second = 0
Endif

update = 1 ' Set to update LCD

tiexit: INTCON.2 = 0 ' Reset timer interrupt flag
Resume

'************************************************* ***************

ShowValue
LCDOUT $FE,$80+12,DEC BAR_value,"%"
RETURN

Show_a
LCDOUT $FE,$80+4,DEC BAR_value," ","cm range"," "
RETURN