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. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Ritesh!! I never paid any mind to the delay.... I though you had engineered it for a minimum time for simulation.

    There was no overflow!

    Code (text):

    delay

        movlw 0xff
        movwf PORTC
        movlw 0fh
        movwf 0x21
        dECfsz 0x21,f
            goto $-1
        clrf PORTC
        RETURN
     
    end
     
    The delay as a delay.
     
    Last edited: Mar 11, 2012
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Cool work....

    I found the meaning from here..!!( a little search)
     
  3. koolguy

    koolguy Active Member

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

    how to change the freq of pulse as in case of duty cycle we can do by adding delay...(like PWM )
     
  4. dave

    Dave New Member

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


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE

    Show me what you mean...
     
  6. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have seen a program which blink LED at different duty cycles simply by adding delay to its subroutine, but in case of changing the freq of blinking LED ?
    like we do this in PWM we change the duty cycle and freq of that pulse also.
    So, i want to know how we can change the freq not by crystal(oscillator) internally by code??
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    If you take a look at Nigel's tutorials......Study them a bit...... There are ways to implement delays... Most programmers write two delay functions... One with uS delay and one with mS delay.

    This way you can call a delay ( with the amount of uS / mS in W ) and have any delay you need.... Nigel has uS delays AND mS delays.
     
    • Like Like x 1
  8. koolguy

    koolguy Active Member

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


    If i want to use this code than i will convert it to Hex by map lab or OSHON then program it to PIC16f676 then make a LED to corresponding pin will thi swork or more step to folows

    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
     
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi Ritesh,
    This code fragment is STILL wrong.
    Code (text):
    delay
        movlw 0xff
        movwf PORTC
        movlw 0fh; you are keeping the counter at 0Fh and only decrementing to 0Eh
        movwf 0x21
        dECfsz 0x21,f
        clrf PORTC
        RETURN
     
    Last edited: Mar 14, 2012
    • Like Like x 1
  10. koolguy

    koolguy Active Member

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

    I have notice that before we can use it by adding this after that decrement instruction GOTO $-1.
    anyway i was asking of blinking LED code and i have posted this code. sorry.
     
    Last edited: Mar 14, 2012
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Now i want to Go with code on my PIC chip hardware..
    please tell how to make its board ??
    here is my HEX code please check is that fine....??
     
    Last edited: Mar 14, 2012
  12. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    All the boards for my tutorials are on my site, veroboard designs so anyone can easily build them.
     
    • Like Like x 1
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Run this in Oshonsoft.. I have set the Delay to suit simulation. It set PORTC On/Off

    Code (text):
        LIST    p=16F676        ;tell assembler what chip we are using
        include "P16F676.inc"   ;include the defaults for the chip
        __config 0x3D14         ;sets the configuration settings (oscillator type etc.)
                               
        errorlevel -302, -207
       
    CounterA  equ 0x20
    CounterB  equ 0x21
    CounterC  equ 0x22
    CounterD  equ 0x23
       
        ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        bcf STATUS,RP0
        clrf PORTA
        MOVLW 0x07
        MOVWF CMCON

        BSF STATUS,RP0
        clrf ANSEL  ; disable ADC

        movlw 0x0f
        MOVWF TRISA     ; porta as inp
       
        clrf TRISC   ; portc as out
        BCF STATUS,RP0
         
    START
        call delay
        movlw 0xff
        movwf PORTC
        call delay
        clrf PORTC
        GOTO START
       
    ;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
    delay:      movlw   .1
            movwf   CounterC
            movlw   .10
            movwf   CounterB
            movlw   .50
            movwf   CounterA
    loop        decfsz  CounterA,1
            goto    loop
            decfsz  CounterB,1
            goto    loop
            decfsz  CounterC,1
            goto    loop
            retlw   0  
           
            end
     
    Last edited: Mar 14, 2012
    • Like Like x 1
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Ritesh...

    These are the delay routines

    Code (text):

    Del0    retlw   0x00            ;delay 0mS - return immediately
    Del1    movlw   d'1'            ;delay 1mS
        goto    Delay
    Del5    movlw   d'5'            ;delay 5mS
        goto    Delay
    Del10   movlw   d'10'           ;delay 10mS
        goto    Delay
    Del20   movlw   d'20'           ;delay 20mS
        goto    Delay
    Del50   movlw   d'50'           ;delay 50mS
        goto    Delay
    Del100  movlw   d'100'          ;delay 100mS
        goto    Delay
    Del250  movlw   d'250'          ;delay 250 ms
    Delay   movwf   count1
    d1  movlw   0xC7            ;delay 1mS
        movwf   counta
        movlw   0x01
        movwf   countb
    Delay_0
        decfsz  counta, f
        goto    $+2
        decfsz  countb, f
        goto    Delay_0

        decfsz  count1  ,f
        goto    d1
        retlw   0x00
     
    Put this at the end of your code and you can call any of the above... (provided you use a 4mhz Xtal)
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Yes, this is working...The HEX file i posted wil that work with that code given by Wp100?
     
    Last edited: Mar 14, 2012
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    You cant fail now you have three of us onboard.....;);)
     
  17. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Please provide one single program I am confused.
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,146
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Why are you confused..... Its you who needs to choose what delays you require.... you now have three sets to choose from.
     
    • Like Like x 1
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Ok, i am using this code of Eric...

    Code (text):
        LIST    p=16F676        ;tell assembler what chip we are using
        include "P16F676.inc"   ;include the defaults for the chip
        __config 0x3D14         ;sets the configuration settings (oscillator type etc.)
     
        errorlevel -302, -207
     
    CounterA  equ 0x20
    CounterB  equ 0x21
    CounterC  equ 0x22
    CounterD  equ 0x23
     
        ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        bcf STATUS,RP0
        clrf PORTA
        MOVLW 0x07
        MOVWF CMCON
     
        BSF STATUS,RP0
        clrf ANSEL  ; disable ADC
     
        movlw 0x0f
        MOVWF TRISA     ; porta as inp
     
        clrf TRISC   ; portc as out
        BCF STATUS,RP0
     
    START
        call delay
        movlw 0xff
        movwf PORTC
        call delay
        clrf PORTC
        GOTO START
     
    ;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
    delay:      movlw   .1
            movwf   CounterC
            movlw   .10                             ; changing its value to .30 for more delay.!!!!
            movwf   CounterB
            movlw   .50
            movwf   CounterA
    loop        decfsz  CounterA,1
            goto    loop
            decfsz  CounterB,1
            goto    loop
            decfsz  CounterC,1
            goto    loop
            retlw   0  
     
            end
    I am attaching the HEX code of it please have a look whether is right??
    and i have assembled it by MAP LAB
     
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Ok, i am using this code of Eric...

    Code (text):
        LIST    p=16F676        ;tell assembler what chip we are using
        include "P16F676.inc"   ;include the defaults for the chip
        __config 0x3D14         ;sets the configuration settings (oscillator type etc.)
     
        errorlevel -302, -207
     
    CounterA  equ 0x20
    CounterB  equ 0x21
    CounterC  equ 0x22
    CounterD  equ 0x23
     
        ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
        bcf STATUS,RP0
        clrf PORTA
        MOVLW 0x07
        MOVWF CMCON
     
        BSF STATUS,RP0
        clrf ANSEL  ; disable ADC
     
        movlw 0x0f
        MOVWF TRISA     ; porta as inp
     
        clrf TRISC   ; portc as out
        BCF STATUS,RP0
     
    START
        call delay
        movlw 0xff
        movwf PORTC
        call delay
        clrf PORTC
        GOTO START
     
    ;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
    delay:      movlw   .1
            movwf   CounterC
            movlw   .10                             ; changing its value to .30 for more delay.!!!!
            movwf   CounterB
            movlw   .50
            movwf   CounterA
    loop        decfsz  CounterA,1
            goto    loop
            decfsz  CounterB,1
            goto    loop
            decfsz  CounterC,1
            goto    loop
            retlw   0  
     
            end
    I am attaching the HEX code of it please have a look whether is right??
    and i have assembled it by MAP LAB
     
  21. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Will this circuit will work with this code??
     

Share This Page