![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sdcard
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodeyuppie by
main.cpp@3:6cde88f8c50f, 2014-12-22 (annotated)
- Committer:
- pradeepvk2208
- Date:
- Mon Dec 22 10:10:38 2014 +0000
- Revision:
- 3:6cde88f8c50f
- Parent:
- 2:d67cd8569921
- Child:
- 5:3979ca24777a
rtcfinalcode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pradeepvk2208 | 3:6cde88f8c50f | 1 | #include "rtsc.h" |
duke970 | 0:d5e352a3ea98 | 2 | |
pradeepvk2208 | 3:6cde88f8c50f | 3 | |
pradeepvk2208 | 1:d360ad53f8fd | 4 | |
duke970 | 0:d5e352a3ea98 | 5 | |
duke970 | 0:d5e352a3ea98 | 6 | int main() |
duke970 | 0:d5e352a3ea98 | 7 | { |
duke970 | 0:d5e352a3ea98 | 8 | |
duke970 | 0:d5e352a3ea98 | 9 | |
duke970 | 0:d5e352a3ea98 | 10 | |
pradeepvk2208 | 3:6cde88f8c50f | 11 | /*// Setup the spi for 8 bit data, high steady state clock, |
duke970 | 0:d5e352a3ea98 | 12 | // second edge capture, with a 1MHz clock rate |
duke970 | 0:d5e352a3ea98 | 13 | spi.format(8,3); |
duke970 | 0:d5e352a3ea98 | 14 | spi.frequency(1000000); |
duke970 | 0:d5e352a3ea98 | 15 | |
duke970 | 0:d5e352a3ea98 | 16 | // Send the commands to write to test the seconds register |
pradeepvk2208 | 3:6cde88f8c50f | 17 | cs = 0; |
duke970 | 0:d5e352a3ea98 | 18 | spi.write(0x80); // set write register to seconds |
pradeepvk2208 | 3:6cde88f8c50f | 19 | spi.write(0x00); // send value of one*//*spiwrite(0x80); |
pradeepvk2208 | 2:d67cd8569921 | 20 | spiwrite(0x81); |
pradeepvk2208 | 2:d67cd8569921 | 21 | spiwrite(0x82); |
pradeepvk2208 | 2:d67cd8569921 | 22 | spiwrite(0x83); |
pradeepvk2208 | 2:d67cd8569921 | 23 | spiwrite(0x84); |
pradeepvk2208 | 2:d67cd8569921 | 24 | spiwrite(0x85); |
pradeepvk2208 | 3:6cde88f8c50f | 25 | spiwrite(0x86);*/ |
duke970 | 0:d5e352a3ea98 | 26 | |
pradeepvk2208 | 2:d67cd8569921 | 27 | |
pradeepvk2208 | 2:d67cd8569921 | 28 | /* cs=1; |
duke970 | 0:d5e352a3ea98 | 29 | cs=0; |
duke970 | 0:d5e352a3ea98 | 30 | spi.write(0x81); //write reg to minutes |
duke970 | 0:d5e352a3ea98 | 31 | spi.write(0x00); |
pradeepvk2208 | 1:d360ad53f8fd | 32 | spiwrite(0x81); |
duke970 | 0:d5e352a3ea98 | 33 | |
duke970 | 0:d5e352a3ea98 | 34 | cs=1; |
duke970 | 0:d5e352a3ea98 | 35 | cs=0; |
duke970 | 0:d5e352a3ea98 | 36 | |
duke970 | 0:d5e352a3ea98 | 37 | spi.write(0x82); //write reg to minutes |
duke970 | 0:d5e352a3ea98 | 38 | spi.write(0x01); |
duke970 | 0:d5e352a3ea98 | 39 | |
duke970 | 0:d5e352a3ea98 | 40 | cs=1; |
duke970 | 0:d5e352a3ea98 | 41 | |
duke970 | 0:d5e352a3ea98 | 42 | cs = 0; |
duke970 | 0:d5e352a3ea98 | 43 | spi.write(0x83); // set write register to seconds |
duke970 | 0:d5e352a3ea98 | 44 | spi.write(0x01); // send value of one |
duke970 | 0:d5e352a3ea98 | 45 | |
duke970 | 0:d5e352a3ea98 | 46 | cs=1; |
duke970 | 0:d5e352a3ea98 | 47 | |
duke970 | 0:d5e352a3ea98 | 48 | cs = 0; |
duke970 | 0:d5e352a3ea98 | 49 | spi.write(0x84); // set write register to seconds |
duke970 | 0:d5e352a3ea98 | 50 | spi.write(0x01); // send value of one |
duke970 | 0:d5e352a3ea98 | 51 | |
duke970 | 0:d5e352a3ea98 | 52 | cs=1; |
duke970 | 0:d5e352a3ea98 | 53 | |
duke970 | 0:d5e352a3ea98 | 54 | cs = 0; |
duke970 | 0:d5e352a3ea98 | 55 | spi.write(0x85); // set write register to seconds |
duke970 | 0:d5e352a3ea98 | 56 | spi.write(0x01); // send value of one |
duke970 | 0:d5e352a3ea98 | 57 | |
duke970 | 0:d5e352a3ea98 | 58 | cs=1; |
duke970 | 0:d5e352a3ea98 | 59 | |
duke970 | 0:d5e352a3ea98 | 60 | cs = 0; |
duke970 | 0:d5e352a3ea98 | 61 | spi.write(0x86); // set write register to seconds |
duke970 | 0:d5e352a3ea98 | 62 | spi.write(0x01); // send value of one |
duke970 | 0:d5e352a3ea98 | 63 | |
pradeepvk2208 | 2:d67cd8569921 | 64 | cs=1;*/ |
duke970 | 0:d5e352a3ea98 | 65 | // Receive the contents of the seconds register |
duke970 | 0:d5e352a3ea98 | 66 | |
pradeepvk2208 | 3:6cde88f8c50f | 67 | /* for(int i=0;i<1000000;i++){ |
duke970 | 0:d5e352a3ea98 | 68 | |
duke970 | 0:d5e352a3ea98 | 69 | |
pradeepvk2208 | 3:6cde88f8c50f | 70 | cs=0; |
duke970 | 0:d5e352a3ea98 | 71 | spi.write(0x00); // set read register to seconds |
pradeepvk2208 | 2:d67cd8569921 | 72 | int seconds = spi.write(0x00); // read the value*/ |
pradeepvk2208 | 3:6cde88f8c50f | 73 | //int seconds=spiread(0x00); |
duke970 | 0:d5e352a3ea98 | 74 | |
pradeepvk2208 | 2:d67cd8569921 | 75 | /*cs=1; |
duke970 | 0:d5e352a3ea98 | 76 | cs=0; |
duke970 | 0:d5e352a3ea98 | 77 | |
pradeepvk2208 | 2:d67cd8569921 | 78 | spi.write(0x01);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 79 | //int minutes =spiread(0x01); |
duke970 | 0:d5e352a3ea98 | 80 | |
duke970 | 0:d5e352a3ea98 | 81 | |
pradeepvk2208 | 2:d67cd8569921 | 82 | /*cs=1; |
duke970 | 0:d5e352a3ea98 | 83 | cs=0; |
duke970 | 0:d5e352a3ea98 | 84 | |
pradeepvk2208 | 2:d67cd8569921 | 85 | spi.write(0x02);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 86 | //int hours =spiread(0x02); |
pradeepvk2208 | 2:d67cd8569921 | 87 | /* cs = 1; //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC |
duke970 | 0:d5e352a3ea98 | 88 | |
duke970 | 0:d5e352a3ea98 | 89 | cs=0; |
duke970 | 0:d5e352a3ea98 | 90 | |
pradeepvk2208 | 2:d67cd8569921 | 91 | spi.write(0x03);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 92 | //int day =spi.write(0x03); |
pradeepvk2208 | 2:d67cd8569921 | 93 | /*cs = 1; |
duke970 | 0:d5e352a3ea98 | 94 | |
duke970 | 0:d5e352a3ea98 | 95 | cs=0; |
duke970 | 0:d5e352a3ea98 | 96 | |
pradeepvk2208 | 2:d67cd8569921 | 97 | spi.write(0x04);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 98 | // int date =spiread(0x04); |
pradeepvk2208 | 2:d67cd8569921 | 99 | /*cs = 1; |
duke970 | 0:d5e352a3ea98 | 100 | |
duke970 | 0:d5e352a3ea98 | 101 | cs=0; |
duke970 | 0:d5e352a3ea98 | 102 | |
pradeepvk2208 | 2:d67cd8569921 | 103 | spi.write(0x05);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 104 | //int month =spiread(0x05); |
pradeepvk2208 | 2:d67cd8569921 | 105 | /*cs = 1; |
duke970 | 0:d5e352a3ea98 | 106 | |
duke970 | 0:d5e352a3ea98 | 107 | cs=0; |
duke970 | 0:d5e352a3ea98 | 108 | |
pradeepvk2208 | 2:d67cd8569921 | 109 | spi.write(0x06);*/ |
pradeepvk2208 | 3:6cde88f8c50f | 110 | // int year =spiread(0x06); |
pradeepvk2208 | 3:6cde88f8c50f | 111 | //cs = 1; |
duke970 | 0:d5e352a3ea98 | 112 | |
pradeepvk2208 | 3:6cde88f8c50f | 113 | //wait(1); |
duke970 | 0:d5e352a3ea98 | 114 | //This printf function is to check the timestamp function in the terminal output |
pradeepvk2208 | 3:6cde88f8c50f | 115 | // printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds); |
pradeepvk2208 | 3:6cde88f8c50f | 116 | // printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds)); |
pradeepvk2208 | 3:6cde88f8c50f | 117 | //}*/ |
duke970 | 0:d5e352a3ea98 | 118 | |
pradeepvk2208 | 3:6cde88f8c50f | 119 | getts(); |
duke970 | 0:d5e352a3ea98 | 120 | |
duke970 | 0:d5e352a3ea98 | 121 | |
duke970 | 0:d5e352a3ea98 | 122 | |
pradeepvk2208 | 1:d360ad53f8fd | 123 | } |
pradeepvk2208 | 1:d360ad53f8fd | 124 | |
pradeepvk2208 | 3:6cde88f8c50f | 125 | /* void spiwrite(int a) |
pradeepvk2208 | 1:d360ad53f8fd | 126 | { |
pradeepvk2208 | 1:d360ad53f8fd | 127 | cs=1; |
pradeepvk2208 | 1:d360ad53f8fd | 128 | cs=0; |
pradeepvk2208 | 1:d360ad53f8fd | 129 | spi.write(a); |
pradeepvk2208 | 1:d360ad53f8fd | 130 | spi.write(0x01); |
pradeepvk2208 | 2:d67cd8569921 | 131 | } |
pradeepvk2208 | 2:d67cd8569921 | 132 | int spiread(int a) |
pradeepvk2208 | 2:d67cd8569921 | 133 | { |
pradeepvk2208 | 2:d67cd8569921 | 134 | cs=1; |
pradeepvk2208 | 2:d67cd8569921 | 135 | cs=0; |
pradeepvk2208 | 2:d67cd8569921 | 136 | spi.write(a); |
pradeepvk2208 | 2:d67cd8569921 | 137 | return(spi.write(0x00)); |
pradeepvk2208 | 2:d67cd8569921 | 138 | } |
pradeepvk2208 | 2:d67cd8569921 | 139 | char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) |
pradeepvk2208 | 2:d67cd8569921 | 140 | { |
pradeepvk2208 | 2:d67cd8569921 | 141 | year1= hexint(year1); |
pradeepvk2208 | 2:d67cd8569921 | 142 | month1=hexint(month1); |
pradeepvk2208 | 2:d67cd8569921 | 143 | date1=hexint(date1); |
pradeepvk2208 | 2:d67cd8569921 | 144 | day1=hexint(day1); |
pradeepvk2208 | 2:d67cd8569921 | 145 | hours1=hexint(hours1); |
pradeepvk2208 | 2:d67cd8569921 | 146 | minutes1=hexint(minutes1); |
pradeepvk2208 | 2:d67cd8569921 | 147 | seconds1=hexint(seconds1); |
pradeepvk2208 | 3:6cde88f8c50f | 148 | char y[3]=getstr(year); |
pradeepvk2208 | 2:d67cd8569921 | 149 | char m[3]=getstr(month); |
pradeepvk2208 | 2:d67cd8569921 | 150 | char dat[3]=getstr(date); |
pradeepvk2208 | 2:d67cd8569921 | 151 | char da[3]=getstr(day); |
pradeepvk2208 | 2:d67cd8569921 | 152 | char h[3]=getstr(hours); |
pradeepvk2208 | 2:d67cd8569921 | 153 | char mi[3]=getstr(minutes); |
pradeepvk2208 | 3:6cde88f8c50f | 154 | char s[3]=getstr(seconds); |
pradeepvk2208 | 2:d67cd8569921 | 155 | char time[15]; |
pradeepvk2208 | 2:d67cd8569921 | 156 | sprintf(time,"%2d%2d%2d%2d%2d%2d%2d",year1,month1,date1,day1,hours1,minutes1,seconds1); |
pradeepvk2208 | 2:d67cd8569921 | 157 | return(time); |
pradeepvk2208 | 2:d67cd8569921 | 158 | |
pradeepvk2208 | 2:d67cd8569921 | 159 | } |
pradeepvk2208 | 2:d67cd8569921 | 160 | |
pradeepvk2208 | 2:d67cd8569921 | 161 | int hexint(int a) |
pradeepvk2208 | 2:d67cd8569921 | 162 | { |
pradeepvk2208 | 2:d67cd8569921 | 163 | a=(a/16)*10+(a%16); |
pradeepvk2208 | 2:d67cd8569921 | 164 | return a; |
pradeepvk2208 | 3:6cde88f8c50f | 165 | }*/ |