I've just started to learn about PICs and have started with some basic "hello world" programs. I'm using a 16F628 and started by doing a slightly modified version of the bincnt.asm program on the Projects page. Got this to work fine with LEDs on the PORTB output pins arranged to light up when the pin is outputting a 1. Then tried to add a pushbutton as an input and have the program branch to a different output to show that the pushbutton was acknowledged. The problem is that the input pin does not seem to be an input, but still an output. The pushbutton is from PORTB<4> (although I've also tried pins on PORTA) to Ground. When the button is not pressed, I expected the pin to be high, but it is low, and actively low - if I tie it through a resistor to Vcc, it stays low. With the code below, the LEDs count properly, until the count overflows to PORTB<4>, at which time the pin goes high (as it would if it's an output), and, after the one second timer delay, all LEDs go on, showing that it has branched properly. I've tried setting the pin direction using the TRIS instruction as well as bank switching and loading the TRIS register as in the code below. Neither seems to set the pin as an input. So far I'm baffled. I haven't done any assembler programming for 25 years, and not much even then, so I'm a newbie - be gentle. Dennis LIST P=16F628 INCLUDE "p16f628.inc" ERRORLEVEL -224 __CONFIG _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF &_MCLRE_OFF &_LVP_OFF ORG 0 ; start at program memory location zero pin equ H'0004' clrf CCP1CON ; turn off compare module movlw 0x07 movwf CMCON ; turn off comparators clrf PORTA ; reset latch clrf PORTB bsf STATUS, RP0 ; set bank 1 bcf STATUS, RP1 bcf PCON, OSCF ; set internal oscillator to 37kHz movlw B'00000000' movwf TRISA ; set PORTA as outputs movlw B'00010000' ; set PORTB as outputs except bit 4 movwf TRISB movlw B'00000100' ; configure with pull ups active and movwf OPTION_REG ; prescaler to TMR0 at 1:32 bsf STATUS, RP0 ; set bank 0 ;-----------------------------------------------------------------------; ; Previous section turns off compare module, comparators and ; ; sets PORTA<0:7> and B<0:3,5:7> as outputs. ; ; Then OPTION_REG is set to make pull-ups active and ; ; sets prescaler to TMR0 at 1:32 so it will ; ; overflow and interrupt approximately every second. PORTB<4> is ; ; the pushbutton input to change patterns. Button must be held ; ; for about a second because it's only checked on timer overfolw ; ;-----------------------------------------------------------------------; ;-----------------------------------------------------------------------; ; Main program ; ;-----------------------------------------------------------------------; clrf PORTB loop: incf PORTB, f btfss INTCON, T0IF ; wait on T0IF to be set goto $ -1 bcf INTCON, T0IF btfss PORTB, pin ; if button not pressed (high) break out and set all LEDS on goto loop movlw B'11111111' movwf PORTB nop nop btfsc PORTB, pin ; if button pressed, go back to counting goto $ -1 goto loop end -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body