Gast
#3989553
uC: AT89S8253 Sprache: C mit microC Hallo. Ich will bzw. muss den Timer0 als 16 Bit Counter verwenden und Pulse am externen Interrupt 0 zählen. Ich frage mich hier schon allerdings wieso über den INT0 an dem Timer hängt. Eröffnet das spezielle möglichkeiten? Der Timer hat doch seber einen Pin... Ich habe mal ein kleines Programm geschrieben in dem ich den Timer0 initialisiere und starte. Bin mir aber überhaupt nicht sicher ob die Reihenfolge so stimmt oder ob sie schlecht gewählt ist. Was passiert den wenn ich den INT0 noch für etwas anderes verwenden will? Muss ich dann priorisieren? IE0 und IT0 hängen auch irgendwie zusammen, kann mir aber nicht genau erklären wie. Vielleicht hat mir jemand einfache Programmierbeispiele (Basics) wie und für was man den Timer verwendet. Hier die Aufgabe und mein Programm: Assume a clock frequency of 12 MHz unless otherwise specified. 1. Detail all the Special Function Registers within the 8051 microcontroller which are involved with controlling the timers. Detail all the values which must be loaded in the appropriate registers to enable the operation of Timer 0 as a 16 – bit counter, which counts clock pulses that are externally gated to the counter by INT0. void Timer0_ISR() org 0x000B ilevel 0{ EA_bit = 0; // Clear global interrupt enable flag TR0_bit = 0; // Stop Timer0 TH0 = 0x00; // Set Timer0 high byte TL0 = 0x00; // Set Timer0 low byte TR0_bit = 1; // Start Timer0 EA_bit = 1; // Set global interrupt enable flag } void main() { P0 = 0x00; // Initialize PORT0 P1 = 0x00; P2 = 0x00; ET0_bit = 1; // Enable Timer0 interrupt -> IE Register (A8h) EA_bit = 1; // Set global interrupt enable -> IE Register (A8h) EX0_bit = 1; // External interrupt 0 enable //TMOD = 0x09; GATE0_bit = 1; // Set to enable timer/counter 0 only while the INT0# pin is high and the TR0 bit is set. -> TMOD Register (89h) C_T0_bit = 0; // Set for counter operation: timer 0 counts negative transitions on external pin T0. -> TMOD Register (89h) // Clear for timer operation: timer 0 counts the divided-down system clock. M10_bit = 0; // M11_M01 = 01 => Mode 1(16-bit Timer/Counter) -> TMOD Register (89h) M00_bit = 1; // -> TMOD Register (89h) //TCON =0x00; TF0_bit = 0; // Ensure that Timer0 interrupt flag is cleared -> TCON Register (88h) TR0_bit = 0; // Turn off Timer0 -> TCON Register (88h) IE0_bit = 0; // Cleared by hardware when interrupt is processed if edge-triggered (see IT0). // Set by hardware when external interrupt is detectedon INT0# pin. IT0_bit = 0; // Clear to select low level active (level triggered) for external interrupt 0 (INT0#). // Set to select falling edge active (edge triggered) for external interrupt 0. TH0 = 0x00; // Set Timer0 high byte TL0 = 0x00; // Set Timer0 low byte TR0_bit = 1; // Run Timer0 while(1){ ; } }