Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

some sort of a mehanism to make LEDs turn on-off in a sequence

Status
Not open for further replies.

amsung2

New Member
I need to to make 60 LEDs blink, each for one second.
one LED to turn on for a second followed by the adjacent LED while the previous one turns off and so on, till cycle repeats.
the main driver behind this is my 89c51 microcontroller. but the output ports aren't sufficient. and I can't come up with a way to multiplex so many LEDs.
I need to come up with a way to do that. my plan is to generate a signal from the microcontroller, and use some support circuitry to do the rest.
I was thinking of using an old fashioned counter, like the IC 4029. but I haven't used that before.
any suggestions?
 
I would think you could just cascade 6 EA. 4017 Decade Counter / Divider chips. Use a 1 second clock rate. Configure with a count to n and recycle. Long as you don't start using high current LEDs it will work just fine.

<EDIT> My bad as it will need more thought using 4017s. </EDIT>

Ron
 
Last edited:
Normal multiplexing needs 16 pins for 64 LEDs. If you look up "Charlieplexing" you would see how to multiplex up to 72 LEDs with 9 outputs.
 
<EDIT> My bad as it will need more thought using 4017s. </EDIT>

Ron

Pretty close Ron, :)

I will take 7.5 CD4017 - so make it 8. (eight usable outputs of each counter when cascaded).

Cascading counters the OP might omit the 89C51 and use a simpler clock source. :)

Boncuk
 
Let me describe what I want to do, build a clock. BUT not an ordinary 7 segment one, that's become common now.
my plan is to have 12 LEDs indicating the hours, 60 LEDs indicating minutes, and 60 LEDs indicating seconds.
here's how I plan to make that work: 89c51 will generate a precise 1 second clock. this signal shall be fed to a counter, or several counters.All the LEDs shall be arranged in a circular concentric fashion.

Now the seconds LEDs shall begin to blink in a sequence, one after the other until they complete the circle at 1 RPM. similarly the minutes LEDs and the hours LEDs.now I only need to figure out how to control so many LEDs without using too much hardware.

I just came up with an idea, tell me if it's gonna work:
it's kind of like changing gears in a car; the MCU generates a clock signal that is fed to one IC 4017, which is connected to 10 LEDs., as usual, it will count up, but when it reaches the 10th LED, the MCU selects the next set of 10 LEDs by selecting a different control line on a multiplexed line. then the cycle repeats.
 
I don't get it. You display 1-60 seconds for the first minute, then display 1-60 minutes for the remainder of the hour?

That would be unlike any other clock for sure.
 
Alright guys, after a lot of thinking, T've come up with the code for my project:

let me explain a little, It is a modified real time clock code. every time half a second passes by, port 0.0 is high, then the next second, it is low. therefore achieving a frequency of 1 HZ.
the MAIN program is interrupted every time the timer counts up from 19456 to 65536. then after every minute the minutes LED is incremented, and similarly the hours LED is incremented as well.

note that the LEDs are arranged in banks of 10 for seconds and minutes, and as bank of 6 for hours (the counter is resset after counting up to 6).
Also note that the dark lines are clock signals to the 4017s,and are cascaded.

every time 10 seconds pass, the next bank of 10 LEDs are switched on with the help of transistors, controlled from port 1.0 to port 1.5.
similarly, for minutes, they are controlled by port 2.0 to 2.5 and hours are controlled in similar fashion from port 3.have a look at the circuit diagram please.

please point out if anything seems to be wrong.
 
and here's the code:

HOURS EQU 07Ch ; HOURS variable
MINUTES EQU 07Dh ; MINUTES variable
SECONDS EQU 07Eh ; SECONDS variable
TICKS EQU 07Fh ; 20th of a second countdown timer
CRYSTAL EQU 11059200 ;The crystal speed
TMRCYCLE EQU 12 ;The number of crystal cycles per timer increment
TMR_SEC EQU CRYSTAL/TMRCYCLE ;The # of timer increments per second
F20TH_OF_SECOND EQU TMR_SEC * 0.05 ;46080
RESET_VALUE EQU 65536-F20TH_OF_SECOND

ORG 0000h ;Start assembly at 0000h
LJMP MAIN ;Jump to the main routine

ORG 001Bh ;This is where Timer 1 Interrupt Routine starts
PUSH ACC ;We'll use the accumulator, so we need to protect it
PUSH PSW ;Protect PSW flags
CLR TR1 ;Turn off timer 1 as we reset the value
MOV TH1,#HIGH (RESET_VALUE-5) ;Set the high byte of the reset value
MMOV TL1,#LOW (RESET_VALUE-5) ;Set the low byte of the reset value
SETB TR1 ;Restart timer 1 now that it has been initialized
jne TICKS,#10 cont
setb P0.0 ;inntitialise the seconds clock (at 1Hz, ie, a square wave of half a second duration)
cont:
DJNZ TICKS,EXIT_RTC ;Decrement TICKS, if not yet zero we exit immediately
MOV TICKS,#20 ;Reset the ticks variable
INC SECONDS ;Increment the second varaiable
clr P0.0
MOV A,SECONDS ;Move the seconds variable into the accumulator
CJNE A,#60,EXIT_RTC ;If we haven't counted 60 seconds, we're done.
MOV SECONDS,#0 ;Reset the seconds varaible
INC MINUTES ;Increment the number of minutes
MOV A,MINUTES ;Move the minutes variable into the accumulator
CJNE A,#60,EXIT_RTC ;If we haven't counted 60 minutes, we're done
MOV MINUTES,#0 ;Reset the minutes variable
INC HOURS ;Increment the hour variable
MOV A,HOURS ;Move the minutes variable into the accumulator
CJNE A,#12,EXIT_RTC ;If we haven't counted 12 hours, we're done
MOV HOURS,#0 ;Reset the hours variable
EXIT_RTC:
POP PSW ;Restore the PSW register
POP ACC ;Restore the accumulator
RETI ;Exit the interrupt routine

MAIN:
MOV TH1,#HIGH RESET_VALUE ;Initialize timer high-byte
MOV TL1,#LOW RESET_VALUE ;Initialize timer low-byte
MOV TMOD,#10h ;Set timer 1 to 16-bit mode
SETB TR1 ;Start timer 1 running
MOV IP,#8 ;Timer 1 Priority=1, all others = 0
MOV HOURS,#00 ;Initialize to 0 hours
MOV MINUTES,#00 ;Initialize to 0 minutes
MOV SECONDS,#00 ;Initialize to 0 seconds
MOV TICKS,#20 ;Initialize countdown tick counter to 20
SETB EA ;Initialize interrupts
SETB ET1 ;Initialize Timer 1 interrupt
setb p1.0 ;enable the first bank of 10 LEDs for first 10 seconds
setb p2.0 ;enable the first bank of 10 LEDs for first 10 minutes
setb p4.0 ;enable the first bank of 6 LEDs for first 6 hours
check:


;MONITORING SECONDS
jne SECONDS,#10 sfw1 ;check if 10 seconds have passed.
setb P1.1 ;enable the next bank of 10 leds for seconds
clr P1.0
sfw1:
jne SECONDS,#20 sfw2 ;check if 20 seconds have passed.
setb p1.2 ;enable the next bank of 10 leds for seconds
clr P1.1
sfw2:
jne SECONDS,#30 sfw3 ;check if 30 seconds have passed.
setb p1.3 ;enable the next bank of 10 leds for seconds
clr P1.2
sfw3:
jne SECONDS,#40 sfw4 ;check if 40 seconds have passed.
setb p1.4 ;enable the next bank of 10 leds for seconds
clr P1.3
sfw4:
jne SECONDS,#50 sfw5 ;check if 50 seconds have passed.
setb p1.5 ;enable the next bank of 10 leds for seconds
clr P1.4
sfw5:
setb P1.0 ;therefore less than 10 seconds have passed, enable the first bank


;MONITORING MINUTES
jne MINUTES,#10 mfw1 ;check if 10 minutes have passed.
setb p2.1 ;enable the next bank of 10 leds for minutes
clr P2.0
mfw1:
jne MINUTES,#20 mfw2 ;check if 20 minutes have passed.
setb p2.2 ;enable the next bank of 10 leds for minutes
clr P2.1
mfw2:
jne MINUTES,#30 mfw3 ;check if 30 minutes have passed.
setb p2.3 ;enable the next bank of 10 leds for minutes
clr P2.2
mfw3:
jne MINUTES,#40 mfw4 ;check if 40 minutes have passed.
setb p2.3 ;enable the next bank of 10 leds for minutes
clr P1.0
mfw4:
jne MINUTES,#50 mfw5 ;check if 50 minutes have passed.
setb p2.5 ;enable the next bank of 10 leds for minutes
clr P2.4
mfw5:
setb P2.0 ;therefore less than 10 minutes have passed,
enable the first bank

;MONITORING HOURS
jne HOURS,#6 hfw1 ;check if 6 hours have passed.
setb p3.1 ;enable the next bank of 6 leds for hours
clr P3.0
hfw5:
setb P3.0 ;therefore less than 6 hours have passed,
enable the first bank
sjmp check ;loop unendingly
END
 
alright guys, after a lot of trial and error I think this should be as close to the final circuit as I can get.
I'm sorry coz it's slightly large.
brief explanation: three 4017s, each driving the hours, minutes and seconds LEDs.
the clock signal for those comes from the 89s52.
the LEDs are arranged in groups of 10 (6 in case of hours) and have a common cathode connected to a resistor and connected to ground via a PNP transistor.
the trick is to switch the next transistor 'on' after the first 10 LEDs have finished blinking, get it?

please take a look at the circuit , It will kind of explain itself.
the thick lines coming out of the MCU are clock signals, while the other lines are control lines to control the switching transistors.

the code is still unfinished, there are issues with the port pins not wanting to source current.
I'll post it soon, you guys can check it. need help with that badly...
 

Attachments

  • final.png
    final.png
    143.2 KB · Views: 143
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top