• PicŪ Basic

  • Wake a PICŪ from sleep using RB0

    A simple little piece of code showing how to wake a 16F877 from sleep using the interrupt pin RB.0

    Example Code

    'Program History
    'Date Author Comments
    '29.09.04 JS This program works with original dev board, programming
    ' 877 via bootloader NO WDT
    '30.09.04 JS RB port change interrupt changed to RB0 pin change
    ' Only 1 sw and 1 led used with led loop indicator
    '30.09.04 JS Remove excess code
    '30.09.04 JS RB0/INT interrupt working, correct settings for INTCON reg'r
    ' disable PortB pullups, RB0/INT falling edge as well as
    ' enabling and clearing the RBO/INT interupt

    Include "PROTON_20.INC"

    ' Define the pins that are connected to pushbuttons.
    ' The switch must be connected to PORTB, pin0
    Symbol SW1 = PORTB.0

    ' Define the pins that are connected to LEDs
    Symbol LED1 = PORTD.0
    Symbol LED2 = PORTD.1

    INTCON.4 = 1 ' Enable the RB0/INT interrupt
    OPTION_REG = $BF ' Enable PORTB pull-ups (was 7F-0111 1111)
    ' OPTION_REG.7=1 - Disable PORTB pull-ups
    ' OPTION_REG.6=0 - RB0/INT falling edge
    TRISB = %00001111 ' Set PORTB.0-3 (SWs) to input, 4-7 (LEDs)to output

    Output PORTD ' Enable portD to drive leds

    'Pull RB4 High
    High PORTB.4

    'Test leds
    LED1 = 1
    LED2 = 1
    delayms 1000


    'Leds off
    LED1 = 0
    LED2 = 0

    'Led loop indicator
    LED2 = 1
    delayms 1000
    LED2 = 0

    ' Check SW1 pressed to toggle on LED
    If SW1 = 1 Then LED1 = 1

    delayms 5000

    INTCON.1 = 0 ' Clear the RB0/INT interrupt

    Nap 7 ' Go to sleep. When the watchdog is
    ' disabled, NAP won't wake up until
    ' an interrupt occurs.

    Goto main ' Do it again upon waking
    contributed by Javed.
  • Recent Activity


    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    See_Mos Yesterday, 10:05 Go to last post

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    towlerg Yesterday, 13:23 Go to last post