CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

7seg+ds1307

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kamillas



Joined: 24 Oct 2011
Posts: 50

View user's profile Send private message

7seg+ds1307
PostPosted: Sun Nov 13, 2011 12:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 14, 2011 9:04 am     Reply with quote

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

View user's profile Send private message

thank's for your aide
PostPosted: Wed Nov 16, 2011 11:48 am     Reply with quote

hello sir"ezflyr", you really understand me, and I thank you for this very clear answer, and I thank your interest for my question.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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