|
|
View previous topic :: View next topic |
Author |
Message |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
7seg+ds1307 |
Posted: Sun Nov 13, 2011 12:34 pm |
|
|
I used the DS1307 and the 7 segment display to display the seconds, then how to treat a number of two figures, one by one, ie, how to use the mask,
my program :
Code: | ]#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#include "ds1307.c"
#define a 80
byte sec;
byte min;
byte hr;
byte day;
byte month;
byte year;
byte dow;
char tab[10]= {0xbF,0x6,0x5b,0x4f,0x66,0x6D,0x7D,0x7,0x7f,0x6F};
void main()
{
ds1307_init();
//ds1307_set_date_time(18,12,9,3,23,59,58); //day, month,year,dow,hr,min.sec
WHILE (1)
{
ds1307_get_time(hr,min,sec);
sec = (sec & 0xf0)
OUTPUT_A(0x01);
OUTPUT_B(tab[sec]);
delay_ms(20);
sec = (sec & 0x0f)
OUTPUT_A(0x02);
OUTPUT_B(tab[sec]);
delay_ms(20);
}
}
|
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Nov 14, 2011 9:04 am |
|
|
Hi,
First of all you've got three or four threads going about your 7 segment clock project. This is really bad form, and maybe one of the reasons you haven't received a reply to your latest question. Why not just stick to one thread until you finish your project??
Your question isn't really all that clear, but I think you are asking how to split a numerical integer value such as "36" into it's respective digits, namely "3" and "6", is that correct?
As you've found, you aren't going to do it with simple bit masking. You will need to use the modulus operator, '%' to do this.
I haven't tested it, but something like this should work:
Code: |
SecOnes = Secs % 10;
SecTens = Secs / 10;
|
The first statement gives you the remainder of Sec divided by 10, so if Secs was '36' you would get a 6. The second statement gives you the whole number of times that 10 goes into Secs with no remainder, and would give you a 3 if Secs was '36'. This code will work for a two digit number, but can be expanded to any number of digits by putting it inside a loop.
There may be other, faster, ways to do this, but this method should work.
John |
|
|
kamillas
Joined: 24 Oct 2011 Posts: 50
|
thank's for your aide |
Posted: Wed Nov 16, 2011 11:48 am |
|
|
hello sir"ezflyr", you really understand me, and I thank you for this very clear answer, and I thank your interest for my question. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|