请问各种大神关于C8051F040定时器相关问题

2019-07-15 11:42发布

/////////////////////////////////////
//  Generated Initialization 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的定时,简单来说就是定时器并没有工作,  求个位大神给予帮助   希望能指出相关问题 并给出作答

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
hobbye501
1楼-- · 2019-07-15 15:14
 精彩回答 2  元偷偷看……
a568184418
2楼-- · 2019-07-15 19:42
hobbye501 发表于 2017-3-13 11:29
问题可能出在两个地方,1.定时初始化 2,定时中断  你可以把断点放在中断里,看看进没进来
void Timer1_ISR() interrupt 3
{

并没有进入定时器中断  能否找出这段程序的问题?  定时器启动我已经看了很多遍   不知道是哪出的问题
hobbye501
3楼-- · 2019-07-16 01:22
a568184418 发表于 2017-3-13 15:38
并没有进入定时器中断  能否找出这段程序的问题?  定时器启动我已经看了很多遍   不知道是哪出的问题

没进入中断的话 就是初始化问题了   你看看是哪里配置错了

一周热门 更多>