#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3B31);
void init();
uint Timer0Num,Timer1Num,Timer2Num;//
void timer0();
void timer1();
void timer2();
void main()
{
init();
while(1)
{
if(Timer0Num>=20)
{
Timer0Num = 0;
RD0 = ~RD0;
}
if(Timer1Num >= 4)
{
Timer1Num = 0;
RD2 = !RD2;
}
if(Timer2Num >= 50)
{
Timer2Num = 0;
RD4 = !RD4;
}
}
}
void init(void)
{
TRISD = 0;
PORTD = 0;
OPTION = 0x07;//256分频
TMR0 = 56;
PIE1 |= 0x01 | 0x02;
TMR1H = (65536-50000)/256;
TMR1L = (65536-50000)%256;
T1CON = 0x21;//4分频
TMR2 = 0;
PR2 = 100;
T2CON = 0x1D;
INTCON = 0xE0;
}
void interrupt Ints()
{
if(T0IE&&T0IF) timer0();
if(TMR1IE&&TMR1IF) timer1();
if(TMR2IE&&TMR2IF) timer2();
}
void timer0()
{
T0IF = 0;
TMR0 = 56;
Timer0Num++;
}
void timer1()
{
TMR1IF = 0;
TMR1H = (65536-50000)/256;
TMR1L = (65536-50000)%256;
Timer1Num++;
}
void timer2()
{
TMR2IF = 0;
TMR2 = 0;
PR2 = 200;
Timer2Num++;
}