PIC16f877a bcd seven segment controling through four inputs


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2018
    Posts
    2

    Default PIC16f877a bcd seven segment controling through four inputs

    Hi,
    I am trying to make a BCD seven segment display which takes input from 4 bits (port d) and gives output at port b for lsb and port c for msb what I am tryin to do is I take the input and I will subtract it with a value which I stored in w register if the result is zero than accordingly I will turn on or turn off those pins at port b and c. Every time I will change values every time in w register here is my code i make it for only showing 14 and 15. but its not working can any one help me.

    RES_VECT CODE 0x0000 ; processor reset vector
    GOTO START ; go to beginning of program

    ; TODO ADD INTERRUPTS HERE IF USED
    FIXED EQU 20h
    ;INPUT EQU 21h
    ;output_LSB EQU 22h
    ;output_MSB EQU 23h
    MAIN_PROG CODE ; let linker place main program
    START

    BSF STATUS,RP0
    MOVLW b'00000000' ;making all pins of port b as output
    MOVWF TRISB
    MOVLW b'00000000' ;making all pins of port c as output
    MOVWF TRISC
    MOVLW b'00001111' ;making first 4 pins of port d as input
    MOVWF TRISD
    BCF STATUS,5
    ;MOVF PORTD,W
    ;MOVWF PORTB
    ;CLRF PORTD
    MAIN_LOOP
    BCF STATUS, 2 ;CLEAR STATUS REGISTER PIN 2
    CLRF PORTD ;CLEARING ALL PORT D PINS
    MOVF PORTD, W ;TAKING VALUES FROM PORTD AND STORING IN W REGISTER
    MOVWF FIXED ;MOVING VALUE FROM W REGISTER TO VARIABLE FIXED
    MOVF b'00001111',W ;MOVING 15('F') TO W REGISTER
    SUBWF FIXED, 0 ;SUBTRACTING VALUE OF W REGISTER FROM FIXED AND STORING RESULT IN W REGISTER
    BTFSS STATUS,2 ;BIT TEST IF ZERO REGISTER OF STATUS REGISSSTER IF IT IS SET. SKIP NEXT LINE
    MOVLW b'00000101' ; TRANSFERING 5 ON PORT B "WHICH IS LSB OF OUTPUT"
    MOVWF PORTB
    MOVLW b'00000001' ;TRANSFERING 1 ON PORT C "WHICH IS MSB OF OUTPUT"
    MOVWF PORTC
    GOTO LINEAR_1 F
    GOTO MAIN_LOOP

    LINEAR_1
    MOVF PORTD ,W
    MOVF b'00001110',W ;MOVING 14('E') TO W REGISTER
    SUBWF FIXED, 0 ;SUBTRACTING VALUE OF W REGISTER FROM FIXED AND STORING RESULT IN W REGISTER
    BTFSS STATUS, 2 ;BIT TEST IF ZERO REGISTER OF STATUS REGISSSTER IF IT IS SET. SKIP NEXT LINE
    GOTO LINEAR_2
    MOVLW b'00000100' ;TRANSFERING 4 ON PORT B "WHICH IS LSB OF OUTPUT"
    MOVWF PORTB
    MOVLW b'00000001' ;TRANSFERING 1 ON PORT C "WHICH IS MSB OF OUTPUT"
    MOVWF PORTC
    BSF PORTD,7
    GOTO MAIN_LOOP

    END

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: PIC16f877a bcd seven segment controling through four inputs

    I'm no assembler pro but, shouldn't this line :MOVF b'00001111',W ;MOVING 15('F') TO W REGISTER be something like this: MOVLW b'00001111',W ;MOVING 15('F') TO W REGISTER?
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PIC16f877a bcd seven segment controling through four inputs

    I thought it was a forum for PicBASIC pro

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: PIC16f877a bcd seven segment controling through four inputs

    Yes, execution will be looking at address 15 for a file value which is probably zero instead of moving the literal 15 to w.
    Probably a typo because setting w with a literal is done properly elsewhere.

    Code still makes no sense. Both copies to portC will always execute. Both values are 1 for now, but won’t be in application.
    You need to skip a goto, not skip a line. Otherwise you just sent the last value in w which was 15.
    If the code does what you want you only see a mash of the two values you want on the LEDs anyway.
    Both overall display values 14 & 15 would be written alternately very fast.

    This forum has always supported assembly where it relates to PBP, and so it should, but from start to finish belongs on Microchip’s forum.
    If you link to a new post there, it looks easy to sort out, but I don’t think it should happen here.
    Last edited by Art; - 9th April 2018 at 19:11.

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: PIC16f877a bcd seven segment controling through four inputs

    Code:
    w = portd
    portb = w & b00001111
    w = w >> 4
    portc = w
    Maybe that’s a more appropriate answer
    PBP can’t do anything that can’t be done in assembler.
    No need to ever check anything unless there are possible values you want to discount.

Similar Threads

  1. BCD to 7-segment issues
    By andywpg in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th March 2020, 05:52
  2. Replies: 10
    Last Post: - 4th September 2008, 18:55
  3. controling a servo via the usb of a pc useing a pic
    By Jhdgkss in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th May 2008, 00:24
  4. 7 segment display with PIC16F877A 20MHZ
    By freqout in forum General
    Replies: 2
    Last Post: - 8th April 2008, 15:31
  5. Controling a TDA7318 (I2C) Audio Processor
    By Badger in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd June 2004, 22:59

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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