PIC 8-bit Timer0

PIC 8-bit Timer0
Çeşme:
- https://microcontrollerslab.com/how-use-pic-microcontroller-timers-interrupt/
- http://www.exploreembedded.com/wiki/PIC18F4520_Timer.
- http://narodstream.ru/pic-urok-5-tajmery/
  1. PIC16F84A
/* * https://microcontrollerslab.com/how-use-pic-microcontroller-timers-interrupt/ * http://www.exploreembedded.com/wiki/PIC18F4520_Timer. * * * * TIMER0 8-bit $$RegValue = 256-((Delay * Fosc)/(Prescalar*4))$$ TIMER1 16-bit $$RegValue = 65536-((Delay * Fosc)/(Prescalar*4))$$ TIMER2 8-bit $$RegValue = 256-((Delay * Fosc)/(Prescalar*4))$$ */ #include <xc.h> #define _XTAL_FREQ 4000000 #pragma config FOSC = XT // Oscillator Selection bits (HS oscillator) #pragma config WDTE = OFF // Watchdog Timer (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable bit (Power-up Timer is enabled) #pragma config CP = OFF // Code Protection bit (Code protection disabled) unsigned int TIM0_count = 0; int tmr0def = 0; void main(void) { // 50ms tmr0def = (int)((255-(((50/1000.0)*(_XTAL_FREQ/4.0))/256.0))+0.5)+2; TRISB = 0x00; PORTB = 0x00; TRISA = 0x00; PORTA = 0x00; // Prescaler Rate : 256 OPTION_REG = 0x07; //0b00000111; // Enable GIE & TMR0 INTCON = 0xA0; //0b10100000; TMR0 = tmr0def; while (1); } void interrupt isr() { TIM0_count++; // count to 1 sec adding 50ms interrupts if (TIM0_count > 19) { TIM0_count = 0; PORTBbits.RB0 = ~PORTBbits.RB0; } T0IF = 0; TMR0 = tmr0def; }