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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/05/06 02:45
Read: times


 
#128945 - An Update
Responding to: ???'s previous message
Sorry for not getting back to you guys for a while. I have been very busy.

Here is my new source code. I was a bit confused as to whether or not it would be a good idea to use external interrupts to capture the switch input. A lot of posts on this forum talk about debouncing issues but I think that it would make the code a lot more elegant. Plus, the user could press the switch at any time and it would work, whereas the switch has to be held down until the code checks the input pin if I had done it without interrupts. Therefore, I decided to try it.

#include "8051equ.inc"

.org	00h
	ajmp	start

.org	03h
        push    PSW

	; set 30h to new number based on timer
	mov	30h, TL0

        pop     PSW
	reti

.org	0bh
	reti

.org	13h
	reti

.org	1bh
	reti

.org	23h
	reti

.org	25h


initialize:
        mov     SP, #040h

	; start timer 0 - 16 bit timer mode
	mov	TMOD, #01h
	setb	TR0

	mov	PSW, #00h
	
	; interrupt when switch is hit
        clr     IT0
	setb	EA
	setb	EX0
	ret

; delay for short while (not important exactly how long)
delay_x:
	mov	r7, #0ffh
loop_1:
	dec	r7
	djnz	r7, loop_1
	ret

; 8-bit binary to bcd converter
; a  - input value
; r2 - output digit 1
; r3 - output digit 2
; r4 - output digit 3
bin_to_bcd:

	mov	B, #010d
	div	ab
	mov	r4, B
	mov	B, #010d
	div	ab
	mov	r3, B
	mov	B, #010d
	div	ab
	mov	r2, B
	ret

segment_table:	
	.db 	00001001b, 11101011b, 01000101b, 01100001b, 10100011b, 00110001b, 00010001b, 01101011b, 00000001b, 00100011b

; display 3 digit BCD number in the A register
display_bcd:
	mov	dptr, #segment_table
	movc	a, @a+dptr
	mov	P1, a
	ret
		
start:
	acall	initialize

display_loop:
        mov     a, 30h
	acall	bin_to_bcd

	mov	a, r2
	acall	display_bcd
	setb	P3.3
	acall	delay_x
	clr	P3.3

	mov	a, r3
	acall	display_bcd
	setb	P3.4
	acall	delay_x
	clr	P3.4

	mov	a, r4
	acall	display_bcd
	setb	P3.5
	acall	delay_x
	clr	P3.5

	ajmp	display_loop
	
.end


It seems to me that this should work. However, it does not. The 3 7-segment displays usually all display 0's. If I reset the device sometimes they display "Y X Y" where X is a blank 7-segment display and Y is a random decimal digit. Also, sometimes all 3 7-segment displays are blank. P3.2 (INT0) is connected to a switch which is connected to GND. However, when the switch is hit, nothing happens. Nothing at all. Regardless of what (if any) digits are being displayed, they stay there and the switch is ignored.

Any ideas? Thanks again to all.

List of 53 messages in thread
TopicAuthorDate
Pseudo-Random Number Generator Strangeness            01/01/70 00:00      
   Problem lies in BCD converter            01/01/70 00:00      
      Why?            01/01/70 00:00      
         I like see the program 0-255            01/01/70 00:00      
            0-255 SSD Counter            01/01/70 00:00      
               Clarity?            01/01/70 00:00      
               Thanks for the reply            01/01/70 00:00      
                  WRONG            01/01/70 00:00      
                  Not necessarily each line            01/01/70 00:00      
                     re useful            01/01/70 00:00      
      FIXED            01/01/70 00:00      
         Yes ... but WHAT fixed it???            01/01/70 00:00      
   Hints for a smaller program            01/01/70 00:00      
      Great!            01/01/70 00:00      
         More hints            01/01/70 00:00      
   Count the cycles            01/01/70 00:00      
      Good guess, Maarten!!!            01/01/70 00:00      
      Brilliant, Maarten!            01/01/70 00:00      
      Wait Period            01/01/70 00:00      
         Wait does not make up            01/01/70 00:00      
            Makes Sense            01/01/70 00:00      
               why 'debounce'            01/01/70 00:00      
                  ARGHHHHH eric            01/01/70 00:00      
                     Jez, please            01/01/70 00:00      
               Divide by 2            01/01/70 00:00      
   This problem needs more thought            01/01/70 00:00      
      Interrupts don't help            01/01/70 00:00      
         Thanks, Maarten            01/01/70 00:00      
   A Suggestion            01/01/70 00:00      
      use TH1            01/01/70 00:00      
         Use TL0            01/01/70 00:00      
            agreed somewhat, but            01/01/70 00:00      
   Misunderstanding            01/01/70 00:00      
      Just SSD values            01/01/70 00:00      
         Thanks for the reply            01/01/70 00:00      
         Dan if like            01/01/70 00:00      
         7-Segment Connexions            01/01/70 00:00      
            Will Comment Soon...            01/01/70 00:00      
               Famous last words!            01/01/70 00:00      
               A More Excellent Way            01/01/70 00:00      
                  some do flowcharts, before they code            01/01/70 00:00      
   An Update            01/01/70 00:00      
      Typo            01/01/70 00:00      
      Still misleading comment            01/01/70 00:00      
         Fine            01/01/70 00:00      
   Dan this program needs            01/01/70 00:00      
      Tautology?!            01/01/70 00:00      
         Overkill            01/01/70 00:00      
            a typical example of follwing rules to the letter            01/01/70 00:00      
               Exception to the rule?            01/01/70 00:00      
            Not only comments, but format as well            01/01/70 00:00      
               8051 Simulator            01/01/70 00:00      
                  simulator support            01/01/70 00:00      

Back to Subject List