Port pin instruction not working


Go to last post By: towlerg
Yesterday 18:58
Forum: The Lounge
Starter: basparky
Views: 0
Replies: 2
Yesterday 16:44
Forum: Proton Plus Compiler v3
Starter: Klr650
Views: 0
Replies: 0
Yesterday 08:45
Forum: The Lounge
Starter: normnet
Views: 0
Replies: 2
+ Reply to Thread
Results 1 to 4 of 4

Thread: Port pin instruction not working29 days old

  1. #1
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    279
    Thumbs Up
    Received: 7
    Given: 0
    Total Downloaded
    347.18 MB

    0 Not allowed!

    Default Port pin instruction not working

    Trying to control a Stepper motor but the instruction in the loop do not set port pins. If I put HIGH PORTB.x then it sets the pin and doing this proves the hardware side is correct. Why does it not work with PORTB = %xxxxxxxx? What an I doing wrong.
    Code below:-

    Code:
    Device = 18F4620
    Declare Xtal = 20
     
     All_Digital = True
     Dim I As Word
     Dim Loop1 As Byte
     I = 500
     DelayMS 500
    
     Start:
    
     For Loop1 = 1 To 10
         PORTB = %00000110
         DelayMS I
         PORTB = %00000100
         DelayMS I
         PORTB = %00000101
         DelayMS I
         PORTB = %00000001
         DelayMS I
         PORTB = %00001001
         DelayMS I
         PORTB = %00001000
         DelayMS I
         PORTB = %00001010
         DelayMS I
         PORTB = %00000010
         DelayMS I 
      Next
      GoTo Start
    Thanks David

  2. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,021
    Thumbs Up
    Received: 315
    Given: 120
    Total Downloaded
    1.51 GB

    0 Not allowed!

    Default Re: Port pin instruction not working

    All ports on a microcontroller are inputs when it is first powered up, so writing to PORTB will have no effect because it has not been made an output.

    Before the loop, use Low PORTB. This will make the pins of PORTB output low, so that subsequent writes to PORTB or LATB will alter it.
    Last edited by Les; 19th November 2018 at 19:55.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Member John Lawton's Avatar
    Join Date
    Feb 2003
    Posts
    269
    Thumbs Up
    Received: 6
    Given: 13
    Total Downloaded
    1.23 GB

    0 Not allowed!

    Default Re: Port pin instruction not working

    You haven't defined PORTB as outputs, they default to inputs. Use TRISB=0
    With these devices you are recommended to use LATB rather than PORTB when setting outputs.

  4. #4
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    279
    Thumbs Up
    Received: 7
    Given: 0
    Total Downloaded
    347.18 MB

    0 Not allowed!

    Default Re: Port pin instruction not working

  5. Yes, that works I was thinking that setting to 1 made them output. Works now.
    THanks.

    David

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. MCP23017 port pin expander not working
    By Dave-S in forum Proton Plus Compiler v3
    Replies: 27
    Last Post: 13th April 2018, 17:49
  2. Input Capture only working with one pin at a time Help!
    By Hornett in forum Absolute Beginners Section
    Replies: 7
    Last Post: 20th March 2017, 00:15
  3. Input Pin No Working (16F88)
    By t0pP8uZz in forum Proton Plus Compiler v3
    Replies: 12
    Last Post: 1st February 2014, 08:21
  4. Trouble with port pin
    By Charles Coultas in forum The Lounge
    Replies: 23
    Last Post: 17th September 2009, 12:06
  5. Pointer to a Port Pin
    By ChrisB in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 20th September 2005, 13:46

Members who have read this thread : 34

Actions :  (Set Date)

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