/////////////////////////////////////
// Generated Ini
tialization File //
/////////////////////////////////////
#include "C8051F040.h"
sbit LED2=P4^0;
unsigned char count,sfrt;
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Port_IO_Init()
{
// P0.0 - Unassigned, Open-Drain, Digital
// P0.1 - Unassigned, Open-Drain, Digital
// P0.2 - Unassigned, Open-Drain, Digital
// P0.3 - Unassigned, Open-Drain, Digital
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Open-Drain, Digital
// P3.5 - Unassigned, Open-Drain, Digital
// P3.6 - Unassigned, Open-Drain, Digital
// P3.7 - Unassigned, Open-Drain, Digital
SFRPAGE = CONFIG_PAGE;
P4MDOUT = 0x01;
P6MDOUT = 0x18;
XBR2 = 0x40;
}
void Timer_Init()
{
sfrt = SFRPAGE;
SFRPAGE = TIMER01_PAGE;
CKCON = 0X01;
TMOD = 0x10; //T1·½Ê½1
TH1 = 0x3c;
TL1 = 0xb0; //³õÖµ ¶¨Ê±50ms ¼ÆË㹫ʽ 2µÄ16´Î·½-50ºÁÃë/1us = 65536-50000000/1000 = 65536-50000=15536=0x3CB0;
ET1 = 1; //ÔÊÐíTIMER1¶¨Ê±Æ÷ÖжÏ
EA = 1; //×ÜÖж˿ª¿ªÆô
TR1 = 1; //Æô¶¯¶¨Ê±Æ÷
SFRPAGE = sfrt;
}
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
OSCICN = 0x00;
}
void delay()
{
unsigned int tn = 8000;
while ( --tn != 0 );
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Port_IO_Init();
}
void main()
{
Init_Device();
delay();
Timer_Init();
Oscillator_Init();
while(1);
/* {
P4 = 0x00;
P6 = 0x00;
delay();delay();delay();delay();delay();
LED2 = 1;
P6 = 0xff;
P4 = 0xff;
delay();delay();delay();delay();delay();
};*/
}
void Timer1_ISR() interrupt 3
{
SFRPAGE = TIMER01_PAGE;
ET1 = 0; //ÔÊÐíTIMER1¶¨Ê±Æ÷ÖжÏ
TF1 = 0;
TH1 = 0x3c;
TL1 = 0xb0; //³õÖµ ¶¨Ê±50ms ¼ÆË㹫ʽ 2µÄ16´Î·½-50ºÁÃë/1us = 65536-50000000/1000 = 65536-50000=15536=0x3CB0;
count++;
if(count >= 20)
{
count = 0;
P6 = ~P6;
}
ET1 = 1;
}
上述是我C8051F040
单片机定时器50MS程序 现在问题的定时器并没有生产50MS的定时,简单来说就是定时器并没有工作, 求个位大神给予帮助 希望能指出相关问题 并给出作答
没进入中断的话 就是初始化问题了 你看看是哪里配置错了
一周热门 更多>