Timer
Timer được sử dụng cho nhiều chức năng như :
– Định thì để tạo sự kiện
– Đếm sự kiện
-Tạo dạng sóng…
PIC16F877A có 3 Timers:
– Timer 0
– Timer 1
– Timer 2


Code Timer 0 nhấp nháy đèn LED đơn
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000
#include <xc.h>
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
unsigned int Count = 0;
void main(void) {
TRISCbits.TRISC0 = 0; //RC0 pin as output
//config timer0
TMR0 = 55;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS2 = 0;
OPTION_REGbits.PS1 = 1;
OPTION_REGbits.PS0 = 0;
OPTION_REGbits.T0CS = 0;
while (1)
{
if(INTCONbits.TMR0IF == 1)
{
INTCONbits.TMR0IF = 0;
TMR0 = 55;
Count++;
if(Count == 125)
{
Count = 0;
PORTCbits.RC0 ^= 1; //toggle the LED
}
}
}
}
Mô Phỏng

Link download: https://drive.google.com/drive/folders/1pu7wmjVov95bgEkeI3YDmzlRo4fTOz-m?usp=sharing
Tham khảo tại: https://xcvn.blogspot.com/
You have a entirely exciting website. I like the directly poop that you accommodate with every article. Charmion Gardner Jorry
If you are going for best contents like I do, only go to see this web page all the time because it presents feature contents, thanks
Do you mind if I quote a couple of your posts as long as I provide credit
and sources back to your weblog? My website is in the exact same niche as yours and my visitors
would truly benefit from some of the information you present here.
Please let me know if this alright with you.
Appreciate it!
I randomly stopped by your site but you are really successful
Thanks so much for the blog post.Thanks Again. Great.
Hello. This article was extremely fascinating, especially because I was looking for thoughts on this issue last Monday. Jillane Wit Curr
book} in it or something. {I think|I feel|I believe} {that you|that you simply|that you just} {could|can} do with {some|a few} {%|p. Dodi Steve Ignacio
pkfbnafd cialis dosage 40 mg dangerous http://cialisirt.com/ generic cialis tadalafil Gene Tremaine Hoover
I precisely needed to appreciate you once again. I am not sure the things that I might have handled in the absence of the entire pointers provided by you on such a problem. It has been a very frightening difficulty in my circumstances, however , looking at the skilled mode you processed that made me to jump over fulfillment. I am happier for this help and in addition hope that you know what a great job you are always getting into instructing others through the use of your site. I know that you have never encountered all of us. Jenica Theodoric Ambrosane
Everyone loves it when folks come together and share opinions. Great site, stick with it. Eydie Kimble Seaver
I think this is one of the such a lot important info for me.
And i am happy studying your article. However wanna observation on some general issues, The web site taste
is great, the articles is in reality great : D. Excellent activity, cheers
My web-site – best CBD oil for dogs
This article is really a nice one it assists new the web viewers, who are wishing for blogging.
Hi, i think that i saw yyou visited myy website so i came to “return the favor”.I’mtrying to find things tto enhance my site!I suppose its ok to use a few of your ideas!!
https://kratomwwwtea.com/where-to-buy-kratom.html
pure kratom
pure kratom https://kratomwwwtea.com/where-to-buy-kratom.html