Thanks mackrackit, IF (ADVAL > 1) AND (ADVAL < 53) THEN ... this code is working..
Since we using ADCIN for switches, should be able to TOGGLE the ports.. I have tried with WHILE..WEND also.. no luck.. Could you pls ..Thanks again.
Thanks mackrackit, IF (ADVAL > 1) AND (ADVAL < 53) THEN ... this code is working..
Since we using ADCIN for switches, should be able to TOGGLE the ports.. I have tried with WHILE..WEND also.. no luck.. Could you pls ..Thanks again.
Can we see your WHILE/WEND code? Or better yet your new and updated code.
But something like this should work
Code:ADCIN 0, adval WHILE (ADVAL > 1) AND (ADVAL < 53) do something ADCIN 0, adval WEND SELECT CASE ....
Dave
Always wear safety glasses while programming.
Hi, The debounce was the problem..Following both codes are working after adding some delay.. I didnt use CASE.. Pls suggest if it needs to be fine tuned..Thanx..
if (ADVAL > 200) AND (ADVAL < 256) THEN
toggle porte.0
pause 150
endif
-----------------------------------------------
ADCIN 0, adval
WHILE (ADVAL = 255) 'AND (ADVAL < 256)
toggle porte.0
pause 150
ADCIN 0, adval
WEND
If it is all working then I would say it is good.
not knowing yhe whole project it is hard to say if it needs fine tuned, but what you have looks like a good solution.
Dave
Always wear safety glasses while programming.
Hi Naga. I did something like this before. I edited the code & schematic to show only the relevent info. The only thing different is if you press the bottom 2 switches at the same time, it will do a 5th function.
ANSEL = 0 'all inputs digital ADC command converts to analog
CMCON = 7 'comparators off
DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
@ device pic12F675, INTRC_OSC_NOCLKOUT, wdt_on, BOD_ON, pwrt_on, mclr_off, protect_on
BUT VAR BYTE 'MESSAGE BUTTONS VARIABLE
BUT2 VAR BYTE 'VARIABLE TO COMPARE BUT READINGS TO PREVENT WRONG ADC READINGS
Pause 500 'SETTLE DOWN
START:
NAP 0 'REDUCE STANDBY CURRENT
ADCIN 3,BUT
IF BUT < 100 Then TABLE 'BUTTON PUSHED
GoTo START
TABLE:
ADCIN 3,BUT
Pause 100
ADCIN 3,BUT2
IF BUT <> BUT2 Then TABLE 'RE-READ THE ADC
IF BUT < 91 AND BUT > 71 Then (DO 1ST THING)
IF BUT < 50 AND BUT > 40 Then (DO 2ND THING)
IF BUT < 15 AND BUT > 8 Then (DO 3RD THING)
IF BUT < 8 AND BUT > 4 Then (DO 4TH THING)
IF BUT < 5 AND BUT > 2 Then (DO 5TH THING)
GOTO START
@ Peterdeco1,Thank you very much .. Very nice..Working perfectly.. Thanks to all of you..
Other problem is..
When using MeLabs default (PM) Assembler compiles OK:
@ device pic12F675, INTRC_OSC_NOCLKOUT, wdt_on, BOD_ON, pwrt_on, mclr_off, protect_on
When using Microchip's (MPASM) Assembler:
@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
3 errors,image attached..
Last edited by naga; - 18th August 2009 at 07:45.
Bookmarks