PAUSE not working

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi All,
I am running into a frustrating problem using the PIC 12F683. What I need to do is monitor a pin for 5 volts or ground. When the pin is ground, an output pin is low, and when the pin is high, wait for 5 seconds and then turn the output pin high.
I thought it would be simple to adapt the BUTX4.PBP sample program from the ME Labs website and just insert a PAUSE 5000 statement between the
PB=0 and Low LED statements.
However this causes the LED to never come on whether the pushbutton is pushed or not.
I am completely at a loss!
Here is the code snippet that works:

IF PB = 0 Then
LOW LED

Here is the code snippet that doesn't:

IF PB = 0 Then
PAUSE 5000
LOW LED

Any help would be appreciated!
Regards,
mikejp56
 

MrChips

Joined Oct 2, 2009
30,708
You need to implement an IF-THEN-ELSE control structure.

IF --- THEN
---
ELSE
---
ENDIF

for example:
Code:
IF PB=0 THEN
  LOW LED
ELSE
  PAUSE 5000
  HIGH LED
ENDIF
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
You need to implement an IF-THEN-ELSE control structure.

IF --- THEN
---
ELSE
---
ENDIF

for example:
Code:
IF PB=0 THEN
  LOW LED
ELSE
  PAUSE 5000
  HIGH LED
ENDIF
Hi Mr. Chips,
Thanks for that. I will try it and post back.
Regards,
mikejp56
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi Mr. Chips,
Thanks for that. I will try it and post back.
Regards,
mikejp56
Hi Mr. Chips,
I am using the sample code from the ME Labs website, and it already has that. I just want to delay the tun on time of the LED for 5 seconds.
Here is the ME Labs code;

' Name : BUTX4.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' Target PIC : PIC12F683
' Hardware : LAB-X4 Experimenter Board
' Oscillator : 4MHz internal
' Keywords : IF THEN
' Description : PICBASIC PRO program to show button press on LED.
' Note: Disable MCLR in config so button can be used.
'

LED Con 0 ' Alias GPIO.0 to LED
PB Var GPIO.3 ' Alias GPIO.3 to push button

ANSEL = 0 ' Set all digital
CMCON0 = 7 ' Analog comparators off

mainloop: ' Button press turns on LED (MCLRE must not be enabled)
If PB = 0 Then ' If button pressed...
Low LED ' Turn on LED
Else
High LED ' Turn off LED
Endif
Goto mainloop ' Do it forever

End
 

sagor

Joined Mar 10, 2019
903
Example code in #7 does not seem to define which pins are input and which are output (TRISIO). Default for that chip is all pins are inputs. A LED will not come on unless the pin is defined as output. (TRISIO bit 0 = 0)
Remember that GPIO.3 is input only, all other GPIO pins can be either.
Make sure the MCLR function is disabled in the configuration bits when you program the chip, else it will simply reset the chip each time it goes low.
 

upand_at_them

Joined May 15, 2010
940
Double check your compiler's syntax. The single equal sign (=) typically refers to an assignment. And the double equals (==) is what is usually done for a comparison.
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi sagor and upand_at_them,
Thanks for both of your help. I hadn't done PIC stuff in quite a while, and the rust is definitely showing. Pin definitions really do help!
Thanks again.
Regards,
mikejp56
 

MrChips

Joined Oct 2, 2009
30,708
Hi sagor and upand_at_them,
Thanks for both of your help. I hadn't done PIC stuff in quite a while, and the rust is definitely showing. Pin definitions really do help!
Thanks again.
Regards,
mikejp56
If you are learning to program an MCU, then do one thing at a time.
Before incorporating a switch input, get the LED to blink first.

loop:
PAUSE 500
HIGH LED
PAUSE 500
LOW LED
GOTO loop
 

peterdeco

Joined Oct 8, 2019
484
Do you have a pullup on your button? Also in Picbasic Pro the high and low commands automatically convert inputs to outputs. Same as adcin. It converts a digital input to an analog input.
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi All,
Sorry for the delay in reporting back. As I stated previously, I have been away from PICs for quite a while, and the rust is definitely showing. I was connecting to a wrong pin.
The code and circuit as drawn work perfectly.
Thanks for your help.
Regards,
mikejp56
 
Top