Need some pointers on 16F628 inputs
I am trying to get my 628 to read PORTA as input for a BCD switch. I am having problems though.
I tried CMCON = 7 and TRISA = %00001111
I set the switch on PORTA.0 - PORTA.3
Couldnt get anything to go..
So I switched to the following code just to test with, still no joy...
I need some pointers on this imput business...
Code follows :
define osc 4
TRISB = %11110000
PB0 VAR PORTB.0
PB1 VAR PORTB.1
PB2 VAR PORTB.2
PB3 VAR PORTB.3
SW0 VAR PORTB.4
SW1 VAR PORTB.5
SW2 VAR PORTB.6
SW3 VAR PORTB.7
SCAN:
If SW0 = 1 then
HIGH PB0
ELSE
LOW PB0
ENDIF
If SW1 = 1 then
HIGH PB1
ELSE
LOW PB1
ENDIF
If SW0 = 2 then
HIGH PB2
ELSE
LOW PB2
ENDIF
If SW0 = 3 then
HIGH PB3
ELSE
LOW PB3
ENDIF
goto scan
This is getting frustrating...
Here is the latest code bit:
define osc 4
CMCON = 7
TRISA = %11111111
TRISB = %00000000
PB0 VAR PORTB.0
PB1 VAR PORTB.1
PB2 VAR PORTB.2
PB3 VAR PORTB.3
SW0 VAR PORTA.0
SW1 VAR PORTA.1
SW2 VAR PORTA.2
SW3 VAR PORTA.3
SCAN:
If SW0 = 1 then
HIGH PB0:PAUSE 2000
ELSE
LOW PB0
ENDIF
If SW1 = 1 then
HIGH PB1:PAUSE 2000
ELSE
LOW PB1
ENDIF
If SW2 = 1 then
HIGH PB2:PAUSE 2000
ELSE
LOW PB2
ENDIF
If SW3 = 1 then
HIGH PB3:PAUSE 2000
ELSE
LOW PB3
ENDIF
HIGH PORTB.5
PAUSE 20
LOW PORTB.5
PAUSE 20
GOTO SCAN
I added the portb.5 so I could flash an LED to indicate the loop is running, which it does.
Still have no ouput on portb.0 to portb.3. The porta inputs are tied high with 10K resistors to +5v