Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

microprocessors - Why I only get 6 pulses from TImer0 Interrupts?

I only get, from the interrupts, 6 pulses in RA2 (LED). the signal should be a pulsetrain (one pulse every seccond). Here is the code and a pic from the simulation pulses comming from RA2 (LED) hope you can help me with this best regards, Richar

#include <pic.h>
#include <htc.h>

void Initialization ();

__CONFIG(FOSC_LP & WDTE_ON & PWRTE_OFF & CP_OFF);
#define _XTAL_FREQ 32768              

#define Drive1 RA0
#define Drive0 RA1
#define Machine RB4
#define LED RA2
#define Stall_In  RB0

int S = 0;                      

void main() 
{
    Initialization ();
    while (1)
    {
        //do something after interrupts     
    }
}
void Initialization(void)
{
    TRISA = 0b00000000;                 
    TRISB = 0b00000001;             
    OPTION_REG = 0b00000101;    
    INTCON = 0b10100000;            
    TMR0 = 128;                         
    LED = 0;
    Stall_In = 0;
    Drive0 = 0;
    Drive1 = 0;
    Machine  = 0;
}

void interrupt tc_int(void)
{    
    if (T0IE && T0IF) 
    {        
        T0IE = 0;
        T0IF=0;
        TMR0 = 128;
        S = S+1;
        LED = 1;
        LED = 0;
        T0IE = 1;           
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...