PIC Code

[edit] I posted this in wrong section, can someone move it to PICs?

I am trying to turn on PORTA when RB0 (bit0 of PORTB) gets input. But PORTA doesn’t turn on when I give +5V to RB0.

	#include <p18f1320.inc>

	__config _CONFIG1H, 0x04; external oscillator
	__config _CONFIG2L, 0x00; PWRT and brown out off
	__config _CONFIG2H, 0x00; PWRT and brown out off
	__config _CONFIG4L, 0x80 

main
; all outputs
	CLRF TRISA; outputs
	SETF TRISB;inputs

; init
	CLRF PORTA
	CLRF PORTB

checkagain

	MOVLW b'00000001'; bit 0
	ANDWF PORTB, 0
	BZ checkagain	
	SETF  PORTA,0; turn on port a

	GOTO checkagain

	END

RB0 is an analog pin by default on that PIC, and will therefore read as 0 until it is configured as a digital pin (see the ADC section of the datasheet).

Also make sure you’re applying the input to the right pin - for some bizarre reason, the 18F1xxx parts have a slightly different pinout than other 18-pin PICs.

Oh… ok, how do I change it to digital?

tries using RB2

[EDIT]

I tried RB2 wich is digital and the LED just always stays on without the input.

	#include <p18f1320.inc>

	__config _CONFIG1H, 0x04	; external oscillator
	__config _CONFIG2L, 0x00		; PWRT and brown out off
	__config _CONFIG2H, 0x00		; PWRT and brown out off
	__config _CONFIG4L, 0x80 

main
	; all outputs
	CLRF TRISA ; outputs
	SETF TRISB ;inputs

; init
	CLRF PORTA
	CLRF PORTB

checkagain

	MOVLW b'00000100' ; bit 0
	ANDWF PORTB, 0
	BZ checkagain
	SETF  PORTA,0 ; turn on port a

	GOTO checkagain

The digital/analog status of pins is set via one of the ADCONx registers (and CMCONx on parts with comparators). You need to check the datasheet, details vary widely between parts.

As currently written, your program will turn on PORTA the first time the input is seen high, and then leave it on forever - you have no code to turn PORTA back off. Could that explain the results you’re seeing?

That is all I am trying to do. It is just for learning I/O.

Hmm… the led is still turning on before I say.

	#include <p18f1320.inc>

	__config _CONFIG1H, 0x04	; external oscillator
	__config _CONFIG2L, 0x00		; PWRT and brown out off
	__config _CONFIG2H, 0x00		; PWRT and brown out off
	__config _CONFIG4L, 0x80 

main
	MOVLW 0x70 ; Configure A/D
	MOVWF ADCON1 ; for digital inputs

	; all outputs
	CLRF TRISA ; outputs
	SETF TRISB ;inputs

; init
	CLRF PORTA
	CLRF PORTB

checkagain

	MOVLW b'00000001' ; bit 0
	ANDWF PORTB, 0
	BZ checkagain
	SETF  PORTA,0 ; turn on port a

	GOTO checkagain

0x70 Sets RB0, RB1, RB4 as digital IO pins.