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
    I have seen that program flow with that arrow moving with code...
    but i want to see LED with switch like this in MAPlab ....
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I have loaded you code into MPLAB..... It doesn't compile

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

    INIT
        BSF STATUS,RP0
        MOVLW 0x5
        MOVWF CMCON
        MOVLW 0x0
        MOVWF ANSEL     ; disable ADC
        MOVWF TRISC     ; portb as output
        MOVLW 0x3f
        MOVWF TRISA     ; porta as input
        BCF STATUS,RP0

    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

     
    For starters this chip DOESN'T have a portb, and there was no inc file.
     
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Sorry, i was testing this code on OSHON simulator.
    OK, is this possible to watch led display, switch, lcd in map lab??
    please tell where to learn more about this oscillator setting?
     
    Last edited: Mar 9, 2012
  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,310
    Likes:
    914
    Location:
    Rochdale UK

    I find that as I have a copy of Oshonsoft.. I use the config generator a little too often. Its easier to select all the bits in the config screen and write down the config reg's value..

    I thought you had Proteus... You can compile directly in ISIS. run and simulate..
     
    • Like Like x 1
  6. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Tell me which version should it will work for pic in assembly?
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    It's $465 for Proteus ISIS I would stick with Oshonsoft
     
  8. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Can't we download it free....my friend have.
     
  9. koolguy

    koolguy Active Member

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

    I was testing these code in OSHON but this instruction shows an error and the above initialization(list,include) were removed ...
    MOVWF ANSEL
    is there any method to test PIC16f676 as OSHON does not support 676 (i think)
     
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,240
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Ritesh,
    Oshonsoft does support F676

    Post your FULL code..

    E.
     
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Sorry,
    I got it lying in right half.
    My code are :-

    START

    btfsc 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
    but how to use switch in simulator i have set port a to switch but working...!!
     
    Last edited: Mar 10, 2012
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

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

    In your program PORTA 0 & 1 are set for ADC input.!

    You are testing BTFSS PORTA,1 ; its set for analog inp

    The PORT pins on PORTC do toggle ON/OFF but are VERY fast, you need a longer On/OFF time.

    E
     
    • Like Like x 1
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,
    So, what i have to change in it??
    Sorry, i don't get you?
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,240
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    I understand that you are trying to flash an LED on PORTC.???

    Run this code in Oshonsoft.
    NOTE, as its simulation the flash rate will be very slow.

    In a PIC the PORTC should go high for 0.5Sec and low for 0.5Sec continuous



    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 0x05
        MOVWF CMCON

        BSF STATUS,RP0
        clrf ANSEL  ; disable ADC

        movlw 0x0c
        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   D'3'
            movwf   CounterC
            movlw   D'138'
            movwf   CounterB
            movlw   D'85'
            movwf   CounterA
    loop        decfsz  CounterA,1
            goto    loop
            decfsz  CounterB,1
            goto    loop
            decfsz  CounterC,1
            goto    loop
            retlw   0  
           
            end
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    No, that i can do..
    but i want to flash LED with switch reading..
    any way, i want to study more about this first how it work??
    __config 0x3D14
     
  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    Read the datasheet - the config settings are all explained there.
     
  17. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,240
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    Look at page #54 Section 9.1 of the 16F676 datasheet.

    CONFIGURATION REG
     
  18. koolguy

    koolguy Active Member

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

    I am not getting this conf bits...

    bit 13-12 BG1:BG0: Bandgap Calibration bits for BOD and POR voltage(1)
    00 = Lowest bandgap voltage
    11 = Highest bandgap voltage
    bit 11-9 Unimplemented: Read as ‘0’
    bit 8 CPD: Data Code Protection bit(2)
    1 = Data memory code protection is disabled
    0 = Data memory code protection is enabled
    bit 7 CP: Code Protection bit(3)
    1 = Program Memory code protection is disabled
    0 = Program Memory code protection is enabled
    bit 6 BODEN: Brown-out Detect Enable bit(4)
    1 = BOD enabled
    0 = BOD disabled
    bit 5 MCLRE: RA3/MCLR pin function select(5)
    1 = RA3/MCLR pin function is MCLR
    0 = RA3/MCLR pin function is digital I/O, MCLR internally tied to VDD
    bit 4 PWRTE: Power-up Timer Enable bit
    1 = PWRT disabled
    0 = PWRT enabled
    bit 3 WDTE: Watchdog Timer Enable bit
    1 = WDT enabled
    0 = WDT disabled
    bit 2-0 FOSC2:FOSC0: Oscillator Selection bits
    111 = RC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
    110 = RC oscillator: I/O function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
    101 = INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
    100 = INTOSC oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
    011 = EC: I/O function on RA4/OSC2/CLKOUT pin, CLKIN on RA5/OSC1/CLKIN
    010 = HS oscillator: High speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
    001 = XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
    000 = LP oscillator: Low power crystal on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
    Note 1: The Bandgap Calibration bits are factory programmed and must be read and saved prior to erasing
    the device as specified in the PIC16F630/676 Programming Specification. These bits are reflected
    in an export of the configuration word. Microchip Development Tools maintain all calibration bits to
    factory settings.
    2: The entire data EEPROM will be erased when the code protection is turned off.
    3: The entire program memory will be erased, including OSCCAL value, when the code protection is
    turned off.
    4: Enabling Brown-out Detect does not automatically enable Power-up Timer.
    5: When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled.
     
  19. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    The bits are binary, convert the hexadecimal __config value to binary and you can easily see what the settings are.
     
    • Like Like x 1
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    This sound better now..
    But here are 14 bits and how this 3D14 is set it should be like this 3DE( i think)
     
    Last edited: Mar 10, 2012
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Ritesh!! we are going round in circles.... I have simulated the code I sent you in Oshonsoft... I can't get RA0 or RA1 into digital mode.

    Eric! Any Idea why this code will not switch off the ADC completely??

    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.)
                                ; HERE SET TO INTERNAL OSCILLATOR 4MHZ
        ORG 0
        GOTO INIT
     
    INIT
       
        MOVLW 0x5
        MOVWF CMCON
        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
     
    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
     
     

Share This Page