capix
- 25th December 2005, 19:45
hi everyone
well im kind of doing some test using PIC16F877A here...test on ir sharp sensors...well as far from what im done, im able to display the range with the bargraph as the indicators...my problem is, i want to set an alarm for range 14cm and below but before it set the alarm it will countdown for 15sec...
here for short flow:
if (range<15) -> countdown start for 15sec -> check again if (range<15) -> if yes then high LED on portB.7 ->if range>15 take reading again or low LED
problem: when range<15 is detect countdown will engage, but at the countdown if there has a status change range>14 before countdown reach 0 the LED still HIGH or blink...i want if there has a status change in the range there will no blink...
code:
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
LED var PORTB.7
'************************************************* ***************
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:
call loop
mainloop:
countD = 15
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 high led
if (a<15) then call countdown
if (a>14) then low led
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
'************************************************* ***************
loop: 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
ShowValue
LCDOUT $FE,$80+12,DEC BAR_value,"%"
RETURN
Show_a
LCDOUT $FE,$80+4,DEC BAR_value," ","cm range"," "
RETURN
countdown
FOR loop1 = 15 to 0 step -1
LCDOUT $FE,$c0," countdown : ", dec countd," "
countd = countd - 1
pause 1000
next loop1
return
any help and ideas would be appreciate....thanx
best regards
capix
well im kind of doing some test using PIC16F877A here...test on ir sharp sensors...well as far from what im done, im able to display the range with the bargraph as the indicators...my problem is, i want to set an alarm for range 14cm and below but before it set the alarm it will countdown for 15sec...
here for short flow:
if (range<15) -> countdown start for 15sec -> check again if (range<15) -> if yes then high LED on portB.7 ->if range>15 take reading again or low LED
problem: when range<15 is detect countdown will engage, but at the countdown if there has a status change range>14 before countdown reach 0 the LED still HIGH or blink...i want if there has a status change in the range there will no blink...
code:
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
LED var PORTB.7
'************************************************* ***************
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:
call loop
mainloop:
countD = 15
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 high led
if (a<15) then call countdown
if (a>14) then low led
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
'************************************************* ***************
loop: 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
ShowValue
LCDOUT $FE,$80+12,DEC BAR_value,"%"
RETURN
Show_a
LCDOUT $FE,$80+4,DEC BAR_value," ","cm range"," "
RETURN
countdown
FOR loop1 = 15 to 0 step -1
LCDOUT $FE,$c0," countdown : ", dec countd," "
countd = countd - 1
pause 1000
next loop1
return
any help and ideas would be appreciate....thanx
best regards
capix