PDA

View Full Version : Porta.1 as input



Jcee324
- 20th November 2004, 18:18
Hello

I have a problem with my 16F627 (or with my program). I have done a smal program to drive a stepper motor. The program workes fine until I what to start/stop the motor useing Porta.1 as input. My program code lookes like this:

DEFINE OSC 4

'Port A och B
TRISA = 255
TRISB = 0

'Variabler
Rb0 VAR PORTB.0
Rb1 VAR PORTB.1
Rb2 VAR PORTB.2
Rb3 VAR PORTB.3

Delay1 VAR BYTE
Delay2 VAR BYTE

Delay1 = 10
Delay2 = 1000

'Programkod

Program:

IF PORTA.1 = 1 Then st2
IF PORTA.1 = 0 Then st1

GoTo Program

st1:

Low Rb0
High Rb1
Low Rb2
High Rb3

Pause delay1

Low Rb0
High Rb1
High Rb2
Low Rb3

Pause delay1

High Rb0
Low Rb1
High Rb2
Low Rb3

Pause delay1

High Rb0
Low Rb1
Low Rb2
High Rb3

Pause delay1

GoTo Program


st2:
Low Rb0
Low Rb1
Low Rb2
Low Rb3

Pause delay2

GoTo Program

If I use Portb.4 as the input instead of porta.1 it workes just fine. The motor stopes for one second (delay2) when I push the button connected to pin 10 (portb.4) but when I use porta.1 (pin 18) the motor doesn't stop.

Does anyone know what I am doing wrong?

\Jonas
http://www.geocities.com/jcee324/eindex.htm

hmr
- 20th November 2004, 19:31
Hi,

I'm quite new in PICBasic Programming but I think you should set Port A as digital because all MCU with analog input come up in analog mode.

ADCON1=7

I think this will solve your problem

Hans

Jcee324
- 20th November 2004, 20:11
Hello Hans

Thank you very much! It solved the problem. I just had to change the ADCON = 7 to CMCON = 7 because it's a 16F627.

Well, thanks again

\Jonas
http://www.geocities.com/jcee324/eindex.htm