12F683 + buttons


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV USA
    Posts
    5

    Question 12F683 + buttons

    Hi Folks,

    I am trying to use a 12F683 with three buttons connected to issue serial commands to a motor controller. I have successfully run an almost identical program using a 16F877 (via the X1 board from MELabs) and it works. The '877 seemed like overkill, so I went to the 12F683 and thought I could run the same program. Here is my problem; the program continuously cycles through the if/then parts of the program (as evident by the LCD) and completely ignores any button inputs, which I verified using an o-scope. What has me stumped is that it works differently on the '877, ie., it will only go to a certain if/then statement unless another button is pressed. I've played with the various registers to make sure my pins are set to digital and as inputs, but to no avail. I've also tried to use one button and step through for the three different options, but I can't for the life of me figure that one out. Here is my PBP code, please let me know if you see any problems. Any help or a push in the right direction would be greatly appreciated.



    ‘************************************************* ***************
    ' Name : 12F683MotorV2.pbp
    ' Compiler : PICBASIC PRO Compiler 2.6
    ' Assembler : PM or MPASM
    ' Target PIC : PIC12F683
    ' Hardware : LAB-X4 Experimenter Board
    ' Oscillator : Defined in program
    ' Keywords : SEROUT
    ' Description : PICBASIC PRO program to Drive Motor via SyRen25
    ' on LCD (and serial port).
    '************************************************* ***************

    Code:
    Include "modedefs.bas"  ' Mode definitions for Serout
    ANSEL = 0            ' Set all digital
    CMCON0 = 7           ' Analog comparators off
    define OSC 8
    OSCCON = $70
    option_reg.7=0
    wpu = %00110001
    Pause 500            ' Wait .5 second for LCD to init
    LCD Var GPIO.1       ' LCD TX pin
    Move var GPIO.2      'Serial Out pin for motor controller
    GPIO = %00110001
    TRISIO = %00110001
    Open var GPIO.0
    Close var GPIO.4
    Mstop var GPIO.5
    
    ' Check any button pressed to move motor
    mainloop:
       If Open = 0 Then ' If Open button pressed...
          serout Move, T2400, [0]   ‘Send command to motor controller
          pause 100
          serout LCD, T2400, [$fe, 1, "Opening Door"]
       
       endif
       
       If Close = 0 Then ' If Close button pressed...
          serout Move, T2400, [255] ‘Send command to motor controller
          pause 100
          serout LCD, T2400, [$fe, 1, "Closing Door"]
       
       endif
       
       If Mstop = 0 Then ' If Stop button pressed...
          serout Move, T2400, [127]   ‘Send command to motor controller
          pause 100
          serout LCD, T2400, [$fe, 1, "Stopping Door"]
       
       Endif
       
       Goto mainloop       ' Do it forever
    
       End

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Tray with a pause 10 after mainloop.

    mainloop:
    Pause 10
    If Open = 0 Then ' If Open button pressed...

    Cheers

    Al.
    All progress began with an idea

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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