PDA

View Full Version : Problem getting switch info into FOR..NEXT Start



Roddy Wayne
- 25th October 2010, 20:29
'************************************************* ***************
'* Name : No Smoke *
'* Author : Roddy Wayne *
'* Notice : *
'* : *
'* Date : 10/23/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************


CLEAR ;always start with clear
DEFINE OSC 4 ;define oscillator speed
define DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
define DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0
DEFINE DEBUG_PACING 1000
ADCON1 = 7
TRISA = %11111111 ;sets porta as inputs
TRISB = %11111111 ;sets portb pins as inputs
TRISC = %00000000 ;sets portc pins as outputs
TRISD = %00000000 ;sets portd pins as outputs
TRISE = %00000000 ;sets porte pins as outputs
B0 Var Byte 'B0, B2, and B4 all variable bytes
B2 Var Byte
B4 Var Byte

Start:
Pause 100 'pause .1 second
B0 = PortB 'Read PortB, put it in B0
Pause 100 'pause .1 second
B2 = PortA 'Read PortA, put it in B2
Pause 100 'pause .1 second
'Debug 14, 1, "B0 Byte = ", BIN8 B0, " ", 13'Display Byte B0, & next line
Pause 100 'pause .1 second
'Debug "B2 Byte = ", Bin8 B2, " " 'Display Byte B2
Pause 1000 'Wait a second
Debug 14 'Light up LCD
If (B0 = %00000000) Then Start 'If no input, go to Start
If (B2 <%00000011) Then Start 'Case must be CLOSED! (bit 1)
If (B0 >=%00000001) And (B2>=%00000011) Then LEDS 'If input, go to LEDS





LEDS: ''''''''''''''''''PLEASE READ''''''''''''''''''''''''''

'Below is where I'm having a problem. I have not been able to search this
'Forum and find out how to read 8 Dip Switches connected to PortB (inputs)
'and transfer this Data into FOR..NEXT Start. TO will be 0 and STEP will
'be - 1. (Because I've added the "FOR B0 =%00000100" line, the code below
'does run correctly. Any advice or help will be greatly appreciated!)

''''''''''''''''''''''''''''THANK YOU!''''''''''''''''''''''''''''''


For B0 =%00000100 to 0 Step -1
High PortC.0 'Led On
Pause 500 'Wait .5 second
Low PortC.0 'Led Off
Pause 1000 'Wait a second
High PortC.7 'Beeper On
Pause 500 'Wait .5 second
Low PortC.7 'Beeper Off
Pause 50
Debug 1, "B0 Byte = ", Bin8 B0, " "
Pause 58000 'Wait about 1 minute (total)
Next B0 'Dec Next B0
High PortC.4 'Led On (Gives me a visual before 4 second delay)
Pause 500 'Pause .5 second
Low PortC.4 'Led Off
Pause 4000 'Pause 4 seconds (gives plenty of time for testing)

Goto Start
End

HenrikOlsson
- 25th October 2010, 21:19
Hi,
Not exactly sure what you want to do here but how about

myValue VAR BYTE

myValue = PortB
For B0 = myValue to 0 Step -1
....
....
Next
Or probably even

For B0 = PortB to 0 Step -1
....
....
Next

/Henrik.

Roddy Wayne
- 25th October 2010, 23:02
Hi,
Not exactly sure what you want to do here but how about

myValue VAR BYTE

myValue = PortB
For B0 = myValue to 0 Step -1
....
....
Next
Or probably even

For B0 = PortB to 0 Step -1
....
....
Next

/Henrik.

Thanks Henrik! I feel like an IDIOT!
"For B0 = PortB to 0 Step -1"
Works just fine!