1. 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.
    Dismiss Notice

How to start PIC16F676 ...??

Discussion in 'Microcontrollers' started by koolguy, Feb 17, 2012.

  1. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,235
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Ian,
    Sent you a PM about 1hr ago, ref this ADC setup problem on OSH.

    E.
     
    • Like Like x 1
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    0x3D14 IS only 14 bits!! 11 - 1101 - 0001 - 0100. the ' D' really should be 1 as bits 12,11 and 10 are unused..
     
    • Like Like x 1
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I want to clear this why there is double __ underscore???
    __config 0x3D14
     
    Last edited: Mar 10, 2012
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    so, we are using this Oscillator:-
    100 = INTOSC oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN

    and
    what does this mean?
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    New code for you ritesh..... Put this into oshonsoft assembler it works ok now

    Code (text):

        ;include "P16F676.inc"      ;include the defaults for the chip
        __config 0x3114         ;sets the configuration settings (oscillator type etc.)
                                ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        CLRF OPTION_REG
        BSF STATUS,RP0
        CLRF VRCON
        MOVLW 0x3f
        MOVWF TRISA     ; porta as input
        MOVLW 0x0
        CLRF ANSEL  ; disable ADC
        MOVWF TRISC     ; portb as output
        BCF STATUS,RP0
        MOVLW 0x7
        MOVWF CMCON
     
    START
     
        btfss PORTA,1   ; test bit 1
        call delay
     
        GOTO START
     
    delay
        movlw 0xff
        movwf PORTC
        movlw 0fh
        movwf 0x21
        dECfsz 0x21,f
        clrf PORTC
        RETURN
     
    end
     
    Band gao voltage associated with BOD & POR Brown Out Detect and Power On Reset Read section 9.3.5 on this topic.
     
    Last edited: Mar 10, 2012
    • Like Like x 1
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Thanks the code are working ...
    What the need of this can't we start normally?
    please explain more this part of code...

    CLRF OPTION_REG??
    CLRF VRCON??
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    I was just trying to find out why the ADC wasn't being turned off.

    VRCON is for the voltage reference module (it's unused, so I disabled it)
    OPTION_REG has interrupt settings so I disabled them all.

    ORG 0
    GOTO INIT

    Try to get into the habit of including this. When you use tables and interrupts you'll need to jump over them.
     
    • Like Like x 1
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,235
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
  10. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Please clear one more doubt __config why two underscore not single is that also set in data sheet??
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    __config is a makro.. written by someone in microchip... To know why there is two underscores you'll need to find him and ask him.

    Usually the underscore is used in C for assembler routines... purely for keeping identifiers apart.... If it was declared just config... It would mean no-one could use this identifier.

    The datasheet may well have two, its depends on the font used.

    Sorry... Its a directive for the assembler / linker, not a makro.....
     
    Last edited: Mar 10, 2012
    • Like Like x 1
  12. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi,

    Please explain the function of bit 3, i am not getting its working.
    MOVLW 0x7
    MOVWF CMCON



    19h CMCON — COUT — CINV CIS CM2 CM1 CM0
     
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Look at figure 6.2 Comparator i/o operating modes.... CIS in the last two configurations (this is where VRCON comes in).
     
    Last edited: Mar 11, 2012
    • Like Like x 1
  14. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Here it is but my doubt is not clear.....
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    In the above code i don't understand if the decrement is not working what the need of it??
    movlw 0fh
    movwf 0x21
    dECfsz 0x21,f
     
  16. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have done some changes in delay for LED remain glowing for few seconds..
    But the OSHON shows HARDWARE STACK OVERFLOW after running simulator.

    Code (text):
    ;include "P16F676.inc"      ;include the defaults for the chip
        __config 0x3114         ;sets the configuration settings (oscillator type etc.)
                                ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        CLRF OPTION_REG
        BSF STATUS,RP0
        CLRF VRCON
        MOVLW 0x3f
        MOVWF TRISA     ; porta as input
        MOVLW 0x0
        CLRF ANSEL  ; disable ADC
        MOVWF TRISC     ; portb as output
        BCF STATUS,RP0
        MOVLW 0x7
        MOVWF CMCON
     
    START
     
        btfss PORTA,1   ; test bit 1
        call delay
     
        GOTO START
     
    delay
        movlw 0xff
        movwf PORTC
        movlw 0fh
        movwf 0x21
    again:  dECfsz 0x21,f
        call again
        clrf PORTC
        RETURN
     
    end
     
  17. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,235
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Ritesh,
    Code (text):

    [B]again[/B]:   dECfsz 0x21,f
        [B]call again[/B]
        clrf PORTC
        RETURN
    Your code is wrong, its calling itself, so it will over flow the STACK
     
  18. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    The code given by IAN also is not working this part the F is decremented to E only....!!

    movlw 0fh
    movwf 0x21
    dECfsz 0x21,f
    clrf PORTC

    from:->


    Code (text):

        ;include "P16F676.inc"      ;include the defaults for the chip
        __config 0x3114         ;sets the configuration settings (oscillator type etc.)
                                ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        CLRF OPTION_REG
        BSF STATUS,RP0
        CLRF VRCON
        MOVLW 0x3f
        MOVWF TRISA     ; porta as input
        MOVLW 0x0
        CLRF ANSEL  ; disable ADC
        MOVWF TRISC     ; portb as output
        BCF STATUS,RP0
        MOVLW 0x7
        MOVWF CMCON
     
    START
     
        btfss PORTA,1   ; test bit 1
        call delay
     
        GOTO START
     
    delay
        movlw 0xff
        movwf PORTC
        movlw 0fh
        movwf 0x21
        dECfsz 0x21,f
        clrf PORTC
        RETURN
     
    end
     
  19. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,235
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi


    delay
    movlw 0xff
    movwf PORTC
    movlw 0fh
    movwf 0x21; you are reloading 0x21 with 0Fh
    dECfsz 0x21,f; DEC by 1 count
    clrf PORTC ; clearing PORTC.
    RETURN; now returning!!!

    The decfsz is NOT being used a Conditional Instruction!!
     
    • Like Like x 1
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    Then i think there is no use of it!!
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    As we've told you repeatedly - READ THE DATASHEET!! - there's only 35 odd instructions, it's hardly difficult.

    The obvious one you SHOULD have used is 'decf'.
     

Share This Page