elen-group
- 9th July 2008, 23:57
Hello all,
I am programming in PicBasic Pro. We are using two switches (connected at A0 and A3) and two sensors (connected at A1 and A2) as the input and two LEds (connected at B0 and B1) as outputs. The following code is supposed to turn on the LED for a fixed time when the switch is pressed. It does the same when the sensors detect anything. It works fine if the switches are pressed separately. However, if they are pressed together, one of the LEd starts blinking while the other stays on.
ADCON0 = 0
ADCON1=0
CMCON = 7
ANSEL = 0
DEFINE OSC 20
'OSCTUNE = %011110
'T1CON = %01111001
' Simple LED Test
'TRISB = %00000000 'setup PORTB; 0 for output, 1 for input
'TRISB=0 'alternative way of writing above line
TRISB.1=0
TRISA.0=1
TRISA.1=1
TRISB.0=0
TRISA.2=1
TRISA.3=1
i VAR BYTE
i=100
j VAR BYTE
j=100
loop:
PORTB.1=PORTA.1
PORTB.0=PORTA.2
'first switch
IF PORTA.0 = 1 Then
i = 0
ENDIF
if (i < 100) then
PORTB.1=1 'light LED
PAUSE 50 'pause
i = i+1
ELSE
PORTB.1=0 'turn off LED
i=100
ENDIF
'second switch
IF PORTA.3 = 1 Then
j=0
ENDIF
if(j < 100) THEN
PORTB.0=1 'light LED
PAUSE 50
j = j+1
ELSE
PORTB.0=0 'turn off LED
j=100
ENDIF
GOTO loop
end
'''''''''''''''''''''''''''''''''''''''''''
When successful with the above code, I plan to implement it further to use 4 inputs and 4 outputs. Any help in this direction will be greatly appreciated.
Thanks.
I am programming in PicBasic Pro. We are using two switches (connected at A0 and A3) and two sensors (connected at A1 and A2) as the input and two LEds (connected at B0 and B1) as outputs. The following code is supposed to turn on the LED for a fixed time when the switch is pressed. It does the same when the sensors detect anything. It works fine if the switches are pressed separately. However, if they are pressed together, one of the LEd starts blinking while the other stays on.
ADCON0 = 0
ADCON1=0
CMCON = 7
ANSEL = 0
DEFINE OSC 20
'OSCTUNE = %011110
'T1CON = %01111001
' Simple LED Test
'TRISB = %00000000 'setup PORTB; 0 for output, 1 for input
'TRISB=0 'alternative way of writing above line
TRISB.1=0
TRISA.0=1
TRISA.1=1
TRISB.0=0
TRISA.2=1
TRISA.3=1
i VAR BYTE
i=100
j VAR BYTE
j=100
loop:
PORTB.1=PORTA.1
PORTB.0=PORTA.2
'first switch
IF PORTA.0 = 1 Then
i = 0
ENDIF
if (i < 100) then
PORTB.1=1 'light LED
PAUSE 50 'pause
i = i+1
ELSE
PORTB.1=0 'turn off LED
i=100
ENDIF
'second switch
IF PORTA.3 = 1 Then
j=0
ENDIF
if(j < 100) THEN
PORTB.0=1 'light LED
PAUSE 50
j = j+1
ELSE
PORTB.0=0 'turn off LED
j=100
ENDIF
GOTO loop
end
'''''''''''''''''''''''''''''''''''''''''''
When successful with the above code, I plan to implement it further to use 4 inputs and 4 outputs. Any help in this direction will be greatly appreciated.
Thanks.