BST1: TIMER 0 PIC16F877A với trình biên dịch XC8



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

Bài 8: Timer & Counter - PIONEER CLUB

Code Timer 0 nhấp nháy đèn LED đơn

#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000
#include <xc.h>
#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;
            if(Count == 125)
                Count = 0;
                PORTCbits.RC0 ^= 1;                     //toggle the LED

Mô Phỏng

Link download:

Tham khảo tại:


  1. 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!

  2. 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

  3. I was sitting in my kitchen drinking a cup of coffee and cleaning my camera . I was really down and the rain outside didn’t help. I had just turned 78. I had lost my wife last year after a short battle with cancer. I missed her terribly. We had been married for almost 60 years. Little did I know my life was going to change.

    I was thinking about selling our home since the reason for buying such a big home was gone. It was large because my wife had several sewing machines and needed the room. It was a pre-manufactured home with about 2,000 square feet. Due to our snoring, I lived in one end of the home in a small bedroom and she had lived in the other end in the master bedroom. Around the walls were pictures of my wife that I had taken when we were younger. Almost all were her in the nude. She was a great model and very beautiful.

    I was getting up to get another cup of coffee when the doorbell rang. I don’t get visitors and even my daughters didn’t visit very often. I opened the door and there stood a beautiful young woman. She was about 5′ 4″ with long dark hair. She was wearing a halter top and I could see she had, although small, great tits. It took me several seconds to recognize she was my new next door neighbor. She and her husband had just recently moved in.

    She said I’m Jennifer your next door neighbor. I said good morning and asked her if she wanted a cup of coffee. She said that would be great and followed me into the kitchen. I noticed her looking at all the nude photos of my wife. When we sat down I told her those were pictures of my late wife. She asked if I was a photographer and I said not a professional one. I now take general pictures, usually of flowers and sunsets. We talked for a little while about various subject. She finally said the reason she came over was to see if she could use my phone. They were trying get a phone of their own installed. I handed her my cell phone. I went to get us more coffee as I heard her talking. I heard her say that was more than they could afford. As I came back I could see tears in her eyes. As I handed her a tissue she said they were having financial problems. She got up to go and thanked me for the coffee. As I walked her out she stopped to look at my wife’s pictures. Before I could stop my mouth I said I had a lot more in my side of the house. She smiled and said she would like to see them sometime. She walked out and I had a view of the beautiful tight ass. I thought to myself that her husband was very lucky.


Please enter your comment!
Please enter your name here