Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //FINAL EXAM A1
- #include <mc9s12c32.h>
- unsigned int dummyread, count = 0;
- unsigned int t1, t2;
- #pragma interrupt_handler tc0_isr
- void tc0_isr()
- {
- dummyread = TC0;
- t1 = TCNT;
- count++;
- }
- #pragma interrupt_handler tc1_isr
- void tc1_isr()
- {
- dummyread = TC1;
- t2 = TCNT;
- count++;
- }
- void main()
- {
- unsigned float t;
- TSCR1=0x90; // enable timer and allow fast flag clear
- TIOS = 0xfc; // set tco and tc1 to input compare
- DDRT = ~0x03; // set pt0 and pt1 as input capture
- TCTL4 = 0x05; // pt0 and pt1 rising edge capture 0000.0101
- dummyread = TC0;
- dummyread = TC1;
- INTER_ON(); // globally interupt enable
- *(void (**)()) 0x0fee = tc0_isr;
- *(void (**)()) 0x0fec = tc1_isr;
- INTR_ON(); // globally enable interupts
- TIE = 0x03; // enable timer interupt tco and tc1
- while(1)
- {
- while(count < 2);
- count = 0;
- if(t2 > t1) t = t2 - t1;
- else t = 0xffff - t1 + t2 + 1;
- t = 1000000 / t;
- // math to convert 1 foot per X cycles to X feet per 1 second
- // 1 foot 10,000,000 cycles 1,000 feet
- // -------------- * ------------------ = ------------
- // 10,000 cycles 1 second 1 second
- printf("speed = %d\n", t);
- }
- }
Add Comment
Please, Sign In to add comment