Discussion in "8051 Discussion Forum" started by    sks    Sep 19, 2008.
Tue Sep 30 2008, 01:19 pm
#41
Hello Mr Arun,
good morning, thank u for giving a valuable cue. i came to office with problems in mind to ask u, request u to give me cue. when i open the site and read ur answer u won't believe how happy i am right now. please give me a day to compete my 9999 counter code. i don't follow "your trainer kit doesn't have Binary to BCD ic 4511, otherwise it would be very easy". i don't know how i can display 3Digits from a single port with out multiplexing. we will discuss this issue latter on. i will submit the code tomorrow.
thanks again
sks
Tue Sep 30 2008, 01:28 pm
#42
Hello Mr pdi,
good morning, ur reply is highly appreciated. thank u very much. i love all of u people, and have high respect to ur knowledge. ( i mean all of ur knowledge). god bless u all. thanks again.
sks
Tue Sep 30 2008, 09:31 pm
#43
Hello Mr Arun,
i have tried to write the code as per my knowledge and getting cue from u. i don't think this will satisfy you. how ever i have completed the code & couldn't wait to test in my kit. i thought i will show u first. pl see and comment. thanks
sks

;4digit multiplexed 9999 counter


org 0000h

mov r0,#00h
mov r1,#00h
mov r2,#00h
mov r3,#00h

main:
mov p1,#03fh
mov p2,#0fh

pb:
setb p3.0
jb p3.0,pb

pp:
jnb p3.0,pp

one:
inc r0
mov a,r0
call digit_1
cjne r0,#09h,pb
mov r0,#00h
mov p1,#3fh
ten:
inc r1
mov a,r1
call digit_2
cjne r1,#09h,pb
mov r1,#00h
mov p1,#3fh

hundred:
inc r2
mov a,r2
call digit_3
cjne r2,#09h,pb
mov r2,#00h
mov p1,#3fh

thousand:
inc r3
mov a,r3
call digit_4
cjne r3,#09h,pb
mov r3,#00h
sjmp main


digit_1:
clr p2.1
clr p2.2
clr p2.3
call display
mov p1,a
setb p2.0
clr a
call delay
ret

digit_2:
clr p2.0
clr p2.2
clr p2.3
call display
mov p1,a
setb p2.1
clr a
call delay
ret

digit_3:
clr p2.0
clr p2.1
clr p2.3
call display
mov p1,a
setb p2.2
clr a
call delay
ret

digit_4:
clr p2.0
clr p2.1
clr p2.2
call display
mov p1,a
setb p2.3
clr a
call delay
ret

display:

cjne a,#01h,two
mov a,#06h
ret

two:
cjne a,#02h,three
mov a,#5bh
ret
three:
cjne a,#03h,four
mov a,#4fh
ret

four:
cjne a,#04h,five
mov a,#66h
ret

five:
cjne a,#05h,six
mov a,#6dh
ret

six:
cjne a,#06h,seven
mov a,#7dh
ret

seven:
cjne a,#07h,eight
mov a,#07h
ret

eight:
cjne a,#08h,nine
mov a,#7fh
ret

nine:
cjne a,#09h,zero
mov a,#67h
ret

zero:
mov a,3fh
ret

delay:
mov r5,#1

d_loop1:
mov r6,#25

d_loop2:
mov r7,#100

loop:
djnz r7,$
djnz r5,d_loop2
djnz r6,d_loop1
ret
end
Tue Sep 30 2008, 09:54 pm
#44
change this error (commented previous statement):
d_loop1:
mov r6,#25

d_loop2:
mov r7,#100

loop:
djnz r7,$
djnz r6,d_loop2                   ;djnz r5,d_loop2
djnz r5, d_loop1                  ;djnz r6,d_loop1
ret
end


will add in this post if i find any other logical error
:-)
 sks like this.
Tue Sep 30 2008, 10:32 pm
#45
hi pdi,
we want a delay of 25/30 mSec fr multiplexing , am i right?
i hav tried to write the delay routine by following some other delay code.
actually i will love to know the fundamental of delay subroutine code writing, i want to use internal timer, but i don't know. i will modify what u hav suggested. thanks again and good night.
sks
Wed Oct 01 2008, 12:54 am
#46


@ pdi, thanks for your comments !


sahuji, congrats!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

you have done it !

have you tried the code on your trainer ? if not try it and observe what the display does.

if you go thru the logic of your code, you are resetting the counters on count 9, why ?

and also the second digit will only be displayed if the first digit is 9 ( this applies to all other digits)

a lot more tweaking is needed in the above code. especially the display part.

and yes, you can use Binary to BCD cmos ic 4511( 4 of them) to display 4 digits without multiplexing. there is a enable(store) pin on 4511 which can used to latch the data for a particular digit. and you'll be using only 8 port pins to interface 4 digits ( 4 pins for binary input and 4 for enable)



Arun
 sks like this.
Wed Oct 01 2008, 01:11 am
#47
well, basics of timer is as follows:

Timer are a kind of counter which counts clock cycles. Duration of clock cycle depends on your external clock. When this counter overflows or say counts till maximum and then rolls back to zero, an interrupt is generated or flag is raised to indicate overflow has occurred.
Now Incase of 8051, clock cycle = Fosc/12
so time for single clock = 12/Fosc

Lets say you are using 12Mhz clock, so duration for single clock is 12/12 = 1uS
which means for every increment in timer count, a delay of 1uS is generated.
If timer is 16-bit then total delay generated for single overflow (from 0 to 65535) is 65.535mS

If you want delay of 50mS (50000uS) then you just have to count 50,000 times.

timer has to be loaded with -50000 = 0x3CB0 (use windows calculator)
THx = 0x3C
TLx = 0xB0
x can be 1 or 0 depending on timer used.
so when overflow occurs, you get interrupt or poll for TFx to go high, it means 50mS over

Hope timers are clear to you now
 sks like this.
Wed Oct 01 2008, 11:51 am
#48
Hello Mr Arun,
good morning. i just can't express my happiness. tears r coming from my eyes. u believe me. how great u people r. ok i couldn't test the code in my kit due to power failure. i had to come my office for duty. so sorry i will test to night & let u know the result tomorrow. sorry for the late. after this is completed i will try with BCD code. thanks a lot.
sks
Wed Oct 01 2008, 12:08 pm
#49
hello Mr Ajay,
good morning. thank u. now i understand the logic u have described. there r two timers in 8051 right? so i can write TH1 & TL1 right?, pl describe about "If timer is 16-bit". i think i should read the TIMER Chapter in my book & ask.
thanks all.
sks

Thu Oct 02 2008, 01:54 am
#50
yes TH1 and TL1 for timer 1 and TH0 and TL0 for timer 0.

you must read about timers in your book, if you want recommendation, then go through 8051 User manual from Intel. Best guide to learn 8051.
search in google, its free to download.
 sks like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

PeterGem
Thu May 16 2024, 06:27 am
Timothywalay
Thu May 16 2024, 04:40 am
Timothypet
Wed May 15 2024, 06:14 pm
RandyBence
Wed May 15 2024, 02:00 pm
JordanDic
Wed May 15 2024, 01:55 pm
DavidDeelf
Wed May 15 2024, 11:16 am
ytaletjkca
Wed May 15 2024, 09:45 am
MildredWoumb
Wed May 15 2024, 04:07 am