#include /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */ #include #include void Init_Port() { // OOO Scaner // A P3-10 -> DATA, P3-7 -> GND PTAD = 0x08; PTADD = 0x08; PTAPE = 0x03; PTASE = 0x00; PTADS = 0x00; // B (LED side) P2-7 -> CLOCK PTBD = 0x08; PTBDD = 0x08; PTBPE = 0x03; PTBSE = 0x00; PTBDS = 0x00; } void Init_Clock() { MCGC2 = MCGC2_HGO_MASK | MCGC2_EREFS_MASK | MCGC2_RANGE_MASK | MCGC2_ERCLKEN_MASK; while (MCGSC_OSCINIT == 0) ; MCGC1 = (2<<6) // external reference clock. | (3<<3); // RDIV = 3 : 12MHz/8=1.5 MHz while ((MCGSC_IREFST != 0) || (MCGSC_CLKST != 2)) // FBE PBE (PLL bypassed internal) MCGC3=MCGC3_PLLS_MASK | (8<<0); // multiply by 32 -> 1.5MHz*32=48MHz while((MCGSC_PLLST != 1) || (MCGSC_LOCK != 1)) ; MCGC1 = (0<<6) //PLL or FLL Clock | (3<<3); // 12MHz/8=1.5 MHz while(MCGSC_CLKST !=3) ; } void delay( unsigned int n) { unsigned int j; for(j=0;j<9*n;j++) ; } void main(void) { unsigned int c=0, n[8], i,j,k; Init_Clock(); Init_Port(); for (;;) { for(j=0; j<65536; j++){ srand(j); // ID number n[0]--n[7] for(i=0; i<8; i++) { n[i]=rand()%2; } SOPT1 = 0x13; // WDT’âŽ~.PB1‚ðØ¾¯Ä“ü—Í for (k=0;k<50;k++) { // 079 // 111 111 000 000 001 [01001111] 011 // 111 111 for(i=0; i<6; i++) { PTAD |= 0x08; PTBD |= 0x08; delay(39); } // 0 00 000 001 // 000 [101]x7 101 PTAD &= ~0x08; PTBD &= ~0x08; delay(39); for(i=0; i<7;i++) { PTAD &= ~0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); } PTAD |= 0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); //ID 1011 1001 imagin for(i=0;i<8;i++){ if(n[i]==1) PTAD |= 0x08; else PTAD &= ~0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); } // 011 PTAD &= ~0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); PTAD |= 0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); PTAD |= 0x08; PTBD |= 0x08; delay(13); PTBD &= ~0x08; delay(13); PTBD |= 0x08; delay(13); } // k } //j c++; } }