用PIC16F877A,晶振用4M的做了一个实验如下:
实验通过示波器测得LED的高电平是500MS,低电平是500MS.以下为测试图:
#include
#define uint unsigned int
#define uchar unsigned char
uint intnum=0;
void init_system()
{
TRISC=0x00;
PORTC=0;
INTCON=0xc0;
PIE1=0x01;
TMR1L=(65536-63000)%256; //并非很多书上定的取50000
TMR1H=(65536-63000)/256;
T1CON=0x31;
}
void interrupt time0() //定时
{
TMR1IF=0;
TMR1L=(65536-63000)%256;
TMR1H=(65536-63000)/256;
intnum++;
}
void main()
{
init_system();
while(1)
{
if(intnum==1)
{
intnum=0;
PORTC=!PORTC;
}
}
}