Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

wake up from sleep problem with pic12f629 :(

Status
Not open for further replies.

bouvett

New Member
Hi,
i have written a program with the scope of lighting leds using interrupt on change on port 3 but unfortunatly though the micro goes into sleep it won't wake up... i have tried all the other I/O lines and everything is like in the tutorial
https://www.electro-tech-online.com/custompdfs/2009/09/PIC_Mid_A_7.pdf

still the program won't work.. at least surely in the Mplab sim....

one other thing i noticed is that the GPIO pin of pin GPIO3 is always set... why is this so? is it because gpio3 is always an input?
thanks a lot
;PIC12F629
;This program is made to read an input from Gp3. each time it gets set it will switch the next led on.
;The program goes in to sleep and wakes only when the switch is set..
;uses the internal oscillator

#include <p12f629.inc> ; call header file of pic12f629

CBLOCK 0x20
PORT_SHADOW
ENDC

LIST P=12F629 ;SET MICROCONTROLLER USED
ORG 0 ;reset vector
GOTO START_SETTINGS

;NO ISR USED, INTERRUPTS NEEDED ONLY TO WAKE UP FROM SLEEP

;Configuration Word
__CONFIG H'3FC4' ;SELECTS INTERNAL OSCILLATOR WITH NO CLOCKOUT, MCLR INTERNAL, BOD AND POR= ON, PORTECTION OFF

;////////////////////////////////////////////////////////////////////////////////////////////////////////
START_SETTINGS
BANKSEL CMCON
MOVLW B'00000111' ;SET DIGITAL INPUTS
MOVWF CMCON

BANKSEL TRISIO
MOVLW B'00000000' ;SETS ALL PORT BITS TO OUTPUT EXCEPT FOR BIT3 WHICH IS ALWAYS AN INPUT
MOVWF TRISIO

;NOTE THAT GP3 DOESN'T HAVE AN INTERNAL WEAK PULL UP

BANKSEL OPTION_REG
MOVLW B'00000100' ;SETS SOURCE OF TMR0 TO INTERNAL OSCILLATOR AND PRESCALAR TO TMR0,PRESCALAR SET TO 1:32
MOVWF OPTION_REG

;INTERRUPTS: SET THE INTERRUPT ENABLE FOR PORT CHANGE BUT DO NOT SET THE GLOBAL INTERRUPT..
;SO THAT THE MICRO WOULD WAKE UP FROM SLEEP BUT NOT GO THROUGH ISR
;AT SLEEP THE I/O WILL STILL WORK NORMALLY

BANKSEL INTCON
MOVLW B'00001000' ;PORT CHANGE INTERRUPT ENABLED
MOVWF INTCON

;SWITCH OFF TIMER1 AS IT WILL NOT BE USED
BANKSEL T1CON
BCF T1CON,0

BANKSEL IOC
BSF IOC,IOC3

;CALIBRATE THE OSCILLATOR
BANKSEL OSCCAL
CALL 3FFH
MOVWF OSCCAL

;///////////////////////////////////////////////////////////////////////////////////////////////////////////

;PROGRAM STARTS HERE

;PORT_SHADOW RES 1

START CLRF PORT_SHADOW ;RESET SHADOW

BANKSEL GPIO
MOVF GPIO,W

BSF PORT_SHADOW,0 ;SET FRIST LED
MOVF PORT_SHADOW,W
MOVWF GPIO

; CLRWDT

SLEEP ; GOTO SLEEP
;IF WAKED UP IT MUST BE SINCE THERE IS A PORT CHANGE, I.E IN BIT 3
;THUS WAIT FOR IT TO GO LOW(SWITCH DEPRESSED)
;WHEN IT DOES, READ THE PORT AGAIN TO STOP THE CONDITION AND GO BACK TO SLEEP

BANKSEL GPIO
MOVF GPIO,W ;READ SO TO SWITCH OFF CHANGE" CONDITION
BCF INTCON,GPIF ;CLEAR FLAG

BCF PORT_SHADOW,0 ;CLEAR FIRST LED
BSF PORT_SHADOW,1 ;SET THE NEXT LED
MOVF PORT_SHADOW,W
MOVWF GPIO

;CHECK WHETHER SWITCH IS DEPRESSED
CHECK BTFSC GPIO,3
GOTO CHECK

;DEBOUNCE DELAY
NOP
NOP
NOP
NOP

SLEEP

BANKSEL GPIO
MOVF GPIO,W ;READ SO TO SWITCH OFF CHANGE" CONDITION
BCF INTCON,GPIF ;CLEAR FLAG

GOTO START ;START AGAIN

END ;PROGRAM STOPS HERE


thanks a lot
regards
 
Hi

well this may be a problem
BANKSEL TRISIO
MOVLW B'00000000' ;SETS ALL PORT BITS TO OUTPUT EXCEPT FOR BIT3 WHICH IS ALWAYS AN INPUT
MOVWF TRISIO

Should this not be:

MOVLW B'00001000' ?

Rupert
 
Last edited:
Are you actually getting a change on the port pin(s)? You said GP3 is always set?

I would check the voltage on GP3 say with a multimeter. Or disable going into sleep (for now) and just echo GP3 to another GP pin output to a LED, so you can see GP3 sensing the input and the LED going on/off accordingly.

And you might want to double check your config fuses setup, and maybe re-write it using the standard bit flags so it is easier to debug. I have no idea if "__CONFIG H'3FC4'" is doing what you want it to do.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top