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





Bookmarks