Connect with us

Need help with PIC16F676

Discussion in 'Electronic Basics' started by uuuuu, Aug 18, 2003.

Scroll to continue with content
  1. uuuuu

    uuuuu Guest

    I want to switch on PORTA pins RA4 & RA5 but the problem is that pin RA2
    seems to go on as well (by on I mean low). Attached my code, I was
    wondering if anyone can help to find the problem. BTW I have 3 warnings
    when compiling that the wrong bank is selected, why am I getting these
    warnings, I used the BANKSEL macro ?

    Tia.


    list p=16F676 ; list directive to define processor
    #include <p16f676.inc> ; processor specific variable definitions

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

    ;******************************************************************************
    ;Defines
    ;******************************************************************************

    #define Bank0 0x00
    #define Bank1 0x80

    ;******************************************************************************
    ;Reset Vector
    ;******************************************************************************
    ORG 0x000 ; processor reset vector
    nop ; required by in circuit debugger
    goto Init ; go to beginning of program

    ;******************************************************************************
    ;Interrupt Vector
    ;******************************************************************************
    ORG 0x004
    return ; interrupt trap - returns without re-enabling
    ;******************************************************************************
    ;Initialization
    ;******************************************************************************
    Init
    ;call 0x3FF ; retrieve factory calibration value
    ; comment instruction if using simulator, ICD2, or ICE2000
    BANKSEL Bank1 ; BANK1
    movwf OSCCAL ; update register with factory cal value
    movlw B'00000000' ;
    movwf TRISA ;
    clrf ANSEL ; configure A/D I/O as digital
    banksel Bank0 ; change back to PORT memory bank
    movlw CM2 | CM1 | CM0 ; configure comparator inputs as digital I/O
    movwf CMCON ;

    ;******************************************************************************
    ;Main
    ;******************************************************************************
    Main
    movlw B'11001111' ; RA4, RA5 will be low (= on in my circuit)
    movwf PORTA
    main1
    goto main1

    ;******************************************************************************
    ;Subroutines & Functions
    ;******************************************************************************


    END ; directive 'end of program'
     
  2. Guest

    Guest Guest

     
  3. Guest

    Guest Guest

     
  4. strill

    strill Guest

    Hi Tia

    This may be redundant but try putting a BANKSEL macro at the beginning of
    init.
    The assembler/PIC may be defaulting to the wrong bank.

    Strill
     
  5. uuuuu

    uuuuu Guest

    Hi Tia
    The bank select command was there, where were you looking ?
    I'll simplify it:
    To set RA2 as an output pin with low output what do I do?
    Here is what I did (but it did not work as RA2 stayed high all the time)

    BANKSEL Bank1
    bsf TRISA,2
    clrf ANSEL

    banksel Bank0
    movlw CM2 | CM1 | CM0
    movwf CMCON
    bcf PORTA,2 ; set output low

    Thanks.
     
  6. Guest

    BANKSEL expects a label taken from somewhere in your code. That
    "somewhere" is then examined to discover which bank it happens to be
    in (it could vary as your code grows longer). Then, and only then,
    will the compiler decide what instruction(s) to use for selecting the
    correct bank and these will replace "BANKSEL <variable>". (section
    5.6, page 40 of MPASM user's guide)

    My guess is that you need to do something like this:-

    BANKSEL TRISA

    to keep the compiler happy.
    should be

    bcf TRISA,2

    to set to output

    Cheers
    Robin
     
  7. Charles Jean

    Charles Jean Guest

    Ater configuration word and before variable and constant declarations
    put:

    errorlevel -302

    this will suppress the warnings you are getting for bank selections

    a quirk, I quess, with MPASM

    What a way to run a railroad!!!


    If God hadn't intended us to eat animals,
    He wouldn't have made them out of MEAT! - John Cleese
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-