![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
yuppie2
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodehet by
rtsc.cpp@3:6cde88f8c50f, 2014-12-22 (annotated)
- Committer:
- pradeepvk2208
- Date:
- Mon Dec 22 10:10:38 2014 +0000
- Revision:
- 3:6cde88f8c50f
- Child:
- 4:374c51671a69
rtcfinalcode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pradeepvk2208 | 3:6cde88f8c50f | 1 | #include "rtsc.h" |
pradeepvk2208 | 3:6cde88f8c50f | 2 | SPI spi(PTD6, PTD7, PTD5); |
pradeepvk2208 | 3:6cde88f8c50f | 3 | DigitalOut cs(PTD2); |
pradeepvk2208 | 3:6cde88f8c50f | 4 | |
pradeepvk2208 | 3:6cde88f8c50f | 5 | void spiwrite(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 6 | { |
pradeepvk2208 | 3:6cde88f8c50f | 7 | cs=1; |
pradeepvk2208 | 3:6cde88f8c50f | 8 | cs=0; |
pradeepvk2208 | 3:6cde88f8c50f | 9 | spi.write(a); |
pradeepvk2208 | 3:6cde88f8c50f | 10 | spi.write(0x01); |
pradeepvk2208 | 3:6cde88f8c50f | 11 | } |
pradeepvk2208 | 3:6cde88f8c50f | 12 | |
pradeepvk2208 | 3:6cde88f8c50f | 13 | int spiread(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 14 | { |
pradeepvk2208 | 3:6cde88f8c50f | 15 | cs=1; |
pradeepvk2208 | 3:6cde88f8c50f | 16 | cs=0; |
pradeepvk2208 | 3:6cde88f8c50f | 17 | spi.write(a); |
pradeepvk2208 | 3:6cde88f8c50f | 18 | return(spi.write(0x00)); |
pradeepvk2208 | 3:6cde88f8c50f | 19 | } |
pradeepvk2208 | 3:6cde88f8c50f | 20 | char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) |
pradeepvk2208 | 3:6cde88f8c50f | 21 | { |
pradeepvk2208 | 3:6cde88f8c50f | 22 | year1= hexint(year1); |
pradeepvk2208 | 3:6cde88f8c50f | 23 | month1=hexint(month1); |
pradeepvk2208 | 3:6cde88f8c50f | 24 | date1=hexint(date1); |
pradeepvk2208 | 3:6cde88f8c50f | 25 | day1=hexint(day1); |
pradeepvk2208 | 3:6cde88f8c50f | 26 | hours1=hexint(hours1); |
pradeepvk2208 | 3:6cde88f8c50f | 27 | minutes1=hexint(minutes1); |
pradeepvk2208 | 3:6cde88f8c50f | 28 | seconds1=hexint(seconds1); |
pradeepvk2208 | 3:6cde88f8c50f | 29 | /*char y[3]=getstr(year); |
pradeepvk2208 | 3:6cde88f8c50f | 30 | char m[3]=getstr(month); |
pradeepvk2208 | 3:6cde88f8c50f | 31 | char dat[3]=getstr(date); |
pradeepvk2208 | 3:6cde88f8c50f | 32 | char da[3]=getstr(day); |
pradeepvk2208 | 3:6cde88f8c50f | 33 | char h[3]=getstr(hours); |
pradeepvk2208 | 3:6cde88f8c50f | 34 | char mi[3]=getstr(minutes); |
pradeepvk2208 | 3:6cde88f8c50f | 35 | char s[3]=getstr(seconds);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 36 | char time[15]; |
pradeepvk2208 | 3:6cde88f8c50f | 37 | sprintf(time,"%2d%2d%2d%2d%2d%2d%2d",year1,month1,date1,day1,hours1,minutes1,seconds1); |
pradeepvk2208 | 3:6cde88f8c50f | 38 | return(time); |
pradeepvk2208 | 3:6cde88f8c50f | 39 | |
pradeepvk2208 | 3:6cde88f8c50f | 40 | } |
pradeepvk2208 | 3:6cde88f8c50f | 41 | |
pradeepvk2208 | 3:6cde88f8c50f | 42 | int hexint(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 43 | { |
pradeepvk2208 | 3:6cde88f8c50f | 44 | a=(a/16)*10+(a%16); |
pradeepvk2208 | 3:6cde88f8c50f | 45 | return a; |
pradeepvk2208 | 3:6cde88f8c50f | 46 | } |
pradeepvk2208 | 3:6cde88f8c50f | 47 | |
pradeepvk2208 | 3:6cde88f8c50f | 48 | char* getts(void) |
pradeepvk2208 | 3:6cde88f8c50f | 49 | { |
pradeepvk2208 | 3:6cde88f8c50f | 50 | spi.format(8,3); |
pradeepvk2208 | 3:6cde88f8c50f | 51 | spi.frequency(1000000); |
pradeepvk2208 | 3:6cde88f8c50f | 52 | spiwrite(0x80); |
pradeepvk2208 | 3:6cde88f8c50f | 53 | spiwrite(0x81); |
pradeepvk2208 | 3:6cde88f8c50f | 54 | spiwrite(0x82); |
pradeepvk2208 | 3:6cde88f8c50f | 55 | spiwrite(0x83); |
pradeepvk2208 | 3:6cde88f8c50f | 56 | spiwrite(0x84); |
pradeepvk2208 | 3:6cde88f8c50f | 57 | spiwrite(0x85); |
pradeepvk2208 | 3:6cde88f8c50f | 58 | spiwrite(0x86); |
pradeepvk2208 | 3:6cde88f8c50f | 59 | for(int i=0;i<1000000;i++){ |
pradeepvk2208 | 3:6cde88f8c50f | 60 | int seconds=spiread(0x00); |
pradeepvk2208 | 3:6cde88f8c50f | 61 | int minutes =spiread(0x01); |
pradeepvk2208 | 3:6cde88f8c50f | 62 | int hours =spiread(0x02); |
pradeepvk2208 | 3:6cde88f8c50f | 63 | int day =spi.write(0x03); |
pradeepvk2208 | 3:6cde88f8c50f | 64 | int date =spiread(0x04); |
pradeepvk2208 | 3:6cde88f8c50f | 65 | int month =spiread(0x05); |
pradeepvk2208 | 3:6cde88f8c50f | 66 | int year =spiread(0x06); |
pradeepvk2208 | 3:6cde88f8c50f | 67 | cs = 1; |
pradeepvk2208 | 3:6cde88f8c50f | 68 | |
pradeepvk2208 | 3:6cde88f8c50f | 69 | wait(1); |
pradeepvk2208 | 3:6cde88f8c50f | 70 | printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds); |
pradeepvk2208 | 3:6cde88f8c50f | 71 | printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds)); |
pradeepvk2208 | 3:6cde88f8c50f | 72 | } |
pradeepvk2208 | 3:6cde88f8c50f | 73 | } |