AVR Display on both sides

Go To Last Post
3 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, could you please help me make this program display the values from the tables on both sides of seven segment display. First table displays it on the left (bit7 = 0) and second table is displaying the values on the right (bit7 = 1), but it doesn't display on both sides at the same time, and I can't figure out how to do that.


;Program to sequence LEDs on port C, using a look up table 

;Stack and Stack Pointer Addresses 
.equ     SPH    =$3E              ;High Byte Stack Pointer Address 
.equ     SPL    =$3D              ;Low Byte Stack Pointer Address 
.equ     RAMEND =$25F             ;Stack Address 

;Port Addresses 
.equ     PORTC  =$15              ;Port C Output Address 
.equ     DDRC   =$14              ;Port C Data Direction Register Address 

;Register Definitions 
.def     leds   =r0               ;Register to store data pointed to by Z 
.def     temp   =r16              ;Temporary storage register 
.def     count  =r17 
.def     YL     =r28              ;Define low byte of Y 
.def     YH     =r29              ;Define high byte of Y 
.def     ZL     =r30              ;Define low byte of Z 
.def     ZH     =r31              ;Define high byte of Z 

;Program Initialisation 
;Set stack pointer to end of memory 
         ldi    temp,high(RAMEND) 
         out    SPH,temp          ;Load high byte of end of memory address 
         ldi    temp,low(RAMEND) 
         out    SPL,temp          ;Load low byte of end of memory address 

;Initialise output ports 
         ldi    temp,$ff
         out    DDRC,temp         ;Set Port C for output by sending $FF to direction register 
         ;Main Program 
reset:   ldi    ZL,low(table*2)   ;Set Z pointer to start of table 
         ldi    ZH,high(table*2) 
         clr    count             ;Set table position counter to zero 
         lpm    r0, Z+            ;Load R0 with data pointed to by Z 
         lpm    r1, Z+            ;Load R0 with data pointed to by Z 
         rcall  delay             ;Call delay subroutine 
         inc    count             ;Increment table position counter 
         cpi    count,7           ;and test if end of table has been reached 
         brne   next              ;if not the end of the table, get next data value in table 
         rjmp   reset             ;else reset Z pointer to start of table 

;Delay Subroutine (25.349 ms @ 1MHz) 
delay:   ldi    YH,high($18C0)    ;Load high byte of Y 
         ldi    YL,low($18C0)     ;Load low byte of Y 
loop:    out    PORTC, r0         ;left side
         sbiw   Y,1               ;Decrement Y 
         out    PORTC, r1         ;right side
         brne   loop              ;and continue to decrement until Y=0 
         ret                      ;Return 

table:	 .DB $3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $67, $77, $7C, $39, $5E, $79, $71; 0-F on left
table2:	 .DB $BF, $86, $DB, $CF, $E6, $ED, $FD, $87, $FF, $E7, $F7, $FC, $B9, $DE, $F9, $F1; 0-F on right


Last Edited: Sun. Mar 8, 2015 - 10:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You never use values from table2.


Personally,  I would just say:

         lpm    r0, Z+            ;Load R0 with data pointed to by Z 
         lpm    r1, Z+            ;Load R1 with data pointed to by Z
         ori    r1, 0x80          ;set bit 7 for right-hand digit

Your code will display 01, 23, 45, 67, 89, ...


I would certainly not multiplex like this anyway.     I bet that you would get some ghosting.

Just display LHS for 2ms and then RHS for 2ms.     Persistence of vision will show both digits.


You normally do the multiplexing with a 2ms Timer Interrupt.



  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John Samperi

Ampertronics Pty. Ltd.


* Electronic Design * Custom Products * Contract Assembly