/* Write a subrotine to convert a BCD number into an 8-bit value * ready to be sent to the 7-segment display on the CSULB protoshield. * Source: * 1. AVR Addressing Indirect * http://www.csulb.edu/~hill/ee346/Lectures/13%20AVR%20Addressing%20Indirect.pdf */ .INCLUDE .DSEG A: .BYTE 1 .CSEG .ORG 0x0000 RST_VECT: rjmp setup .ORG 0x0100 ; bypass IVT .INCLUDE "spi_shield.inc" setup: rcall initShield clr spiLEDS // turn off discrete red LEDs loop: lds r24, A rcall BCD_to_7SEG mov spi7SEG, r24 call WriteDisplay rjmp loop ; -------------------------- ; ------ BCD to 7SEG ------- ; Called from Home subroutine ; Inputs: r24 Output: r24 ; The input is a 4-bit binary number and the output are the segments ; to turn on to view display this number on a 7-segment display. ; SREG and register r1 are modified by this subroutine ; -------------------------- BCD_to_7SEG: cbr r24,0b11110000 ; limit to 1 nibble ldi ZL,low(table<<1) ; load address of look-up table ldi ZH,high(table<<1) clr r1 add ZL, r24 adc ZH, r1 lpm r24, Z ret // 0 1 2 3 // gfedcba gfedcba gfedcba gfedcba gfedcba gfedcba table: .DB 0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101 // 0 1 2 3 4 5 .DB 0b01111101, 0b00000111, 0b01111111, 0b01100111, 0b01110111, 0b01111100 // 6 7 8 9 A B .DB 0b00111001, 0b01011110, 0b01111001, 0b01110001 // C D E F