Problem With Digital Timer!!

Thread Starter

Shear_Intelligence

Joined Jun 10, 2012
29
Hi There,

I Tried to impliment digital timer using 8051, user pushed button to enter desired amount of delay and then presses start button, when user pushes start button the value in timer0 (which i configured as counter), is displayed decreasing and when the value becomes 0 the relay is switched off,
the problem which i cannot sort out is that controller is counting values and displays them perfect but when it comes to display value in decreasing i dunno what happens and output becomes ambiguous.
Please help, because my hommies don't consider me an engineer without repairing home appliances :(

Code that i wrote for it

Rich (BB code):
SEG0 EQU 30H
SEG1 EQU 31H
SEG2 EQU 32H
SEG3 EQU 33H
BUTTON EQU P3.4
SEGMENT7 EQU P2
STOP EQU P1.0
START EQU P1.1
ORG 00H
TIMER_SETUP:

	MOV TMOD, #00010110B ;; 8 BIT AUTO RELOAD TIMER 0 AS COUNTER TIMER 1 AS 16 BIT TIMER 
	MOV TH0, #0D

MAIN:
	SETB TR0
	SETB BUTTON
	SETB STOP
	SETB START
	MOV SEG0, #00H
	MOV SEG1, #00H
	MOV SEG2, #00H
	MOV SEG3, #00H
	CALL DISPLAY
	
GET:
	MOV A, TL0
	CALL CONV
	CALL DISPLAY
	JNB START, GO
	JNB TF0, GET
	JMP MAIN
GO:
	CLR TR0
	MOV A, TL0
GOT:
	DEC A
	CALL CONV
	CALL DISPLAY
	CALL DELAY_1S
	MOV B, A
	DJNZ B, GOT
	
CONV:
	MOV B, #10D
	DIV AB
	MOV SEG0, B
	MOV B, #10D
	DIV AB
	MOV SEG1, B
	MOV SEG2, A
RET

DISPLAY:
	
	MOV A, SEG0
	ANL A, #0FH
	ORL A, #80H
	MOV SEG0, A
	MOV SEGMENT7,SEG0
	CALL DELAY
	MOV A, SEG1
	ANL A, #0FH
	ORL A, #40H
	MOV SEGMENT7,A
	CALL DELAY
	MOV A, SEG2
	ANL A, #0FH
	ORL A, #20H
	MOV SEGMENT7,A
	CALL DELAY
	MOV A, SEG3
	ANL A, #0FH
	ORL A, #10H
	MOV SEGMENT7,A
	CALL DELAY
	


RET
DELAY_TIME:
	MOV R2, TH0
AGAIN_TIME:
	CALL DELAY_1MIN
	DJNZ R2, AGAIN_TIME
DELAY_1MIN:
	MOV R1, #60D
AGAIN_1MIN:
	CALL DELAY_1S
	DJNZ R1, AGAIN_1MIN
DELAY_1S:
	MOV R0, #20D
AGAIN_1S:
	CALL DELAY_50MS
	DJNZ R0, AGAIN_1S
	
DELAY_50MS:
	MOV TL1, #0B0H
	MOV TH1, #3CH
	SETB TR1
CHECK:
	JNB TF1, CHECK
	CLR TR1
	CLR TF1
	RET
	
DELAY:
	MOV R4, 255
	DJNZ R4, $
RET
END
 

Attachments

Last edited by a moderator:

absf

Joined Dec 29, 2010
1,968
How are your buttons connected - how do you set the numbers on the LED? I know there is "start" & "stop" and "button" in your software. But I can see only one button.

Why there is no comments on your software? You know it would take hours for others to understand what is going on in your software.... Have you tried to draw a simple flow chart for your codes so you can understand the program flow better?

Allen
 

absf

Joined Dec 29, 2010
1,968
There are some mistakes in your code.....

see below

Rich (BB code):
GET:
	MOV A, TL0         	;GET T0
	CALL CONV	        ;CONVERT TO bcd
	CALL DISPLAY	        ;DISPLAY ON LED
	JNB START, GO	;GOTO GO IF START IS PRESEED
	JNB TF0, GET
	JMP MAIN
GO:
	CLR TR0		        ;STOP T0 COUNTER
	MOV A, TL0	                ;PUT VALUE IN ACC
GOT:
	DEC A		                ;A=A-1
	CALL CONV	        ;VALUE IN ACC IS DESTROYED IN SUBROUTINES
	CALL DISPLAY	        ;TRY TO SAVE A IN TEMP_A
	CALL DELAY_1S
	MOV B, A	                ;COMPARE TEMP_A INSTEAD OF B REG
	DJNZ B, GOT	        ;DJNZ TEMP_A,GOT HERE
	
TEMP_A	EQU  R7	;NEW VAR TEMP_A IS CREATED AT THE BEGINNING.
Allen
 

LDC3

Joined Apr 27, 2013
924
Rich (BB code):
SEG0 EQU 30H
SEG1 EQU 31H
SEG2 EQU 32H
SEG3 EQU 33H
...
I don't know how long your program is, but I bet that it takes more than 48 bytes (there's more than 48 lines for the code). I think the the first lines should be:
SEG0 EQU 78H
SEG1 EQU 79H
SEG2 EQU 7AH
SEG3 EQU 7BH
...
 

absf

Joined Dec 29, 2010
1,968
The Display hardware and software are also having problems.....

You display each of the 4 digits for 50mS totaling 200mS and go to rest for 1000mS. The display would flicker and 80% of the time only the MSD is displaying or may be nothing.

Since your LED display is common anode, it would be better to use PNP transistors and use logic low to switch on the digit. Are you just simulating or did you build the actual hardware?

Allen
 

Thread Starter

Shear_Intelligence

Joined Jun 10, 2012
29
I don't know how long your program is, but I bet that it takes more than 48 bytes (there's more than 48 lines for the code). I think the the first lines should be:
SEG0 EQU 78H
SEG1 EQU 79H
SEG2 EQU 7AH
SEG3 EQU 7BH
...
Actually to be very honest i don't understand what does those lines mean seg0 to seg1, i mean my teacher once wrote on the board and i wrote it, now i was going through my notes then i read and wrote in my software.
 

Thread Starter

Shear_Intelligence

Joined Jun 10, 2012
29
The Display hardware and software are also having problems.....

You display each of the 4 digits for 50mS totaling 200mS and go to rest for 1000mS. The display would flicker and 80% of the time only the MSD is displaying or may be nothing.

Since your LED display is common anode, it would be better to use PNP transistors and use logic low to switch on the digit. Are you just simulating or did you build the actual hardware?

Allen
i actually build the hardware but with 2803 ic and programmed but din work so i decided to simulate first, the problem with this logic is this that i want to display decreasing no with the delay of 1 sec, i mean firstly a becomes for example 12 then displayed and decreamented after and second displayed 11, i want to do this but can't do this, and as far as npn transistor concerns it has fast switching as compared to pnp that's why i used it and easy to calculate value of RB
 

absf

Joined Dec 29, 2010
1,968
Actually to be very honest i don't understand what does those lines mean seg0 to seg1, i mean my teacher once wrote on the board and i wrote it, now i was going through my notes then i read and wrote in my software.
SEG0 - SEG3 are the variables for storing the 4 digits to be displayed. Each variable consists of 2 parts. The lower nibble is the number 0-9 which goes to the 7447 decoder and the upper nibble is used to control which one of the 4 transistors to be turned on. Each bit is corresponding to one transistor.

When the variable is masked with ORL #80H then bit 7=Hi and bits 6-4 = Lo, this is the LSD (unit digit).
ORL #40H bit 6 = Hi, bits 7,5,4,= Lo
ORL #20H bit 5 = Hi, bits 7,6,4 = Lo
ORL #10H bit 4 = Hi, bits 7,6,5,=Lo.....

Allen
 
Last edited:

absf

Joined Dec 29, 2010
1,968
i actually build the hardware but with 2803 ic and programmed but din work so i decided to simulate first, the problem with this logic is this that i want to display decreasing no with the delay of 1 sec, i mean firstly a becomes for example 12 then displayed and decreamented after and second displayed 11, i want to do this but can't do this, and as far as npn transistor concerns it has fast switching as compared to pnp that's why i used it and easy to calculate value of RB
The reason ULN2803 doesn't work is because your digits are common anode and they need +V on the common pins. The ULN2803 only has collectors and bases coming out of the IC and all the emitters are common together and come out on one pin. That's why you can't use it. Using discrete npn transistors, you can connect the emitter to the anode of the LED and collector to +V and use logic high to conduct the transistor to supply +V to the common anode.

I know how the circuit works now and I have your circuit in my proteus working. But sine this is homework, I can only give you help instead of revealing the answer. That would be against the rules of this forum.....

Didn't you get enough help form the above to make your circuit working yet? Your major problem has already been pointed out at post #4.

Allen
 

LDC3

Joined Apr 27, 2013
924
Actually to be very honest i don't understand what does those lines mean seg0 to seg1, i mean my teacher once wrote on the board and i wrote it, now i was going through my notes then i read and wrote in my software.
SEG0 - SEG3 are the variables for storing the 4 digits to be displayed. Each variable consists of 2 parts. The lower nibble is the number 0-9 which goes to the 7447 decoder and the upper nibble is used to control which one of the 4 transistors to be turned on. Each bit is corresponding to one transistor.

When the variable is masked with ORL #80H then bit 7=Hi and bits 6-4 = Lo, this is the LSD (unit digit).
ORL #40H bit 6 = Hi, bits 7,5,4,= Lo
ORL #20H bit 5 = Hi, bits 7,6,4 = Lo
ORL #10H bit 4 = Hi, bits 7,6,5,=Lo.....

Allen
What Allen forgot to say was that the hexadecimal number is the address location of the variable. If your program is longer than 30h bytes, then using "SEG0 EQU 30H" will have you writing data in the middle of your code. You'll be lucky if your code still functions afterwards. Hopefully, using 78H (instead of 30H) will put the data after your program.
 
your button operation is manually or by software.you have tried to choose counter ah! yeah oh.this is possible we can use 8051 act as a counter also.you need to enable the counter operation you must choose C/T with bar. here choose this bit 1 is for counter operation if you need to enable time set this bit 0 ( this bit is available in Tmod Register) This is used for only if u have to choose counter opertion for 8051)



BacklinksVault
 
Last edited:

Thread Starter

Shear_Intelligence

Joined Jun 10, 2012
29
The reason ULN2803 doesn't work is because your digits are common anode and they need +V on the common pins. The ULN2803 only has collectors and bases coming out of the IC and all the emitters are common together and come out on one pin. That's why you can't use it. Using discrete npn transistors, you can connect the emitter to the anode of the LED and collector to +V and use logic high to conduct the transistor to supply +V to the common anode.

I know how the circuit works now and I have your circuit in my proteus working. But sine this is homework, I can only give you help instead of revealing the answer. That would be against the rules of this forum.....

Didn't you get enough help form the above to make your circuit working yet? Your major problem has already been pointed out at post #4.

Allen
Sir, i'm done with my software when i simulate it, it works fine but when i burn it to hardware it works for 1 min and after a min first two digits are turned off, dunno why :( , and this isn't my home work if you have any idea please reveal that why digits are turned off circuit is same as attachment
 

absf

Joined Dec 29, 2010
1,968
I am not sure what happens that it doesn't work in your hardware......It could be a hardware problem. Are you using the exact same 7-segment LED display and 7447 as in the simulator? Could it be a connection problem. Are your transistors tested before you use them? Was the circuit on breadboard or PCB?

The only software problem that would make the first 2 digits not displaying is the CONV and DISPLAY subroutines. Try showing us your latest program and highlight those that you have changed compared to the one listed in post #1.

Allen
 
Top