PIC12F635 - Any advise?


Closed Thread
Results 1 to 4 of 4
  1. #1

    Question PIC12F635 - Any advise?

    Hello
    I am new to pic programming. I have bought two RF modules and would like to make the link between them using my PIC12f635. I have written the following program for the transmitter:

    //PROGRAM START

    TRISIO=%011111
    w1 VAR word
    by var byte
    cmcon0=%111
    intcon=0
    GPIO=0
    Include "modedefs.bas"

    START:
    if gpio.0=1 then ZERO
    IF GPIO.1=1 THEN ONE
    IF GPIO.2=1 THEN Two
    IF GPIO.4=1 THEN FOUR
    GOTO START

    ZERO:
    serout GPIO.5,N2400,["abc",12]
    pause 50
    LOW GPIO.0
    goto start
    ONE:
    serout GPIO.5,N2400,["abc",56]
    pause 50
    LOW GPIO.1
    goto start
    Two:
    serout GPIO.5,N2400,["abc",90]
    pause 50
    LOW GPIO.2
    goto start
    FOUR:
    serout GPIO.5,N2400,["abc",34]
    pause 50
    LOW GPIO.4
    goto start

    // program end

    I WOULD LIKE TO KNOW HOW I CAN PLACE THE MCU IN POWERDOWN MODE UNTILL I PRESS A BUTTON?



    //Receiver Program Start

    TRISIO=%011111
    pause 50
    GPIO=0
    pause 50
    w1 VAR word
    intcon=0
    cmcon0=7
    Include "modedefs.bas"
    pause 50

    start:
    serin GPIO.2,N2400,100,start,["abc"],w1
    pause 50
    goto check
    goto start
    check:
    if w1=12 then zero
    if w1=56 then one
    if w1=90 then four
    if w1=34 then five
    goto start

    zero:
    if w1=12 then
    toggle gpio.0
    pause 2000
    else
    pause 50
    goto check
    goto start
    endif

    one:
    if w1=56 then
    toggle gpio.1
    pause 2000
    else
    pause 50
    goto check
    goto start
    endif

    four:
    if w1=90 then
    toggle gpio.4
    pause 2000
    else
    pause 50
    goto check
    goto start
    endif
    five:
    if w1=34 then
    toggle gpio.5
    pause 2000
    else
    pause 50
    goto check
    goto start
    endif

    //Program End

    I WOULD LIKE AN EXPERT ADVISE ON THE RELIABILITY OF THE RECEIVER CODE BEFORE I USE IT TO CONTROL ANY MAINS DEVICE USING AN RELAY OR SCR.

    (I am using PICBASICPro)

    Thanks in advance for your replies.

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


    Did you find this post helpful? Yes | No

    Default

    I would reduce the code of Receiver Program in this way:

    Code:
    start:
    serin GPIO.2,N2400,100,start,["abc"],w1
    
    if w1=12 then zero
    if w1=56 then one
    if w1=90 then four
    if w1=34 then five
    goto start
    
    zero:
    toggle gpio.0
    pause 2000
    goto start
    
    one:
    toggle gpio.1
    pause 2000
    goto start
    
    four:
    toggle gpio.4
    pause 2000
    goto start
    
    five:
    toggle gpio.5
    pause 2000
    goto start
    
    END
    Remember decoupling cap (10nF) on the pic and snubber diodes on relays


    Al.
    Last edited by aratti; - 20th July 2009 at 18:27.
    All progress began with an idea

  3. #3


    Did you find this post helpful? Yes | No

    Smile

    Thanks for the reply. But I still want to know how I can place the transmitter's MCU to power-down mode and wake it up once a key (on port A)is pressed and put it to sleep again once it has sent out the command? Can someone help me with the code changes -thanks
    Last edited by financecatalyst; - 20th July 2009 at 21:06.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by financecatalyst View Post
    Thanks for the reply. But I still want to know how I can place the transmitter's MCU to power-down mode and wake it up once a key (on port A)is pressed and put it to sleep again once it has sent out the command? Can someone help me with the code changes -thanks
    Sleep
    interrupt wake up , interrupt on change
    Code:
    'intcon.0  'RAIF  PortA Interrupt Flag
    'intcon.1  'INTF  PORTA.2 INT Interrupt Flag
    'intcon.2  'T0IF  Timer 0 Interrupt Flag
    'intcon.3  'RAIE  PortA Interrupt Enable
    'intcon.4  'INTE  PortA.2 INT Interrupt Enable
    'intcon.5  'T0IE  Timer 0 Interrupt Enable
    'intcon.6  'PEIE  Peripheral  Interrupt Enable
    'intcon.7  'GIE   Global interrupt enable
    
    'enable Global interrupts GIE
    'by setting bit 7
    'enable on change interrupts 
    'by setting bit 3 RAIE
    'Clear all interrupt flag bits
    'bits 0,1,2,
    '
    intcon = 10001000
    ' tell it what to do when interrupt occurs
    On Interrupt GoTo . . . 
    'clear the flag bit before going back to sleep
    intcon.0 = 0
    sleep
    'or
    @ sleep
    check this link
    http://www.picbasic.co.uk/forum/showthread.php?t=11325
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Need advise how find problem in PID controller
    By phoenix_1 in forum Off Topic
    Replies: 0
    Last Post: - 28th October 2009, 01:22
  2. suitable resistance values to hold PIC12f635 pins to the ground
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th August 2009, 03:08
  3. Need advise on PIC controlling a variable resistor
    By baldwics in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 16th February 2006, 20:35
  4. Problems with variable - Advise welcome
    By tracking in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th June 2005, 18:40
  5. Newbie - Advise Please
    By tracking in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2005, 18:37

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