init PORTD FOR 16F877A


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2010
    Posts
    2

    Unhappy init PORTD FOR 16F877A

    Hello everyone,

    Before posting this, I've documented myself, but still I have the same annoying problem for one week now.
    I have designed a circuit, using a 16F877A, that is intended to display different
    messages on an HD44780 based LCD, when different keys are pressed, along with switching on a LED, corresponding to the key.

    For my purpose I use PORT B, as 4bit and control lines for the LCD, and PORT D
    as keys interface and LED driver.

    The LCD works fine, but my problem is with PORT D. Even if it is switched to general purpose I/O port (bcf TRISE,PSPMODE), and configured accordingly to my needs (movlw b'00011111'; movwf TRISD), it acts chaotically, especially on RD 0 to 3, by interpreting the inputs as being key-pressed(0 V), and this combined with the fact that the corresponding LED is not lighting.

    Did anyone had this problem also and has a solution to this?

    Thank you in advance,

    PS: Downwards is a chunk of my code, the init part and how I verify my PORTD imputs and command the LEDs.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    list p=16f877A ; list directive to define processor

    #include <p16f877A.inc> ; processor specific variable definitions



    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF





    ERRORLEVEL 0, -302



    ;;;;;;;;;;;;;;; pini necesari LCD;;;;;;;;

    #define D7 PORTB,1

    #define D6 PORTB,2

    #define D5 PORTB,3

    #define D4 PORTB,4

    #define E PORTB,5

    #define RS PORTB,7

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    lcd_port equ PORTB

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCD





    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;;;;;;;;;;;;;;;;;;;;;;;BUTOANE

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    btn_port equ PORTD

    btn1 equ 0

    btn2 equ 1

    btn3 equ 2

    btn4 equ 3

    btn5 equ 4



    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; iesiri

    #define out5 PORTB,0

    #define out4 PORTB,6

    #define out3 PORTD,7

    #define out2 PORTD,6

    #define out1 PORTD,5



    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sfarsit definire iesiri

    cblock 0x20

    d1,d2,d3,var,var_dly,count

    endc

    ;;;;;;;;;;;;;;;;;;;;;;;;; sfarsit declaratii etc







    ;;;;;;;;;;;;;;;;;;;;;;;;; progr principal

    init_porturi:
    ; ports init
    clrf STATUS

    clrf PORTB

    clrf PORTD

    banksel TRISB

    ;bsf OPTION_REG,7

    ;bcf INTCON,4

    clrf TRISB
    ; my LCD uses only 6 lines, and 2 pins are used for light switch on, and one for powering up the LCD for proper INITIALIZATION when a
    PIC hardware RESET
    bcf TRISE,PSPMODE

    movlw 0x1f

    movwf TRISD

    banksel PORTB

    clrf PORTB

    clrf PORTD

    clrf STATUS

    call LCD_Init

    ; ;;;;;;;;;;;;;;;;;end of init side




    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; main loop

    pre_main:

    call stare_de_veghe
    ; this is something for LCD
    main:

    ;btfss btn_port,btn1

    ;call cmd_1

    btfss btn_port,btn2

    call cmd_2

    btfss btn_port,btn3

    call cmd_3

    btfss btn_port,btn4

    call cmd_4

    btfss btn_port,btn5

    call cmd_5

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;fina l main loop

    cmd_1 ;; the same for rest of cmd mnemonics
    ; bla bla bla
    bsf out1; set the LED for out1
    call delay ; generic 1s delay
    bcf out1; clear LED

    ;bla bla bla
    return

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Coss_cat

    @ first, i must tell you here is a PicBASIC Pro Forum ... so it is not the best place to ask for Assembler relative questions ...

    NOW, I see two possibilities ...

    1) PortD is controlled by the TrisE register ... so check that.

    2) may be a simple debounce problem ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jun 2010
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Thank you Acetronics. I am new to the forum, just registered yesterday. I thought it is not such a stupid question to ask for PORTD init, considering the fact that I already did the TRISE thing.
    Also it is good to know rules arround, and so please tell me where exactly this thread should be posted. I will try to repair my mistake.

    Thank you in advance,

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The best place to ask questions on PIC asembly language would be on the Microchip web forum at http://www.microchip.com/forums/Default.aspx?

    This forum is for the MicroengineeringLabs PicBasic Pro & Picbasic compilers.

    The primary focus here is helping folks having problems with BASIC, but we do on occasion offer help with assembler.

    You should have external pull-up resistors holding your portd inputs high, with each button press grounding an input pin. If you don't have the external pull-ups that would explain erratic behaviour.

    Also - be sure on return from any called routine that you're in the proper bank to test portd pins.

    I would post all of your code on the Microchip forum for quicker help. It's hard for people to help if they can't see all of your code since the parts you don't show could be where the problem is.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts