#include <xc.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.
const unsigned char leddoan[] =
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82,0xF8, 0x80, 0x90};
unsigned int dem=44;
unsigned int chuc,donvi;
//void tinhtoan(unsigned count);
void tinhtoan (unsigned int dem)
{
for(int j=0;j<25;j++)
{
chuc = dem/10;
donvi = dem%10;
PORTBbits.RB0 = 1;
PORTBbits.RB1 = 0;
PORTD = leddoan[chuc];
__delay_ms(50);
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 1;
PORTD = leddoan[donvi];
__delay_ms(50);
}
// TRISBbits.Ty_ms(50);RISB1=0;
}
void main(void) {
ANSEL=0;
ANSELH=0;
TRISBbits.TRISB0=0;
TRISBbits.TRISB1=0;
TRISD=0x00;
PORTD=0xFF;
__delay_ms(100);
while(1)
{
tinhtoan(dem);
dem--;
if(dem <=99)
{
dem = 81;
}
}
}