Porta.1 as input


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Jcee324's Avatar
    Jcee324 Guest

    Default Porta.1 as input

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Fribourg, Switzerland
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Jcee324's Avatar
    Jcee324 Guest


    Did you find this post helpful? Yes | No

    Talking

    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

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  3. Replies: 11
    Last Post: - 12th July 2008, 02:36
  4. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  5. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts