PIC16F1824, problem with oscillator and RA3,RA4,RA5


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Nov 2013
    Posts
    17

    Default PIC16F1824, problem with oscillator and RA3,RA4,RA5

    I don't know what is wrong.
    I made the following code and i have 2 problems.
    -Pause 500 is not 0.5 second, it comes about 2 seconds
    When i replace RA0,RA1,RA2 with RA3,RA4,RA5
    -I can't make RA3,4,5 to work as an input.

    What is wrong ?

    @DEVICEINTOSC 'Internal oscillator: I/O function on CLKIN pin
    @DEVICELVP_OFF 'Low-voltage programming. Not used
    @DEVICEWDT_OFF 'Watchdog timer software-controlled. Not used
    @DEVICEPWRT_OFF 'Enable the power-up timer. Not used
    @DEVICECPD_OFF 'Data code protection
    @DEVICECP_OFF 'Code protection
    @DEVICEMCLR_OFF 'Use MCLR pin as MCLR. Not used
    @DEVICEBOD_OFF 'Disable Brown-out reset
    @DEVICEFCMEN_OFF 'Enables internal oscillator on external death. Not Used
    @IESO_OFF 'Two-speed start-up. Not used

    DEFINE OSC 4
    TRISA = 1 'All inputs
    TRISC = 0 'All outputs
    ANSELA = 0 'Digital in-out
    ANSELC = 0 'Digital in-out

    GOTO START

    START:
    IF PORTA.0 = 1 THEN
    GOTO LOOP1
    ELSE
    GOTO LOOP2
    ENDIF
    GOTO START
    END

    LOOP1:
    IF PORTA.1 = 1 THEN
    PORTC.0 = 1
    ELSE
    PORTC.0 = 0
    pause 500
    PORTC.0 = 1
    pause 500
    PORTC.0 = 0
    ENDIF
    GOTO START
    END

    LOOP2:
    IF PORTA.2 = 1 THEN
    PORTC.0 = 1
    ELSE
    PORTC.0 = 0
    ENDIF
    GOTO START
    End

  2. #2
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    For the Oscillator problem , you need to configure OSCCON register ...
    The default upon reset osc freq. is 500 khz for that PIC mcu .. (That's what datasheet refers on Page 71) . To operate @ 4MHZ you must add the command line below
    OSCCON=%01101000

    Have a nice day

  3. #3
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Thank you, I will try it.

  4. #4
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Ok, with the oscillator, but the problem with RA3,RA4 and RA5 continue.
    I replace the pic with another 1824 with no better result.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Is this the read-modify-write issue?

    (I never remember the details)

    I would try turn on 1 second, off 1 second, goto start (keep it simple blinker to start).

    Robert

  6. #6
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    As datasheet explains ,simply , inserting the lines below gotta be sufficient to configure RA<5:3> as inputs

    BANKSEL PORTA ;
    CLRF PORTA ;Init PORTA
    BANKSEL LATA ;Data Latch
    CLRF LATA ;
    BANKSEL ANSELA ;
    CLRF ANSELA ;digital I/O
    BANKSEL TRISA ;
    MOVLW B'00111000' ;Set RA<5:3> as inputs
    MOVWF TRISA ;and set RA<2:0> as outputs


    Since the way you define your Fuse settings are a bit different than the way I do with my PBP version , the problem might have got to do with yours .. So If you make certain of your "device" declarations , try removing the "end" lines from your code ...
    If it still doesn't help , we'll try to figure out an another solution ..

    Have a nice day ..

  7. #7
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Thank you for your reply, I will try it.
    But the mystery is that RA0,RA1,RA2 working.
    I will try it with simpler code.

  8. #8
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Thank you gunayburak for your answer.
    I add it to the code and i will try it.

    I also focus the problem in fuse settings.
    How will you define the fuse settings ?

  9. #9
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    RA<2:0> MUST WORK ! Because you still use PORTA.0 , PORTA.1 , PORTA.2 declarations in your If conditions ... not PORTA.3 , PORTA4 , PORTA.5 instead ...

  10. #10
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : BURAK GÜNAY *
    '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 6.5.2014 *
    '* Version : 1.0 *
    '* Notes : 16F1824 RA<5:3> input mode *
    '* : *
    '************************************************* ***************

    #header
    errorlevel -303 ; suppress Program word too large
    #ENDHEADER

    #config
    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    '---------------------------------------------------------------------

    DEFINE OSC 4

    PORTA=%000000 : ANSELA=%00000 : TRISA=%111000
    PORTC=%00000000 : ANSELC=%0000000 : TRISC=%00000000

    START:

    IF PORTA.3=1 THEN
    GOTO LOOP1
    ELSE
    GOTO LOOP2
    ENDIF

    GOTO START


    LOOP1:

    IF PORTA.4=1 THEN
    PORTC.0=1
    ELSE
    PORTC.0=0
    pause 500
    PORTC.0= 1
    pause 500
    PORTC.0= 0
    ENDIF

    GOTO START


    LOOP2:

    IF PORTA.5 = 1 THEN
    PORTC.0 = 1
    ELSE
    PORTC.0 = 0
    ENDIF

    GOTO START







    This is the code you should be using ..

  11. #11
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Since the spaces are gone in previous post , the compiler may display errors on compile .. Here is the code again .

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : BURAK GÜNAY                                       *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 6.5.2014                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : 16F1824 RA<5:3> input mode                        *
    '*          :                                                   *
    '****************************************************************
    
    #header
      errorlevel -303  ; suppress Program word too large
    #ENDHEADER
    
    #config
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    '---------------------------------------------------------------------
    
    DEFINE OSC 4
    
    PORTA=%000000   :   ANSELA=%00000    :   TRISA=%111000
    PORTC=%00000000 :   ANSELC=%0000000  :   TRISC=%00000000   
    
    START:
    
    IF PORTA.3=1 THEN
        GOTO LOOP1
    ELSE
        GOTO LOOP2
    ENDIF
    
    GOTO START
    
    
    LOOP1:
    
    IF PORTA.4=1 THEN
        PORTC.0=1 
    ELSE
        PORTC.0=0 
        pause 500
        PORTC.0= 1
        pause 500
        PORTC.0= 0
    ENDIF
    
    GOTO START
    
    
    LOOP2:
    
    IF PORTA.5 = 1 THEN
        PORTC.0 = 1
    ELSE
        PORTC.0 = 0
    ENDIF
    
    GOTO START

  12. #12
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    When i compile it, it shows me syntax error in the lines from #header till #ENDCONFIG

  13. #13
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Ok. I compile it. According to http://melabs.com/support/config_defaults.htm i change the settings in PBP 16F1824.inc file and i add @ at the beggining of config.

    I will inform you for the results.
    Thank you!

  14. #14
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    just wipe off
    Code:
    #header
      errorlevel -303  ; suppress Program word too large
    #ENDHEADER
    as error 303 message is just " a warning " ( no effect on code )

    BTW ...
    is your compiler up to date ???

    I do not have any error message with this processor ...

    Alain
    Last edited by Acetronics2; - 6th May 2014 at 12:13.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  15. #15
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Yep ..But I get such errors

    Quote Originally Posted by Acetronics2 View Post
    just wipe off
    Code:
    #header
      errorlevel -303  ; suppress Program word too large
    #ENDHEADER
    as error 303 message is just " a warning " ( no effect on code )

    BTW ...
    is your compiler up to date ???

    I do not have any error message with this processor ...

    Alain

  16. #16
    Join Date
    Nov 2013
    Posts
    17


    Did you find this post helpful? Yes | No

    Default !!!Solved!!! PIC16F1824, problem with oscillator and RA3,RA4,RA5

    Totally solved.
    The problem was the way i define the fuse settings.
    Gunayburak was right.

    Thank you all !!!
    Last edited by billys7; - 6th May 2014 at 18:40.

Similar Threads

  1. Power up problem with PIC16F1824
    By nobner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th April 2013, 15:11
  2. PIC16F685 RA4/RA5 pins
    By Adrian in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 9th November 2008, 15:45
  3. PIC18F2320 RA4 output problem
    By Kristjan in forum General
    Replies: 2
    Last Post: - 30th May 2007, 23:56
  4. problem with output RA2 and RA3
    By savnik in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th December 2006, 13:49
  5. RA5/MCLR input in 16f88
    By kacho in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th April 2005, 17:21

Members who have read this thread : 1

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