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. koolguy

    koolguy Active Member

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

    I want to start PIC16F676 with blinking LED projects on hardware with assembly lang.
    so, please post schematic and procedure to make this projects....
    i am using this cheap programmer
    Thanks
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    All the stuff you need is on Nigel's site.....
     
  3. Wp100

    Wp100 Active Member

    Joined:
    Feb 3, 2009
    Messages:
    955
    Likes:
    43
    Location:
    England
    Hi,

    As Ian says use Nigels tutorials, here is lesson 1, led flasher, but modified for your chip.

    Just note the differences and then you can apply then to the rest of his code examples.

    The picture shows how to wire the led, though you must add +5v and 0v .




    Code (text):
    ;Tutorial 1.2 - Nigel Goodwin 2002  ; MODIFIED FOR PIC16F676

        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.)
                                ; HERE SET TO INTERNAL OSCILLATOR 4MHZ

        cblock  0x20            ;start of general purpose registers
            count1          ;used in delay routine
            counta          ;used in delay routine
            countb          ;used in delay routine
        endc
       
        org 0x0000          ;org sets the origin, 0x0000 for the 16F628,
                        ;this is where the program starts running  

        bcf     STATUS,RP0  ;Bank 0
        clrf    PORTA       ;Init PORTA
        movlw   05h         ;Set RA<2:0> to
        movwf   CMCON       ;digital I/O
        bsf     STATUS,RP0  ;Bank 1
        clrf    ANSEL       ;digital I/O
        movlw   00h         ;
        movwf   TRISA       ;as outputs

        movlw   b'00000000' ;set PortC all outputs
        movwf   TRISC
        movwf   TRISA       ;set PortA all outputs
        bcf     STATUS, RP0 ;select bank 0

    Loop   
        movlw   0xff
        movwf   PORTA           ;set all bits on
        movwf   PORTC
        nop             ;the nop's make up the time taken by the goto
        nop             ;giving a square wave output
        call    Delay           ;this waits for a while!
        movlw   0x00
        movwf   PORTA
        movwf   PORTC           ;set all bits off
        call    Delay
        goto    Loop            ;go back and do it again

    Delay   movlw   d'250'          ;delay 250 ms (4 MHz clock)
        movwf   count1
    d1  movlw   0xC7
        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

        end    
     
    • Like Like x 1
  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

    How to start MAP lab IDE v8.33 for PIC16F676..?

    Hello,

    I am new to map lab i want to know how to start it...
    please help me to start with PIC 16f676 with blinking LED like 555 chip...as table.


    thanks
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Its very easy.... Boot up MPLAB IDE... file menu... project / project wizard... follow the instructions.... Are you going to program in assembler or C?

    I have Nigel Goodwin's tutorials converted to C... So you can copy Nigel's or my tutorials ( they are for the pic16f628 / a but with subtle changes you can compile / assemble on to the pic16f676).

    Both links are on my signature.
     
    Last edited: Mar 7, 2012
  7. koolguy

    koolguy Active Member

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

    I would like to do in assembly.
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
  9. koolguy

    koolguy Active Member

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

    i was working on Oshon simulator with LED blinking the code is working fine.
    but i have no idea how to add oscillator option for it , please tell how to use oscillator whether its crystal or code or RC..?
     
  10. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi, i have oshon simulator in it this code shows 12 error..
    If i want to test it in MAplab ide 8.33 please tell how to do it??
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Ritesh.... You can copy the above code (provided by Wp100) and paste it into a new project in MPLAB.

    Have you ever created a new project in MPLAB before?

    If No..

    1) Open MPLAB.
    2) On the menu select "Project/Project Wizard".
    3) Click "next".
    4) Select YOUR chip. then "next"
    5) Select "Microchip MPASM Toolsiute" From the combo box. Select "next".
    6) Browse for a folder ( create one from the common dialog box that opens ). Select "next".
    7) Add files ( in your case, skip this and select "finish").
    8) Once the project is ready, select "New file" from the toolbar.
    9) Paste the code into this page, then "Save As" an ".asm" file into your project directory.
    10) In the MCW window on the Left... Right Click on the "source files" and select "Add Files".
    11) Once the file has been added, Select "Project/ Build All" from the menu.
    12) All being well there should be a hex file in the project directory.
     
    • Like Like x 1
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Ritesh!!! Why have you two threads going for the same problem....

    Use the Info I gave in the other thread to create a MPLAB project.
     
    • Like Like x 1
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    No, I have never used MAP LAB IDE...!!

    OK, after this i got 4 file as .err, .lst, .O and .hex the required file!!
    please tell the use of these three files??

    and does MAPLAB do more function than converting assembly to HEX??
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    If you got the hex file.. It worked... You can simulate within MPLAB to test before writing to the chip... MPLAB also communicates directly with most programmers.
     
    • Like Like x 1
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    But how??
     
    Last edited: Mar 8, 2012
  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    Not at all true - MPLAB communicates directly with MICROCHIP programmers - only a small number of the many programmers available.
     
    • Like Like x 1
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Sorry I had a bad day yesterday........ most of my posts were not correct to some degree.... I didn't mean it the way it sounded....I mean't to say compatible programmers.
     
    • Like Like x 1
  18. koolguy

    koolguy Active Member

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

    I want to make a program which will glow LED on pressing external switch...please help.
     
  19. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Have you looked through Nigels tutorials? Every thing is there for you, and well comented.
     
  20. koolguy

    koolguy Active Member

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

    Iwrote this code:->
    but tested in OSHON simulator with the keypad and code are not working .....can we check this in maplab?? If yes please tell how?
    BCF STATUS,RP0
    MOVLW 0H
    MOVWF PORTB ; portb as output
    MOVLW 0FFH
    MOVWF PORTA ; porta as input
    BSF STATUS,RP0
    MOVLW 00H
    MOVWF TRISB
    MOVLW 0FFH
    MOVWF TRISA
    BCF STATUS,RP0

    START:

    btfss PORTA,1 : test bit 1
    call delay

    GOTO START

    delay:
    movlw 0ffh
    movwf portb
    movlw 0fh
    movwf 021h
    dECfsz 021h,0
    clrf portb
    RETURN
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    You need to set the debugger to MPLAB sim in the debugger menu.
    There is a stimulus. file you can use (when debugger is enabled) so you can activate RA.1 and watch the program flow.
     

Share This Page