Question

datasheet for PIC18Fxx2

datasheet related to the 7segs that I am using can be obtained right here

edit(15/4/2013): code below is the instruction word for PORTD

ldig    SET b'00001000' ;for rght digit
rdig    SET b'00000100' ;for left digit

instruction words for TRISB, TRISD, PORTB and PORTD when the code is first executed

CLRF    TRISB   ;port B as output
CLRF    TRISD   ;port D as output
CLRF    PORTD   ;clear port D not to select any digit
SETF    PORTB   ;set port B to off all segments

I want to make two different digits displayed on 2 seven-segment LED displays using assembly. I was trying with the code listed below and it does not work. notes: rdig = right panel, ldig = left panel, disp1 represent 1, and so on.

loop    MOVFF   disp1, PORTB
        MOVLW   rdig    ;select only the left display
        MOVWF   PORTD   ;unit to be on

        MOVFF   disp8, PORTB
        MOVLW   ldig    ;select only the left display
        MOVWF   PORTD   ;unit to be on

        bra     loop

the output is supposed to be 81 (on the seven-segment display) none of the number appears. only some kind of dim light shows up on each panel. the code, however works if i'm trying to display only one number on either side of the seven-segment display.

loop        MOVFF   disp8, PORTB
            MOVLW   ldig    ;select only the left display
            MOVWF   PORTD   ;unit to be on

            bra     loop

edit: I tried to add a small delay (2 microsec) using TMR0N (b'00000000' instruction word, tmrL = FF, tmrH = FB) to each number display request as below, and only number 1 appears on the right panel.

loop    MOVFF   disp1, PORTB
    MOVLW   rdig    ;select only the left display
    MOVWF   PORTD   ;unit to be on
    call    delay

    MOVFF   disp8, PORTB
    MOVLW   ldig    ;select only the left display
    MOVWF   PORTD   ;unit to be on
    call    delay

    bra     loop

instruction settings for TMR0N

initwrd SET 0x00
tmrH    SET 0xFF
tmrL    SET 0xFB
Was it helpful?

Solution

Assuming that PORTD has the enables per each digit set correctly and same for hardware connections, then your code is correct. The only mistake you have is the amount of delay. Start with 1 ms and increase until you get a display of the two digits with no visible flickering. This amount of delay depends on the number of 7-seg displays you are using (again to avoid flickering). 2 usec is simply not enough. I have been working with PICs for ages, this should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top