Q: using MCLR for Input on 12F683


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    I have one more...

    I want to write the PULSIN value to the memory on the 12F683 (and have it stored even when the power is off) and recall it in the event there is no PULSIN signal.

    What are the proper commands to do this?

    (I assume write and read)

    I.e.

    WRITE 5, failsafe

    READ 5, failsafe

    ...but first I have to get the servo thing working!!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This may help with your data storage.
    The below code is for a counter, sort of like an odometer. It saves the value to EEPROM at each hit of a switch. When the device is turned on the EEPROM is read and the values placed back into a variable for continued use. Also has the ability to reset the stored values back to zero at start up.

    Pick through it and see if it helps.
    Code:
    '*  Notes   :16F877A                                
    '*   SAVE TO EEPROM                                         
    '****************************************************************
     '_config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF &_BODEN_OFF
    
    DEFINE OSC 20
    
    DEFINE LCD_DREG     PORTB
    define LCD_DBIT     4
    DEFINE LCD_RSREG    PORTB
    DEFINE LCD_RSBIT    1
    DEFINE LCD_EREG     PORTB
    DEFINE LCD_EBIT     0
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    2
    DEFINE LCD_COMMANDUS    2000
    DEFINE LCD_DATAUS   50
    
    TRISA = %00000000
    ADCON1=14
    
    Asm
        ERRORLEVEL -306
    Endasm
    include "modedefs.bas"
    
    
    'TOTAL VARS
    O	VAR	BYTE	'ONES
    T	VAR	BYTE	'TENS
    H	VAR	BYTE	'HUNDREDS
    TH	VAR	BYTE	'THOUSANDS
    TTH	VAR	BYTE	'TEN THOUSANDS
    HTH	VAR	BYTE	'HUNDRED THOUSANDS
    M	VAR	BYTE	'MILLIONS
    
    OD	VAR	BYTE	'ONES
    TD	VAR	BYTE	'TENS
    HD	VAR	BYTE	'HUNDREDS
    THD	VAR	BYTE	'THOUSANDS
    TTHD	VAR	BYTE	'TEN THOUSANDS
    HTHD	VAR	BYTE	'HUNDRED THOUSANDS
    MD	VAR	BYTE	'MILLIONS
    
    'TOTAL LOGS
    O_LOG	VAR	BYTE	'ONES
    T_LOG	VAR	BYTE	'TENS
    H_LOG	VAR	BYTE	'HUNDREDS
    TH_LOG	VAR	BYTE	'THOUSANDS
    TTH_LOG	VAR	BYTE	'TEN THOUSANDS
    HTH_LOG	VAR	BYTE	'HUNDRED THOUSANDS
    M_LOG	VAR	BYTE	'MILLIONS
    
    'READ LOGS
    READ O_LOG, OD
    READ T_LOG, TD
    READ H_LOG, HD
    READ TH_LOG, THD
    READ TTH_LOG, TTHD
    READ HTH_LOG, HTHD
    READ M_LOG, MD
    
    
    NUM	VAR	BYTE
    NUM = 0
    pause 1000
    
    CHECK:
    IF PORTE.2 = 1 THEN GOSUB CL_LOG 'FOR RESET AT START UP
    IF PORTE.2 = 0 THEN START
    GOTO CHECK
    
    START:
    HIGH PORTD.2      'LED
    PAUSE 5
    IF PORTD.3 = 1 THEN GOSUB C_P_T  'SWITCH FOR PARTS
    LOW PORTD.2
    PAUSE 5
    GOTO START
    
    C_P_T:
    LCDOUT $FE,1,"C TEST"
    LCDOUT $FE,$C0,DEC MD,DEC HTHD,DEC TTHD,DEC THD,DEC HD,DEC TD,DEC OD
    O = O + 1
    IF O = 10 THEN
    O = 1
    T = T + 1
    	IF T = 10 THEN
    	T = 0
    	H = H + 1
    		IF H = 10 THEN
    		H = 0
    		TH = TH + 1
    			IF TH = 10 THEN
    			TH = 0
    			TTH = TTH + 1
    				IF TTH = 10 THEN
    				TTH = 0
    				HTH = HTH +1
    					IF HTH = 10 THEN
    					HTH = 0
    					M = M +1
    					ENDIF
    				ENDIF
    			ENDIF
    		ENDIF
    	ENDIF
    ENDIF
    
    WRITE O_LOG, O
    WRITE T_LOG, T
    WRITE H_LOG, H
    WRITE TH_LOG, TH
    WRITE TTH_LOG, TTH
    WRITE HTH_LOG, HTH
    WRITE M_LOG, M
    
    READ O_LOG, OD
    READ T_LOG, TD
    READ H_LOG, HD
    READ TH_LOG, THD
    READ TTH_LOG, TTHD
    READ HTH_LOG, HTHD
    READ M_LOG, MD
    
    RETURN
    
    CL_LOG:
    
    HIGH PORTD.2
    PAUSE 100
    LOW PORTD.2
    PAUSE 100
    
    O = $0
    T = $0
    H = $0
    TH = $0
    TTH = $0
    HTH = $0
    M = $0
    
    WRITE O_LOG, O
    READ O_LOG, OD
    WRITE T_LOG, T
    READ T_LOG, TD
    WRITE H_LOG, H
    READ H_LOG, HD
    WRITE TH_LOG, TH
    READ TH_LOG, THD
    WRITE TTH_LOG, TTH
    READ TTH_LOG, TTHD
    WRITE HTH_LOG, HTH
    READ HTH_LOG, HTHD
    WRITE M_LOG, M
    READ M_LOG, MD
    RETURN
    
    END
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Timing out

    I found that PULSIN will time out while you're waiting for something to happen then was clued in on WHILE:WEND.
    So try this command set with something like:
    Code:
    WHILE GPIO.1 = 0    ' Repeat this loop while there is no signal
    pulsout gpio.0, failsafe
    pause pausetime
    WEND
    It comes in handy for something like this.
    Louie

  4. #4
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Thanks LinkMTech and Mackrackit:

    Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).

    I have a couple more questions hopefully you can help me with.

    1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???

    2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.

    Thanks again gents.

    John.

  5. #5


    Did you find this post helpful? Yes | No

    Default Beware PULSOUT as a failsafe

    I crashed my RC aircraft using the PULSOUT command.

    PULSOUT is a 'toggle'. Whatever state the pin was in, it will flip for the duration specified in the PULSOUT command. That is bad news if your servo pin gets clobbered and you were expecting it to be low when you called the PULSOUT routine.

    To be safe, you MUST predefine the pin state before calling PULSOUT.

    e.g.

    LOW ServoPin
    PULSOUT ServoPin, 500

    will work every time.

    HTH
    Brian

  6. #6
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BrianT View Post
    I crashed my RC aircraft using the PULSOUT command.

    PULSOUT is a 'toggle'. Whatever state the pin was in, it will flip for the duration specified in the PULSOUT command. That is bad news if your servo pin gets clobbered and you were expecting it to be low when you called the PULSOUT routine.

    To be safe, you MUST predefine the pin state before calling PULSOUT.

    e.g.

    LOW ServoPin
    PULSOUT ServoPin, 500

    will work every time.

    HTH
    Brian

    Thanks Brian, I've got the pulsout working...actual pretty good now. Just some issues with getting gpio.2 and gpio.3 to simply operate LED's!

    My code is posted above.

    Cheers,

    John.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by johnnylynx View Post
    Thanks LinkMTech and Mackrackit:

    Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).

    I have a couple more questions hopefully you can help me with.

    1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???

    2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.

    Thanks again gents.

    John.
    Can you post your code?
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jan 2009
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Whoops, sorry about that!

    here's the code:


    oSCCON = %01100000 ' Ocs set to 4 MHz
    TRISIO = %00000000 ' Set all ports to outputs, in this example
    CMCON0 = 7 ' Analog comparators off
    ANSEL = 0 ' Analog select set to digital, pg 69 data
    ADCON0 = 0 ' A/D turned OFF, pg 68 of data
    input gpio.4

    inpulse VAR Word
    memory var word
    low gpio.4
    low gpio.3


    start:


    SEROUT 0, 2, [12]
    start2:
    PULSIN 1, 1, inpulse

    if inpulse<50 then
    read 5, memory
    serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
    goto start2
    else
    endif

    if gpio.4=1 then
    write 5, inpulse
    serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
    high gpio.3
    low gpio.4
    else
    low gpio.3
    endif

    SEROUT 0, 2, [17,22,#inpulse*10]
    PAUSE 20


    GOTO start

    END

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


    Did you find this post helpful? Yes | No

    Default

    OSCCON = %01100000 ' Ocs set to 4 MHz
    TRISIO = %00000000 ' Set all ports to outputs, in this example
    CMCON0 = 7 ' Analog comparators off
    ANSEL = 0 ' Analog select set to digital, pg 69 data
    ADCON0 = 0 ' A/D turned OFF, pg 68 of data
    input gpio.4 '<font color=red> make input</font color>

    inpulse VAR Word
    memory var word
    low gpio.4 <font color = red> ' Now you make it an output</font color>
    low gpio.3


    start:


    SEROUT 0, 2, [12]
    start2:
    PULSIN 1, 1, inpulse

    if inpulse<50 then
    read 5, memory
    serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
    goto start2
    else
    endif

    if gpio.4=1 then '<font color=red> still an output, are you wanting an input?</font color>
    write 5, inpulse
    serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
    high gpio.3
    low gpio.4 '<font color=red> is and should be an output</font color>
    else
    low gpio.3
    endif

    SEROUT 0, 2, [17,22,#inpulse*10]
    PAUSE 20


    GOTO start

    END
    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. How to MCLR by code for 16F877
    By fbestepe in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 26th November 2014, 00:51
  2. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 17:38
  3. 16f677a to 12f683
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th July 2007, 06:16
  4. What does this MCLR instruction mean?
    By bartman in forum General
    Replies: 16
    Last Post: - 30th November 2004, 00:32
  5. I/O pin and MCLR
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 1
    Last Post: - 15th July 2004, 10:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts