Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Interrupt()
- {
- // Timer0 Interrupt - Freq = 38461.54 Hz - Period = 0.000026 seconds
- if (INTCON.TMR0IF ==1) // timer 0 interrupt flag
- {
- GPIO.GP0 = ~GPIO.GP0; // Toggle PORTB bit0 LED
- INTCON.TMR0IF = 0; // clear the flag
- INTCON.TMR0IE = 1; // reenable the interrupt
- TMR0 = 243; // reset the timer preset count
- }
- }
- void main()
- {
- CMCON = 0x07; // GP2:0 como IO
- TRISIO = 0x00; // PORT is all output...to show the interrupts
- GPIO = 0; // start with all outputs low
- //Timer0 Registers Prescaler= 1 - TMR0 Preset = 230 - Freq = 38461.54 Hz - Period = 0.000026 seconds
- OPTION_REG.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
- OPTION_REG.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
- OPTION_REG.PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
- OPTION_REG.PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
- OPTION_REG.PS1 = 0;
- OPTION_REG.PS0 = 0;
- TMR0 = 243; // preset for timer register
- // Interrupt Registers
- INTCON = 0; // clear the interrpt control register
- INTCON.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
- INTCON.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
- INTCON.GIE = 1; // bit7 global interrupt enable
- while(1) //endless loop
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement