#include #include #include #include #include #include #include #include #include #include #include #include #define BIT_SET(reg,bit) reg = reg | (1 << bit) #define BIT_CLR(reg,bit) reg = reg & ~(1 << bit) #define BIT_TST(reg,bit) reg & (1 << bit) int main(int argc, char *argv[]){ int time_ticks = 1000; /* 1 second */ PBSEL &= 0xbf; /* TO to PB6 */ PBDIR |= 0x40; /* PB6 to output */ TCTL = 0x0028; /* restart mode, disable capture, toggle output, CLK32, disabled */ TPRER = 33; /* make 1ms tick */ TCMP = 20; /* 20ms before count start, to be sure we get there before second compare */ TSTAT = 0; /* clean slate */ TCTL |= 1; /* start it */ while(TSTAT==0){} /* wait for compare */ TSTAT = 0; /* clear flags */ TCMP = time_ticks; while(TSTAT==0){} /* wait for compare */ TSTAT = 0; /* clear flags */ TCTL &= 0xfffe; /* disable counter */ }