4 Digit 7 Segment Clock

Status
Not open for further replies.

noor_dhaka

Newbie level 2
Joined
Jun 22, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dhaka, Bangladesh
Visit site
Activity points
1,303
Hi everyone, I want the assembly code for 4 digit 7 segment digital clock for PIC16F877A microcontroller. The two 7 segment for SECONDS & two for MINUTES. I need the code in assembly language not in C or other language. Im using MPLAB IDE v8.20 for coding & Proteus for designing the interface. Plz help me.
 

Dhaka, assembly language is not suitable for develop serious projects like digital clock,
I strongly recommend to switch on "C", probably MicroC from mikroe.com,
you have working example with total explanation...
best regards
 
I also agree PAskr U must go for a programming solution through MIcro C not asembly
because creating delay only through assembly is a great course the rest is an extra fatigue,
so Y nat a simple C
Regards
HIM
 

assembly language is not suitable for develop serious projects like digital clock,

Hi,

Thats rather a sweeping statement !

Wonder how I have been managing to do all my large assembler programs over all these years.. including RTCs, Glcds, ph monitors etc etc

Even Microchip provide examples of a real time clocks using Timer1 in Assembler, here is just one of several code examples they provide.
**broken link removed**
 
Instead they say, isn't very diffcult to do this in assembly. It's only displayed seconds and minutes? If yes, all you need to do is use the timer1 to generate an interruption every 5 mili seconds.

You will use this timer to scan the displays (to ensure that you will not see the displays blinking, we need scan every display at 50 times per second, 4 displays we will need 200 interrupts per second), and generate the base time for count seconds.
 

Dhaka, assembly language is not suitable for develop serious projects like digital clock,
I strongly recommend to switch on "C", probably MicroC from mikroe.com,
you have working example with total explanation...
best regards

Well actually im working on assembly language. I know it's very lengthy but It is possible.
 

Dhaka, assembly language is not suitable for develop serious projects like digital clock,
I strongly recommend to switch on "C", probably MicroC from mikroe.com,
you have working example with total explanation...
best regards

not suitable? Why?

The real reasons for writing C programs are:-

a. Easier to write a program
b.Easier to modify.
c. Good Readability
d. Previously written libraries available
e. portable (with little modification) to other micro.

But the bad news is that :- size of hex file is larger.
 


Wait a minute! 4 digit 7 segment digital clock -----The two 7 segment for SECONDS & two for MINUTES. You dont need to show the hour?
Its a clock or a timer --What do you want?
 

While not wishing to insult anybody, writing a TIMER program that counts seconds and minutes in assembly language is VERY easy and could probably be written in fewer bytes than a C program takes to initialize itself.

The basics are:
Use a timer (TMR1 would be easiest because it's 16 bits) to generate a 1 second interrupt
then count seconds units up until it reaches 10 then reset it to zero
count seconds tens up to 6 then reset it to zero
count minutes units up to 10 then reset it to zero
count minutes tens up to 6 then reset it to zero.

That short code could all be inside the ISR, leaving the main program to do the displaying:
convert the seconds units to 7 segment pattern in a look up table and put the bits out on a port.
enable the seconds units digit by turning a port bit on to drive it's common connection (best through a driver device to let it draw more current)
wait a few milliseconds
clear the port bits
wait a millisecond
repeat the whole process for the remaning digits.

Without writing it, I would estimate about 120 instructions would be needed in total, that includes the look-up table.

Brian.
 

Hi

As I mentioned earlier Microchip publish many assembler rtc examples, here one from the 18F datasheets, just 30 instructions !
 

Attachments

  • Doc1.pdf
    95.3 KB · Views: 180

@wp100 - thanks for confirming my statement. Your example doesn't include the ISR wrapper or display code but it reafirms that I think it can be done in no more than 120 bytes.
@Baas Rietrot - the code you posted is rather specific to an X86 processor and uses OS calls so it would not easily adapt to a 16F877A but the principle of linking asm and high level code is absolutely valid.

Thinking about it, the PIC instruction set makes counting down more efficient than counting up so it might be possible to save a few instructions by reversing the count sequence and adjusting the segment look-up table so the correct digits were still shown.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…