Đếm sản phẩm TIMER 0



/*
 * File:   Sp_Timer0.c
 * Author: PhanHoangThinh
 *
 * Created on Ngày 08 tháng 7 n?m 2017, 18:30
 */


#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
// CONFIG1
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
unsigned char dem=0;
void TMR0_dem();
void main(void) {
    ANSEL=0;
    ANSELH=0;
   
    TRISA4=1;
    lcd_init();
    lcd_gotoxy(3,0);
    printf("Dem san pham");
    TMR0_dem();
//    while(1)
//    {
        dem=TMR0;
        if(TMR0IF==1)
        {
            TMR0IF=0;
            lcd_gotoxy(8,1);
            printf("%02d",dem);
        }
       
       
//    }
}
void TMR0_dem(){
    TMR0=0;
    TMR0IF=0;
    T0CS=1;
    GIE=PEIE=TMR0IE=0;
    PSA=1;
    T0SE=0;
}

Previous
Next Post »