Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/04/05 04:32
Read: times


 
#92855 - Divide and conquer
Responding to: ???'s previous message
Joshua, you can divide your total task into smaller sub tasks.

From what you have told us you have 3count variables that need to be displayed on three groups of two digit displays.

Starting from the display end, Each 6276 has 16 bits of data therefore you need 2 bytes times 3 = 6 bytes. Allocate 6 bytes of memory and call this something like 'segment_buffer'. Assuming your 6276's are in one string, write a routine called 'update_segments' - this routine shifts the 6 bytes of 'segment_buffer' out to the 6276s.

Then you can write the code to do the binary to bcd conversion, then the bcd to 7 segment conversion.

As you have seen, there are many ways of solving these problems -by dividing it up, we can change one part without badly affecting the other part.

Some example code:

;
; shift the table of bits pointed to by R0 out to the
; A6276 shift registers
;
update_segments:
mov r2,#6 ;6 bytes to shift
us_1:
mov a,@r0 ;grab the byte to shift
inc r0 ;bump the pointer
mov r3,#8 ;load bit count
;
; shift 8 bits out
;
us_2:
rrc a ;get bit into carry
mov DATA,c ;out to the DATA pin
setb CLOCK
clr CLOCK ;shift it out
djnz r3,us_2

djnz r2,us_1 ;shift the next byte
setb LATCH
clr LATCH ;copy the A6276 shift reg to output latch
ret

;
; Convert bcd value in A to 7 segment code
;
conv_7seg:
anl a,#$0f ;0..15 only
mov dptr,#seven_seg
movc a,@a+dptr
ret
seven_seg:
db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ;your seven segment conversion values

;
; convert value in A to packed bcd in A
;
conv_bcd:
;
;
; fill in the blanks!
;
ret
;
; convert value in A to two digit seven segment
; and store in display buffer
; R0->where to store the result
;
conv_to_display
call conv_bcd
push a
anl a,#0f ;lower nibble only
call conv_7seg
mov @r0,a
inc r0
pop a
swap a ;get high nibble
anl a,#0f
call conv_7seg
mov @r0,a
ret



Then your upper level code looks something like:

mov a,Count1
call conv_bcd
mov r0,#segment_buffer+0 ;first display group
call conv_to_display

mov a,Count2
call conv_bcd
mov r0,#segment_buffer+2 ;second display group
call conv_to_display

mov a,Count3
call conv_bcd
mov r0,#segment_buffer+4 ;third display group
call conv_to_display

call update_segments

;job done




List of 6 messages in thread
TopicAuthorDate
Allegro A6276 Sample Code            01/01/70 00:00      
   Divide and conquer            01/01/70 00:00      
      Informative!            01/01/70 00:00      
   Re:Allegro A6276 Sample Code            01/01/70 00:00      
   Further Questions            01/01/70 00:00      
      Bit shifting            01/01/70 00:00      

Back to Subject List