yan zhang
/
NB_CLOCK_180505
clock
myScope/myclodriv.cpp@3:b8766d623f01, 2018-05-22 (annotated)
- Committer:
- donghuoyinzi
- Date:
- Tue May 22 09:10:05 2018 +0000
- Revision:
- 3:b8766d623f01
- Parent:
- 2:e54d9d87c6cb
0522
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donghuoyinzi | 0:17e9016529cf | 1 | #include "myclodriv.h" |
donghuoyinzi | 1:013b9fdc4e78 | 2 | #include "myclosenr.h" |
donghuoyinzi | 0:17e9016529cf | 3 | |
donghuoyinzi | 0:17e9016529cf | 4 | int cloDAct::snstpSe=0; int cloDAct::mnstpSe=0; int cloDAct::mcstpSe=0; int cloDAct::spstpSe=0; |
donghuoyinzi | 0:17e9016529cf | 5 | int cloDAct::sec; int cloDAct::min; int cloDAct::hour; |
donghuoyinzi | 0:17e9016529cf | 6 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 7 | Fun.: clodriv initialization。 |
donghuoyinzi | 0:17e9016529cf | 8 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 9 | Auth. Vesion:2018.1.5 |
donghuoyinzi | 0:17e9016529cf | 10 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 11 | void cloDAct::init(void) |
donghuoyinzi | 0:17e9016529cf | 12 | { |
donghuoyinzi | 0:17e9016529cf | 13 | |
donghuoyinzi | 0:17e9016529cf | 14 | } |
donghuoyinzi | 0:17e9016529cf | 15 | |
donghuoyinzi | 0:17e9016529cf | 16 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 17 | Fun.: initialization of cloDAct start。 |
donghuoyinzi | 0:17e9016529cf | 18 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 19 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 20 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 21 | void cloDAct::start(void) |
donghuoyinzi | 0:17e9016529cf | 22 | { |
donghuoyinzi | 0:17e9016529cf | 23 | |
donghuoyinzi | 0:17e9016529cf | 24 | } |
donghuoyinzi | 0:17e9016529cf | 25 | |
donghuoyinzi | 0:17e9016529cf | 26 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 27 | Fun.: initialization of cloDAct data。 |
donghuoyinzi | 0:17e9016529cf | 28 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 29 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 30 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 31 | void cloDAct::data(void) |
donghuoyinzi | 0:17e9016529cf | 32 | { |
donghuoyinzi | 1:013b9fdc4e78 | 33 | snstpSe=0; |
donghuoyinzi | 1:013b9fdc4e78 | 34 | mnstpSe=0; |
donghuoyinzi | 1:013b9fdc4e78 | 35 | mcstpSe=0; |
donghuoyinzi | 1:013b9fdc4e78 | 36 | spstpSe=0; |
donghuoyinzi | 1:013b9fdc4e78 | 37 | mcstpSe=0; |
donghuoyinzi | 0:17e9016529cf | 38 | |
donghuoyinzi | 3:b8766d623f01 | 39 | know::polSta[26]='0'; |
donghuoyinzi | 3:b8766d623f01 | 40 | know::polSta[33]='0'; |
donghuoyinzi | 3:b8766d623f01 | 41 | know::polSta[32]='0'; |
donghuoyinzi | 3:b8766d623f01 | 42 | know::polSta[34]='0'; |
donghuoyinzi | 0:17e9016529cf | 43 | |
donghuoyinzi | 2:e54d9d87c6cb | 44 | sec=0; |
donghuoyinzi | 2:e54d9d87c6cb | 45 | min=0; |
donghuoyinzi | 2:e54d9d87c6cb | 46 | hour=0; |
donghuoyinzi | 0:17e9016529cf | 47 | |
donghuoyinzi | 0:17e9016529cf | 48 | know::MotS0=0; |
donghuoyinzi | 0:17e9016529cf | 49 | know::MotS1=0; |
donghuoyinzi | 0:17e9016529cf | 50 | know::MotM0=0; |
donghuoyinzi | 0:17e9016529cf | 51 | know::MotM1=0; //电平归零 |
donghuoyinzi | 0:17e9016529cf | 52 | } |
donghuoyinzi | 0:17e9016529cf | 53 | |
donghuoyinzi | 0:17e9016529cf | 54 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 55 | Fun.: clodriv ready。 |
donghuoyinzi | 0:17e9016529cf | 56 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 57 | Auth. Vesion:2018.1.5 |
donghuoyinzi | 0:17e9016529cf | 58 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 59 | void cloDAct::ready(void) |
donghuoyinzi | 0:17e9016529cf | 60 | { |
donghuoyinzi | 0:17e9016529cf | 61 | |
donghuoyinzi | 0:17e9016529cf | 62 | } |
donghuoyinzi | 0:17e9016529cf | 63 | |
donghuoyinzi | 0:17e9016529cf | 64 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 65 | Fun.: |
donghuoyinzi | 0:17e9016529cf | 66 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 67 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 68 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 69 | void cloDAct::put_revok(void) |
donghuoyinzi | 0:17e9016529cf | 70 | { |
donghuoyinzi | 0:17e9016529cf | 71 | |
donghuoyinzi | 0:17e9016529cf | 72 | } |
donghuoyinzi | 0:17e9016529cf | 73 | |
donghuoyinzi | 0:17e9016529cf | 74 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 75 | Fun.: 秒针正常走时。 |
donghuoyinzi | 0:17e9016529cf | 76 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 77 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 78 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 79 | void cloDAct::put_snorm(void) |
donghuoyinzi | 0:17e9016529cf | 80 | { |
donghuoyinzi | 0:17e9016529cf | 81 | snstpSe++; |
donghuoyinzi | 0:17e9016529cf | 82 | |
donghuoyinzi | 0:17e9016529cf | 83 | switch(snstpSe){ |
donghuoyinzi | 0:17e9016529cf | 84 | case 17: //高电平脉冲宽度46.875ms/15.625ms=3 |
donghuoyinzi | 0:17e9016529cf | 85 | case 18: |
donghuoyinzi | 0:17e9016529cf | 86 | case 19: |
donghuoyinzi | 0:17e9016529cf | 87 | know::MotS1 = 1; //秒针马达端1输出高电平 |
donghuoyinzi | 0:17e9016529cf | 88 | know::MotS0 = 0; //秒针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 89 | break; |
donghuoyinzi | 0:17e9016529cf | 90 | case 20: |
donghuoyinzi | 0:17e9016529cf | 91 | know::MotS0 = 0; //秒针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 92 | know::MotS1 = 0; //秒针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 93 | break; |
donghuoyinzi | 0:17e9016529cf | 94 | case 21: |
donghuoyinzi | 0:17e9016529cf | 95 | case 22: |
donghuoyinzi | 0:17e9016529cf | 96 | case 23: //秒针马达端0输出脉冲 |
donghuoyinzi | 0:17e9016529cf | 97 | know::MotS0 = 1; //秒针马达端0输出高电平 |
donghuoyinzi | 0:17e9016529cf | 98 | know::MotS1 = 0; //秒针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 99 | break; |
donghuoyinzi | 0:17e9016529cf | 100 | case 24: |
donghuoyinzi | 0:17e9016529cf | 101 | know::MotS0 = 0; //秒针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 102 | know::MotS1 = 0; //秒针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 103 | snstpSe=16; |
donghuoyinzi | 0:17e9016529cf | 104 | break; |
donghuoyinzi | 0:17e9016529cf | 105 | default: |
donghuoyinzi | 0:17e9016529cf | 106 | break; |
donghuoyinzi | 0:17e9016529cf | 107 | } |
donghuoyinzi | 0:17e9016529cf | 108 | } |
donghuoyinzi | 0:17e9016529cf | 109 | |
donghuoyinzi | 0:17e9016529cf | 110 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 111 | Fun.: 分针正常走时。 |
donghuoyinzi | 0:17e9016529cf | 112 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 113 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 114 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 115 | void cloDAct::put_mnorm(void) |
donghuoyinzi | 0:17e9016529cf | 116 | { |
donghuoyinzi | 0:17e9016529cf | 117 | mnstpSe++; |
donghuoyinzi | 0:17e9016529cf | 118 | if(mnstpSe<=2){ //高电平脉冲宽度31.250ms/15.625ms=2 |
donghuoyinzi | 3:b8766d623f01 | 119 | switch(know::polSta[26]-'0'){ //周期交替标志 |
donghuoyinzi | 0:17e9016529cf | 120 | case 1: |
donghuoyinzi | 0:17e9016529cf | 121 | know::MotM1 = 1; //分针马达端1输出高电平 |
donghuoyinzi | 0:17e9016529cf | 122 | know::MotM0 = 0; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 123 | break; |
donghuoyinzi | 0:17e9016529cf | 124 | case 0: //分针马达端0输出脉冲 |
donghuoyinzi | 0:17e9016529cf | 125 | know::MotM0 = 1; //分针马达端0输出高电平 |
donghuoyinzi | 0:17e9016529cf | 126 | know::MotM1 = 0; //分针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 127 | break; |
donghuoyinzi | 0:17e9016529cf | 128 | default: |
donghuoyinzi | 0:17e9016529cf | 129 | break; |
donghuoyinzi | 0:17e9016529cf | 130 | } |
donghuoyinzi | 0:17e9016529cf | 131 | } |
donghuoyinzi | 0:17e9016529cf | 132 | else if(mnstpSe<=639&&mnstpSe>=3){ |
donghuoyinzi | 0:17e9016529cf | 133 | know::MotM0 = 0; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 134 | know::MotM1 = 0; //分针马达端1输出低电平 |
donghuoyinzi | 3:b8766d623f01 | 135 | switch(know::polSta[26]-'0'){ |
donghuoyinzi | 0:17e9016529cf | 136 | case 0: |
donghuoyinzi | 3:b8766d623f01 | 137 | know::polSta[26]='1'; //马达端1输出脉冲标识置1 |
donghuoyinzi | 0:17e9016529cf | 138 | break; |
donghuoyinzi | 0:17e9016529cf | 139 | case 1: |
donghuoyinzi | 3:b8766d623f01 | 140 | know::polSta[26]='0'; |
donghuoyinzi | 0:17e9016529cf | 141 | break; |
donghuoyinzi | 0:17e9016529cf | 142 | default: |
donghuoyinzi | 0:17e9016529cf | 143 | break; |
donghuoyinzi | 0:17e9016529cf | 144 | } |
donghuoyinzi | 0:17e9016529cf | 145 | } |
donghuoyinzi | 0:17e9016529cf | 146 | else mnstpSe=0; |
donghuoyinzi | 0:17e9016529cf | 147 | } |
donghuoyinzi | 0:17e9016529cf | 148 | |
donghuoyinzi | 0:17e9016529cf | 149 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 150 | Fun.: 分针追针。 |
donghuoyinzi | 0:17e9016529cf | 151 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 152 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 153 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 154 | void cloDAct::put_mchas(void) |
donghuoyinzi | 0:17e9016529cf | 155 | { |
donghuoyinzi | 0:17e9016529cf | 156 | mcstpSe++; |
donghuoyinzi | 0:17e9016529cf | 157 | |
donghuoyinzi | 0:17e9016529cf | 158 | switch(mcstpSe){ |
donghuoyinzi | 0:17e9016529cf | 159 | case 1: //高电平脉冲宽度31.250ms/15.625ms=2 |
donghuoyinzi | 0:17e9016529cf | 160 | case 2: |
donghuoyinzi | 0:17e9016529cf | 161 | know::MotM1 = 1; //分针马达端1输出高电平 |
donghuoyinzi | 0:17e9016529cf | 162 | know::MotM0 = 0; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 163 | break; |
donghuoyinzi | 0:17e9016529cf | 164 | case 3: |
donghuoyinzi | 0:17e9016529cf | 165 | case 4: |
donghuoyinzi | 0:17e9016529cf | 166 | know::MotM0 = 0; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 167 | know::MotM1 = 0; //分针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 168 | break; |
donghuoyinzi | 0:17e9016529cf | 169 | case 5: //高电平脉冲宽度31.250ms/15.625ms=2 |
donghuoyinzi | 0:17e9016529cf | 170 | case 6: |
donghuoyinzi | 0:17e9016529cf | 171 | know::MotM1 = 0; //分针马达端1输出高电平 |
donghuoyinzi | 0:17e9016529cf | 172 | know::MotM0 = 1; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 173 | break; |
donghuoyinzi | 0:17e9016529cf | 174 | case 7: |
donghuoyinzi | 0:17e9016529cf | 175 | case 8: |
donghuoyinzi | 0:17e9016529cf | 176 | know::MotM0 = 0; //分针马达端0输出低电平 |
donghuoyinzi | 0:17e9016529cf | 177 | know::MotM1 = 0; //分针马达端1输出低电平 |
donghuoyinzi | 0:17e9016529cf | 178 | mcstpSe=0; |
donghuoyinzi | 0:17e9016529cf | 179 | cmp_cmin(); |
donghuoyinzi | 3:b8766d623f01 | 180 | if(know::polSta[33]=='1'){ |
donghuoyinzi | 3:b8766d623f01 | 181 | know::polSta[27]='1'; |
donghuoyinzi | 1:013b9fdc4e78 | 182 | know::time1.attach_us(&cloSAct::isr_systick1,15625); |
donghuoyinzi | 0:17e9016529cf | 183 | } |
donghuoyinzi | 0:17e9016529cf | 184 | break; |
donghuoyinzi | 0:17e9016529cf | 185 | default: |
donghuoyinzi | 0:17e9016529cf | 186 | break; |
donghuoyinzi | 0:17e9016529cf | 187 | } |
donghuoyinzi | 0:17e9016529cf | 188 | } |
donghuoyinzi | 0:17e9016529cf | 189 | |
donghuoyinzi | 0:17e9016529cf | 190 | void cloDAct::cmp_cmin(void) |
donghuoyinzi | 0:17e9016529cf | 191 | { |
donghuoyinzi | 0:17e9016529cf | 192 | tm *tim; |
donghuoyinzi | 0:17e9016529cf | 193 | sec++; |
donghuoyinzi | 0:17e9016529cf | 194 | |
donghuoyinzi | 0:17e9016529cf | 195 | if(sec>=3){ //定时器3 15.625ms*24=375ms=1min 实际追1分钟(分针1格)只需要375ms |
donghuoyinzi | 0:17e9016529cf | 196 | sec=0; |
donghuoyinzi | 0:17e9016529cf | 197 | min++; |
donghuoyinzi | 0:17e9016529cf | 198 | if(min>=60){ |
donghuoyinzi | 0:17e9016529cf | 199 | min=0; |
donghuoyinzi | 0:17e9016529cf | 200 | hour++; |
donghuoyinzi | 0:17e9016529cf | 201 | if(hour>=12) hour=0; |
donghuoyinzi | 0:17e9016529cf | 202 | } |
donghuoyinzi | 0:17e9016529cf | 203 | } |
donghuoyinzi | 0:17e9016529cf | 204 | |
donghuoyinzi | 0:17e9016529cf | 205 | time_t seconds=time(NULL); |
donghuoyinzi | 0:17e9016529cf | 206 | tim=localtime(&seconds); |
donghuoyinzi | 0:17e9016529cf | 207 | |
donghuoyinzi | 0:17e9016529cf | 208 | if(tim->tm_min== min&&tim->tm_hour== hour){ |
donghuoyinzi | 0:17e9016529cf | 209 | min=54; //分针检测信号有效为11时59分 开始追针或等追 |
donghuoyinzi | 0:17e9016529cf | 210 | hour=11; |
donghuoyinzi | 3:b8766d623f01 | 211 | know::polSta[33]='1'; |
donghuoyinzi | 0:17e9016529cf | 212 | } |
donghuoyinzi | 0:17e9016529cf | 213 | } |
donghuoyinzi | 0:17e9016529cf | 214 | |
donghuoyinzi | 0:17e9016529cf | 215 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 216 | Fun.: miao停止,脉冲信号保持为低电平,最少停止250ms。 |
donghuoyinzi | 0:17e9016529cf | 217 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 218 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 219 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 220 | void cloDAct::put_sstop(void) |
donghuoyinzi | 0:17e9016529cf | 221 | { |
donghuoyinzi | 0:17e9016529cf | 222 | spstpSe++; //延时250ms |
donghuoyinzi | 0:17e9016529cf | 223 | |
donghuoyinzi | 0:17e9016529cf | 224 | switch(spstpSe){ |
donghuoyinzi | 0:17e9016529cf | 225 | case 1: |
donghuoyinzi | 0:17e9016529cf | 226 | know::MotS0 = 0; //Mot1秒针驱动引脚输出低电平 |
donghuoyinzi | 0:17e9016529cf | 227 | know::MotS1 = 0; |
donghuoyinzi | 0:17e9016529cf | 228 | break; |
donghuoyinzi | 0:17e9016529cf | 229 | case 17: |
donghuoyinzi | 0:17e9016529cf | 230 | cmp_sec(); |
donghuoyinzi | 3:b8766d623f01 | 231 | if((know::polSta[32]-'0')==1){ |
donghuoyinzi | 0:17e9016529cf | 232 | spstpSe=0; |
donghuoyinzi | 3:b8766d623f01 | 233 | know::polSta[28]='1'; //cmpsec_state="k"; |
donghuoyinzi | 0:17e9016529cf | 234 | } |
donghuoyinzi | 0:17e9016529cf | 235 | else spstpSe=16; |
donghuoyinzi | 0:17e9016529cf | 236 | break; |
donghuoyinzi | 0:17e9016529cf | 237 | default: |
donghuoyinzi | 0:17e9016529cf | 238 | break; |
donghuoyinzi | 0:17e9016529cf | 239 | } |
donghuoyinzi | 0:17e9016529cf | 240 | } |
donghuoyinzi | 0:17e9016529cf | 241 | |
donghuoyinzi | 0:17e9016529cf | 242 | void cloDAct::cmp_sec(void) |
donghuoyinzi | 0:17e9016529cf | 243 | { |
donghuoyinzi | 0:17e9016529cf | 244 | tm *tim; |
donghuoyinzi | 0:17e9016529cf | 245 | time_t seconds=time(NULL); |
donghuoyinzi | 0:17e9016529cf | 246 | tim=localtime(&seconds); |
donghuoyinzi | 3:b8766d623f01 | 247 | if(tim->tm_sec==56) know::polSta[32]='1'; //秒针检测信号有效为56秒 等追 |
donghuoyinzi | 0:17e9016529cf | 248 | } |
donghuoyinzi | 0:17e9016529cf | 249 | |
donghuoyinzi | 0:17e9016529cf | 250 | /***************************** |
donghuoyinzi | 0:17e9016529cf | 251 | Fun.: min停止。 |
donghuoyinzi | 0:17e9016529cf | 252 | Desc.: |
donghuoyinzi | 0:17e9016529cf | 253 | Auth. Vesion:2017.7.2 |
donghuoyinzi | 0:17e9016529cf | 254 | *****************************/ |
donghuoyinzi | 0:17e9016529cf | 255 | void cloDAct::put_mstop(void) |
donghuoyinzi | 0:17e9016529cf | 256 | { |
donghuoyinzi | 0:17e9016529cf | 257 | know::MotM0 = 0; //Mot1分针驱动引脚输出低电平 |
donghuoyinzi | 0:17e9016529cf | 258 | know::MotM1 = 0; |
donghuoyinzi | 0:17e9016529cf | 259 | cmp_smin(); |
donghuoyinzi | 3:b8766d623f01 | 260 | if((know::polSta[34]-'0')==1){ |
donghuoyinzi | 3:b8766d623f01 | 261 | know::polSta[29]='1'; //正常走时停止则为59分 |
donghuoyinzi | 1:013b9fdc4e78 | 262 | know::time1.attach_us(&cloSAct::isr_systick1,15625); |
donghuoyinzi | 0:17e9016529cf | 263 | } |
donghuoyinzi | 0:17e9016529cf | 264 | } |
donghuoyinzi | 0:17e9016529cf | 265 | |
donghuoyinzi | 0:17e9016529cf | 266 | void cloDAct::cmp_smin(void) |
donghuoyinzi | 0:17e9016529cf | 267 | { |
donghuoyinzi | 0:17e9016529cf | 268 | tm *tim; |
donghuoyinzi | 0:17e9016529cf | 269 | time_t seconds=time(NULL); |
donghuoyinzi | 0:17e9016529cf | 270 | tim=localtime(&seconds); |
donghuoyinzi | 3:b8766d623f01 | 271 | if(tim->tm_min==59) know::polSta[34]='1'; //待测 若追针后停止分针则为58分 pol_min=58 |
donghuoyinzi | 0:17e9016529cf | 272 | } |
donghuoyinzi | 0:17e9016529cf | 273 |