├── LICENSE ├── README.md ├── images ├── test ├── v0_0_1_pic_01.jpg └── v0_0_1_sc_01.jpg ├── v0.0.1 W ds3231 └── sketch.ino └── v0.0.1 └── main.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 lydasia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openltc 2 | An Open Source SMPTE Linear Timecode Generator Based on ATmega328P(Arduino UNO). 3 | 4 | #Arduino #LTC #TimeCode 5 | 6 | ![image](https://github.com/lydasia/openltc/raw/main/images/v0_0_1_pic_01.jpg) 7 | ![image](https://github.com/lydasia/openltc/raw/main/images/v0_0_1_sc_01.jpg) 8 | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/FPzze3i_KXw/0.jpg)](https://www.youtube.com/watch?v=FPzze3i_KXw) 9 | -------------------------------------------------------------------------------- /images/test: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /images/v0_0_1_pic_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lydasia/openltc/ba16474e28691d0f1e969fee24b75a1d191129d6/images/v0_0_1_pic_01.jpg -------------------------------------------------------------------------------- /images/v0_0_1_sc_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lydasia/openltc/ba16474e28691d0f1e969fee24b75a1d191129d6/images/v0_0_1_sc_01.jpg -------------------------------------------------------------------------------- /v0.0.1 W ds3231/sketch.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define highLevel 82 7 | #define lowLevel 44 8 | #define groundLevel 63 9 | 10 | struct ts t; 11 | 12 | volatile unsigned char hourCount = 0; 13 | volatile unsigned char minuteCount = 0; 14 | volatile unsigned char secondCount = 0; 15 | volatile unsigned char frameCount = 0; 16 | 17 | volatile unsigned char bitCount = 0; 18 | volatile unsigned char updateCnt = 0; 19 | volatile unsigned char currentBit = 0; 20 | 21 | volatile unsigned char lastLevel = 0; 22 | volatile unsigned char polarBit = 0; 23 | 24 | void setup() 25 | { 26 | Wire.begin(); 27 | DS3231_init(DS3231_INTCN); 28 | DS3231_get(&t); 29 | unsigned char initSecond = t.sec; 30 | while(1) 31 | { 32 | delay(1); 33 | DS3231_get(&t); 34 | if(initSecond != t.sec) 35 | { 36 | hourCount = t.hour; 37 | minuteCount = t.min; 38 | secondCount = t.sec; 39 | break; 40 | } 41 | } 42 | 43 | DDRD = 0b00101000; 44 | 45 | TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); 46 | TCCR0B = _BV(WGM02) | _BV(CS00); 47 | OCR0A = 1; 48 | OCR0B = 0; 49 | 50 | TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); 51 | TCCR2B = _BV(WGM22) | _BV(CS20); 52 | OCR2A = 127; 53 | OCR2B = groundLevel; 54 | 55 | TCCR1A = 0b00 << WGM10; 56 | TCCR1B = 0b01 << WGM12 | 0b001 << CS10; 57 | OCR1A = 3995;//3999@25fps 58 | TIMSK1 = 1 << OCIE1A; 59 | sei(); 60 | 61 | while(1) 62 | ; 63 | } 64 | 65 | void setLevel(void) 66 | { 67 | switch(bitCount) 68 | { 69 | case 0: 70 | polarBit = 0; 71 | currentBit = (((frameCount % 10) >> (1 - 1)) & 1); 72 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 73 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 74 | break; 75 | case 1: 76 | currentBit = (((frameCount % 10) >> (2 - 1)) & 1); 77 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 78 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 79 | break; 80 | case 2: 81 | currentBit = (((frameCount % 10) >> (3 - 1)) & 1); 82 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 83 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 84 | break; 85 | case 3: 86 | currentBit = (((frameCount % 10) >> (4 - 1)) & 1); 87 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 88 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 89 | break; 90 | case 4: 91 | currentBit = 0; 92 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 93 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 94 | break; 95 | case 5: 96 | currentBit = 0; 97 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 98 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 99 | break; 100 | case 6: 101 | currentBit = 0; 102 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 103 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 104 | break; 105 | case 7: 106 | currentBit = 0; 107 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 108 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 109 | break; 110 | case 8: 111 | currentBit = (((frameCount / 10 % 10) >> (1 - 1)) & 1); 112 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 113 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 114 | break; 115 | case 9: 116 | currentBit = (((frameCount / 10 % 10) >> (2 - 1)) & 1); 117 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 118 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 119 | break; 120 | case 10: 121 | currentBit = 0; 122 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 123 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 124 | break; 125 | case 11: 126 | currentBit = 0; 127 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 128 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 129 | break; 130 | case 12: 131 | currentBit = 0; 132 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 133 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 134 | break; 135 | case 13: 136 | currentBit = 0; 137 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 138 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 139 | break; 140 | case 14: 141 | currentBit = 0; 142 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 143 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 144 | break; 145 | case 15: 146 | currentBit = 0; 147 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 148 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 149 | break; 150 | case 16: 151 | currentBit = (((secondCount % 10) >> (1 - 1)) & 1); 152 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 153 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 154 | break; 155 | case 17: 156 | currentBit = (((secondCount % 10) >> (2 - 1)) & 1); 157 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 158 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 159 | break; 160 | case 18: 161 | currentBit = (((secondCount % 10) >> (3 - 1)) & 1); 162 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 163 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 164 | break; 165 | case 19: 166 | currentBit = (((secondCount % 10) >> (4 - 1)) & 1); 167 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 168 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 169 | break; 170 | case 20: 171 | currentBit = 0; 172 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 173 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 174 | break; 175 | case 21: 176 | currentBit = 0; 177 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 178 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 179 | break; 180 | case 22: 181 | currentBit = 0; 182 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 183 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 184 | break; 185 | case 23: 186 | currentBit = 0; 187 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 188 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 189 | break; 190 | case 24: 191 | currentBit = (((secondCount /10 % 10) >> (1 - 1)) & 1); 192 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 193 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 194 | break; 195 | case 25: 196 | currentBit = (((secondCount /10 % 10) >> (2 - 1)) & 1); 197 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 198 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 199 | break; 200 | case 26: 201 | currentBit = (((secondCount /10 % 10) >> (3 - 1)) & 1); 202 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 203 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 204 | break; 205 | case 27: 206 | currentBit = 0; 207 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 208 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 209 | break; 210 | case 28: 211 | currentBit = 0; 212 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 213 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 214 | break; 215 | case 29: 216 | currentBit = 0; 217 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 218 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 219 | break; 220 | case 30: 221 | currentBit = 0; 222 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 223 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 224 | break; 225 | case 31: 226 | currentBit = 0; 227 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 228 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 229 | break; 230 | case 32: 231 | currentBit = (((minuteCount % 10) >> (1 - 1)) & 1); 232 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 233 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 234 | break; 235 | case 33: 236 | currentBit = (((minuteCount % 10) >> (2 - 1)) & 1); 237 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 238 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 239 | break; 240 | case 34: 241 | currentBit = (((minuteCount % 10) >> (3 - 1)) & 1); 242 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 243 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 244 | break; 245 | case 35: 246 | currentBit = (((minuteCount % 10) >> (4 - 1)) & 1); 247 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 248 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 249 | break; 250 | case 36: 251 | currentBit = 0; 252 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 253 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 254 | break; 255 | case 37: 256 | currentBit = 0; 257 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 258 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 259 | break; 260 | case 38: 261 | currentBit = 0; 262 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 263 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 264 | break; 265 | case 39: 266 | currentBit = 0; 267 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 268 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 269 | break; 270 | case 40: 271 | currentBit = (((minuteCount / 10 % 10) >> (1 - 1)) & 1); 272 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 273 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 274 | break; 275 | case 41: 276 | currentBit = (((minuteCount / 10 % 10) >> (2 - 1)) & 1); 277 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 278 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 279 | break; 280 | case 42: 281 | currentBit = (((minuteCount / 10 % 10) >> (3 - 1)) & 1); 282 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 283 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 284 | break; 285 | case 43: 286 | currentBit = 0; 287 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 288 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 289 | break; 290 | case 44: 291 | currentBit = 0; 292 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 293 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 294 | break; 295 | case 45: 296 | currentBit = 0; 297 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 298 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 299 | break; 300 | case 46: 301 | currentBit = 0; 302 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 303 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 304 | break; 305 | case 47: 306 | currentBit = 0; 307 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 308 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 309 | break; 310 | case 48: 311 | currentBit = (((hourCount % 10) >> (1 - 1)) & 1); 312 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 313 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 314 | break; 315 | case 49: 316 | currentBit = (((hourCount % 10) >> (2 - 1)) & 1); 317 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 318 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 319 | break; 320 | case 50: 321 | currentBit = (((hourCount % 10) >> (3 - 1)) & 1); 322 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 323 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 324 | break; 325 | case 51: 326 | currentBit = (((hourCount % 10) >> (4 - 1)) & 1); 327 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 328 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 329 | break; 330 | case 52: 331 | currentBit = 0; 332 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 333 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 334 | break; 335 | case 53: 336 | currentBit = 0; 337 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 338 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 339 | break; 340 | case 54: 341 | currentBit = 0; 342 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 343 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 344 | break; 345 | case 55: 346 | currentBit = 0; 347 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 348 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 349 | break; 350 | case 56: 351 | currentBit = (((hourCount / 10 % 10) >> (1 - 1)) & 1); 352 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 353 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 354 | break; 355 | case 57: 356 | currentBit = (((hourCount / 10 % 10) >> (2 - 1)) & 1); 357 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 358 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 359 | break; 360 | case 58: 361 | currentBit = 0; 362 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 363 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 364 | break; 365 | case 59: 366 | currentBit = (polarBit); 367 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 368 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 369 | break; 370 | case 60: 371 | currentBit = 0; 372 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 373 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 374 | break; 375 | case 61: 376 | currentBit = 0; 377 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 378 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 379 | break; 380 | case 62: 381 | currentBit = 0; 382 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 383 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 384 | break; 385 | case 63: 386 | currentBit = 0; 387 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 388 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 389 | break; 390 | case 64: 391 | currentBit = 0; 392 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 393 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 394 | break; 395 | case 65: 396 | currentBit = 0; 397 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 398 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 399 | break; 400 | case 66: 401 | currentBit = 1; 402 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 403 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 404 | break; 405 | case 67: 406 | currentBit = 1; 407 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 408 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 409 | break; 410 | case 68: 411 | currentBit = 1; 412 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 413 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 414 | break; 415 | case 69: 416 | currentBit = 1; 417 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 418 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 419 | break; 420 | case 70: 421 | currentBit = 1; 422 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 423 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 424 | break; 425 | case 71: 426 | currentBit = 1; 427 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 428 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 429 | break; 430 | case 72: 431 | currentBit = 1; 432 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 433 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 434 | break; 435 | case 73: 436 | currentBit = 1; 437 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 438 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 439 | break; 440 | case 74: 441 | currentBit = 1; 442 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 443 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 444 | break; 445 | case 75: 446 | currentBit = 1; 447 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 448 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 449 | break; 450 | case 76: 451 | currentBit = 1; 452 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 453 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 454 | break; 455 | case 77: 456 | currentBit = 1; 457 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 458 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 459 | break; 460 | case 78: 461 | currentBit = 0; 462 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 463 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 464 | break; 465 | case 79: 466 | currentBit = 1; 467 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(highLevel):(lowLevel); 468 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 469 | break; 470 | default: 471 | OCR2B = groundLevel; 472 | } 473 | } 474 | 475 | void timeUpdate(void) 476 | { 477 | 478 | if(bitCount < 79) 479 | { 480 | bitCount ++; 481 | } 482 | else 483 | { 484 | bitCount = 0; 485 | if(frameCount < 24) 486 | { 487 | frameCount ++; 488 | } 489 | else 490 | { 491 | frameCount = 0; 492 | if(secondCount < 59) 493 | { 494 | secondCount ++; 495 | } 496 | else 497 | { 498 | secondCount = 0; 499 | if(minuteCount < 59) 500 | { 501 | minuteCount ++; 502 | } 503 | else 504 | { 505 | minuteCount = 0; 506 | if(hourCount < 23) 507 | { 508 | hourCount ++; 509 | } 510 | else 511 | { 512 | hourCount = 0; 513 | } 514 | } 515 | } 516 | } 517 | } 518 | 519 | } 520 | 521 | ISR(TIMER1_COMPA_vect) 522 | { 523 | 524 | setLevel(); 525 | 526 | if(updateCnt == 0) 527 | { 528 | updateCnt ++; 529 | } 530 | else 531 | { 532 | updateCnt = 0; 533 | timeUpdate(); 534 | } 535 | } 536 | -------------------------------------------------------------------------------- /v0.0.1/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | volatile unsigned char hourCount = 0; 5 | volatile unsigned char minuteCount = 0; 6 | volatile unsigned char secondCount = 0; 7 | volatile unsigned char frameCount = 0; 8 | 9 | volatile unsigned char bitCount = 0; 10 | volatile unsigned char updateCnt = 0; 11 | volatile unsigned char currentBit = 0; 12 | 13 | volatile unsigned char lastLevel = 0; 14 | volatile unsigned char polarBit = 0; 15 | 16 | int main(void) 17 | { 18 | DDRD = 0b00101000; 19 | DDRB = 0b00110000; 20 | 21 | //50% PWM Ground Level 22 | TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00); 23 | TCCR0B = _BV(WGM02) | _BV(CS00); 24 | OCR0A = 1; 25 | OCR0B = 0; 26 | 27 | //Set Output to Ground Level 28 | TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); 29 | TCCR2B = _BV(WGM22) | _BV(CS20); 30 | OCR2A = 127; 31 | OCR2B = 63; 32 | 33 | //Per 1/2-Bit Interrupt 34 | TCCR1A = 0b00 << WGM10; 35 | TCCR1B = 0b01 << WGM12 | 0b001 << CS10; 36 | OCR1A = 3995;//3999@25fps 37 | TIMSK1 = 1 << OCIE1A; 38 | sei(); 39 | 40 | while(1) 41 | { 42 | } 43 | } 44 | 45 | void setLevel(void) 46 | { 47 | switch(bitCount) 48 | { 49 | case 0: 50 | polarBit = 0; 51 | currentBit = (((frameCount % 10) >> (1 - 1)) & 1); 52 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 53 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 54 | break; 55 | case 1: 56 | currentBit = (((frameCount % 10) >> (2 - 1)) & 1); 57 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 58 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 59 | break; 60 | case 2: 61 | currentBit = (((frameCount % 10) >> (3 - 1)) & 1); 62 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 63 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 64 | break; 65 | case 3: 66 | currentBit = (((frameCount % 10) >> (4 - 1)) & 1); 67 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 68 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 69 | break; 70 | case 4: 71 | currentBit = 0; 72 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 73 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 74 | break; 75 | case 5: 76 | currentBit = 0; 77 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 78 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 79 | break; 80 | case 6: 81 | currentBit = 0; 82 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 83 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 84 | break; 85 | case 7: 86 | currentBit = 0; 87 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 88 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 89 | break; 90 | case 8: 91 | currentBit = (((frameCount / 10 % 10) >> (1 - 1)) & 1); 92 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 93 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 94 | break; 95 | case 9: 96 | currentBit = (((frameCount / 10 % 10) >> (2 - 1)) & 1); 97 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 98 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 99 | break; 100 | case 10: 101 | currentBit = 0; 102 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 103 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 104 | break; 105 | case 11: 106 | currentBit = 0; 107 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 108 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 109 | break; 110 | case 12: 111 | currentBit = 0; 112 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 113 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 114 | break; 115 | case 13: 116 | currentBit = 0; 117 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 118 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 119 | break; 120 | case 14: 121 | currentBit = 0; 122 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 123 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 124 | break; 125 | case 15: 126 | currentBit = 0; 127 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 128 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 129 | break; 130 | case 16: 131 | currentBit = (((secondCount % 10) >> (1 - 1)) & 1); 132 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 133 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 134 | break; 135 | case 17: 136 | currentBit = (((secondCount % 10) >> (2 - 1)) & 1); 137 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 138 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 139 | break; 140 | case 18: 141 | currentBit = (((secondCount % 10) >> (3 - 1)) & 1); 142 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 143 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 144 | break; 145 | case 19: 146 | currentBit = (((secondCount % 10) >> (4 - 1)) & 1); 147 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 148 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 149 | break; 150 | case 20: 151 | currentBit = 0; 152 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 153 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 154 | break; 155 | case 21: 156 | currentBit = 0; 157 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 158 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 159 | break; 160 | case 22: 161 | currentBit = 0; 162 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 163 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 164 | break; 165 | case 23: 166 | currentBit = 0; 167 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 168 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 169 | break; 170 | case 24: 171 | currentBit = (((secondCount /10 % 10) >> (1 - 1)) & 1); 172 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 173 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 174 | break; 175 | case 25: 176 | currentBit = (((secondCount /10 % 10) >> (2 - 1)) & 1); 177 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 178 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 179 | break; 180 | case 26: 181 | currentBit = (((secondCount /10 % 10) >> (3 - 1)) & 1); 182 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 183 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 184 | break; 185 | case 27: 186 | currentBit = 0; 187 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 188 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 189 | break; 190 | case 28: 191 | currentBit = 0; 192 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 193 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 194 | break; 195 | case 29: 196 | currentBit = 0; 197 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 198 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 199 | break; 200 | case 30: 201 | currentBit = 0; 202 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 203 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 204 | break; 205 | case 31: 206 | currentBit = 0; 207 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 208 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 209 | break; 210 | case 32: 211 | currentBit = (((minuteCount % 10) >> (1 - 1)) & 1); 212 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 213 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 214 | break; 215 | case 33: 216 | currentBit = (((minuteCount % 10) >> (2 - 1)) & 1); 217 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 218 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 219 | break; 220 | case 34: 221 | currentBit = (((minuteCount % 10) >> (3 - 1)) & 1); 222 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 223 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 224 | break; 225 | case 35: 226 | currentBit = (((minuteCount % 10) >> (4 - 1)) & 1); 227 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 228 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 229 | break; 230 | case 36: 231 | currentBit = 0; 232 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 233 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 234 | break; 235 | case 37: 236 | currentBit = 0; 237 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 238 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 239 | break; 240 | case 38: 241 | currentBit = 0; 242 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 243 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 244 | break; 245 | case 39: 246 | currentBit = 0; 247 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 248 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 249 | break; 250 | case 40: 251 | currentBit = (((minuteCount / 10 % 10) >> (1 - 1)) & 1); 252 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 253 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 254 | break; 255 | case 41: 256 | currentBit = (((minuteCount / 10 % 10) >> (2 - 1)) & 1); 257 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 258 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 259 | break; 260 | case 42: 261 | currentBit = (((minuteCount / 10 % 10) >> (3 - 1)) & 1); 262 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 263 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 264 | break; 265 | case 43: 266 | currentBit = 0; 267 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 268 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 269 | break; 270 | case 44: 271 | currentBit = 0; 272 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 273 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 274 | break; 275 | case 45: 276 | currentBit = 0; 277 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 278 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 279 | break; 280 | case 46: 281 | currentBit = 0; 282 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 283 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 284 | break; 285 | case 47: 286 | currentBit = 0; 287 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 288 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 289 | break; 290 | case 48: 291 | currentBit = (((hourCount % 10) >> (1 - 1)) & 1); 292 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 293 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 294 | break; 295 | case 49: 296 | currentBit = (((hourCount % 10) >> (2 - 1)) & 1); 297 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 298 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 299 | break; 300 | case 50: 301 | currentBit = (((hourCount % 10) >> (3 - 1)) & 1); 302 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 303 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 304 | break; 305 | case 51: 306 | currentBit = (((hourCount % 10) >> (4 - 1)) & 1); 307 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 308 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 309 | break; 310 | case 52: 311 | currentBit = 0; 312 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 313 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 314 | break; 315 | case 53: 316 | currentBit = 0; 317 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 318 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 319 | break; 320 | case 54: 321 | currentBit = 0; 322 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 323 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 324 | break; 325 | case 55: 326 | currentBit = 0; 327 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 328 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 329 | break; 330 | case 56: 331 | currentBit = (((hourCount / 10 % 10) >> (1 - 1)) & 1); 332 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 333 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 334 | break; 335 | case 57: 336 | currentBit = (((hourCount / 10 % 10) >> (2 - 1)) & 1); 337 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 338 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 339 | break; 340 | case 58: 341 | currentBit = 0; 342 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 343 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 344 | break; 345 | case 59: 346 | currentBit = (polarBit); 347 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 348 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 349 | break; 350 | case 60: 351 | currentBit = 0; 352 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 353 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 354 | break; 355 | case 61: 356 | currentBit = 0; 357 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 358 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 359 | break; 360 | case 62: 361 | currentBit = 0; 362 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 363 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 364 | break; 365 | case 63: 366 | currentBit = 0; 367 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 368 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 369 | break; 370 | case 64: 371 | currentBit = 0; 372 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 373 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 374 | break; 375 | case 65: 376 | currentBit = 0; 377 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 378 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 379 | break; 380 | case 66: 381 | currentBit = 1; 382 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 383 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 384 | break; 385 | case 67: 386 | currentBit = 1; 387 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 388 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 389 | break; 390 | case 68: 391 | currentBit = 1; 392 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 393 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 394 | break; 395 | case 69: 396 | currentBit = 1; 397 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 398 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 399 | break; 400 | case 70: 401 | currentBit = 1; 402 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 403 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 404 | break; 405 | case 71: 406 | currentBit = 1; 407 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 408 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 409 | break; 410 | case 72: 411 | currentBit = 1; 412 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 413 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 414 | break; 415 | case 73: 416 | currentBit = 1; 417 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 418 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 419 | break; 420 | case 74: 421 | currentBit = 1; 422 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 423 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 424 | break; 425 | case 75: 426 | currentBit = 1; 427 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 428 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 429 | break; 430 | case 76: 431 | currentBit = 1; 432 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 433 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 434 | break; 435 | case 77: 436 | currentBit = 1; 437 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 438 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 439 | break; 440 | case 78: 441 | currentBit = 0; 442 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 443 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 444 | break; 445 | case 79: 446 | currentBit = 1; 447 | OCR2B = (lastLevel = (updateCnt?(currentBit?(!lastLevel):(lastLevel)):(!lastLevel))?(1):(0))?(100):(27); 448 | if((updateCnt)&(!currentBit)){polarBit=!polarBit;}; 449 | break; 450 | default: 451 | OCR2B = 63; 452 | } 453 | } 454 | 455 | void timeUpdate(void) 456 | { 457 | 458 | if(bitCount < 79) 459 | { 460 | bitCount ++; 461 | } 462 | else 463 | { 464 | bitCount = 0; 465 | if(frameCount < 24) 466 | { 467 | frameCount ++; 468 | } 469 | else 470 | { 471 | frameCount = 0; 472 | if(secondCount < 59) 473 | { 474 | secondCount ++; 475 | } 476 | else 477 | { 478 | secondCount = 0; 479 | if(minuteCount < 59) 480 | { 481 | minuteCount ++; 482 | } 483 | else 484 | { 485 | minuteCount = 0; 486 | if(hourCount < 23) 487 | { 488 | hourCount ++; 489 | } 490 | else 491 | { 492 | hourCount = 0; 493 | } 494 | } 495 | } 496 | } 497 | } 498 | 499 | } 500 | 501 | ISR(TIMER1_COMPA_vect) 502 | { 503 | 504 | setLevel(); 505 | 506 | if(updateCnt == 0) 507 | { 508 | updateCnt ++; 509 | } 510 | else 511 | { 512 | updateCnt = 0; 513 | timeUpdate(); 514 | } 515 | } 516 | --------------------------------------------------------------------------------