-
辉芒FT60E121-SOP8 中断问题 sos
PA5触发中断时理应只有[color=#80080]BLUE_PIN ([/color][color=#80080]PA0) [/color]输出高电平,但实际情况也[color=#800080]YELLOW_PIN (PA2)[/color]有输出,有没有大佬懂,帮帮小弟 #include "SYSCFG.h" [color=#800080]//***********************宏定义****************************[/color] #define unchar unsigned char unchar FCount; unchar ReadAPin; [color=#800080]#define BLUE_PIN PA0 [/color] #define WHITE_PIN PA1[color=#800080] [/color] [color=#800080]#define YELLOW_PIN PA2[/color][color=#800080] [/color] //定义输出引脚 [color=#800080]#define turn_signal PA5 [/color] #define width_signal PA4 volatile unsigned char is_running = 0; volatile float pwm_counter = 0; #define PWM_PERIOD 10 // PWM周期,根据定时器频率调整 volatile float pwm_blue_duty = 0;//占空比 volatile float pwm_white_duty = 0;//占空比 volatile unsigned int cycle_count=0; volatile unsigned int step=10; int step1=0; [color=#808080]/*-------------------------------------------------[/color] [color=#808080]* 函数名:interrupt ISR[/color] [color=#808080]* 功能: 中断处理[/color] [color=#808080]* 输入: 无[/color] [color=#808080]* 输出: 无[/color] [color=#808080] --------------------------------------------------*/[/color] void interrupt ISR(void) { [color=#800080] if (PA5) { [/color] [color=#800080] YELLOW_PIN = 1; [/color] [color=#800080] BLUE_PIN = 0; [/color] [color=#800080] WHITE_PIN = 0;[/color] [color=#800080] }[/color] if (T0IE && T0IF) {T0IF = 0;} if(TMR2IE && TMR2IF) { TMR2IF = 0; if (pwm_counter >= PWM_PERIOD) pwm_counter = 0; else{pwm_counter+=0.1;} if (pwm_blue_duty>PWM_PERIOD){pwm_blue_duty=0;} } } [color=#808080]/*-------------------------------------------------[/color] [color=#808080]* 函数名:POWER_INITIAL[/color] [color=#808080]* 功能: 上电系统初始化[/color] [color=#808080]* 输入: 无[/color] [color=#808080]* 输出: 无[/color] [color=#808080] --------------------------------------------------*/ [/color] void POWER_INITIAL (void) { OSCCON = 0B01110001; //IRCF=111=16MHz/2=8MHz,0.125us INTCON = 0; //暂禁止所有中断 PORTA = 0B00000000; TRISA = 0B00110000; //PA输入输出 0-输出 1-输入 //PA4-OUT PORTC = 0B00000000; TRISC = 0B00000000; //PC输入输出 0-输出 1-输入 WPUA = 0B00110000; //PA端口上拉控制 1-开上拉 0-关上拉 //开PA6上拉 OPTION = 0B00000000; //Bit3=0 TMR0 MODE,PS=000=TMR0 Rate 1:2 PSRCA = 0B11111111; //源电流设置最大 PSRCC = 0B11111111; PSINKA = 0B11111111; //灌电流设置最大 PSINKC = 0B11111111; MSCON = 0B00110000; //Bit5: PSRCAH4和PSRCA[4]共同决定源电流。00:4mA; 11: 33mA; 01、10:8mA //Bit4: PSRCAH3和PSRCA[3]共同决定源电流。00:4mA; 11: 33mA; 01、10:8mA //Bit3: UCFG1<1:0>为01时此位有意义。0:禁止LVR;1:打开LVR //Bit2: 快时钟测量慢周期的平均模式。0:关闭平均模式;1:打开平均模式 //Bit1: 0:关闭快时钟测量慢周期;1:打开快时钟测量慢周期 //Bit0: 当T2时钟不是选择指令时钟的时候 // 0:睡眠时停止工作:1: 睡眠时保持工作。 } [color=#808080]/*----------------------------------------------------[/color] [color=#808080]* 函数名称:TIMER0_INITIAL[/color] [color=#808080]* 功能:初始化设置定时器[/color] [color=#808080]* 相关寄存器:T0CS T0SE PSA [/color] [color=#808080]* 设置TMR0定时时长=(1/系统时钟频率)*指令周期*预分频值*255[/color] [color=#808080]* =(1/16000000)*2*256*255=8.192ms[/color] [color=#808080] ----------------------------------------------------*/[/color] void TIMER0_INITIAL (void) { OPTION = 0B00000000; //Bit5 T0CS Timer0时钟源选择 // 1-外部引脚电平变化T0CKI 0-内部时钟(FOSC/2) //Bit4 T0CKI引脚触发方式 1-下降沿 0-上升沿 //Bit3 PSA 预分频器分配位 0-Timer0 1-WDT //Bit[2:0] PS 8个预分频比 111 - 1:256 T0IF = 0; //清空T0软件中断 } void TIMER2_INITIAL (void) { T2CON0 = 0B00000001; //T2预分频1:4,后分频1:1 //Bit[6:3]: 定时器2输出后分频比 0000-1:1 //Bit2: 定时器2输出是能位 0-关闭 1-使能 //Bit[1:0]: 定时器2预分频比 01-1:4 T2CON1 = 0B00000000; //T2时钟来自系统时钟,PWM1连续模式 //Bit4: PWM单脉冲模式选择 0-连续 1-单脉冲 //Bit3: PWM蜂鸣器模式选择 0-PWM模式 1:蜂鸣器模式 //Bit[2:0]:Timer2时钟源选择 000-指令时钟 TMR2H = 0; //TMR2赋值 TMR2L = 0; PR2H = 0; //PR赋值 PR2L = 200; TMR2IF = 0; //清TMER2中断标志 TMR2IE = 1; //使能TMER2的中断(配置成timer定时器时不注释) TMR2ON = 1; //使能TMER2启动 PEIE = 1; //使能外设中断 GIE = 1; //使能全局中断 } [color=#800080]void B_UP (void){[/color] [color=#800080] switch(step1)[/color] [color=#800080] { case 0:{pwm_blue_duty+=0.001;step1=1;}[/color] [color=#800080] break;[/color] [color=#800080] case 1:{if (pwm_counter < pwm_blue_duty) BLUE_PIN = 1; [/color] [color=#800080] else BLUE_PIN = 0; step1=0;}[/color] [color=#800080] break;[/color] [color=#800080] pwm_counter=0;[/color] [color=#800080] }[/color] [color=#800080]}[/color] [color=#808080]/*-------------------------------------------------[/color] [color=#808080]* 函数名: main [/color] [color=#808080]* 功能: 主函数[/color] [color=#808080]* 输入: 无[/color] [color=#808080]* 输出: 无[/color] [color=#808080] --------------------------------------------------*/[/color] void main(void) { POWER_INITIAL(); //系统初始化 TIMER0_INITIAL(); TIMER2_INITIAL(); GIE = 1; //开中断 T0IE = 1; //开定时器/计数器0中断 TMR2IE = 1; while(1) { [color=#800080] B_UP ();[/color] } }
2156浏览量 0回复量 关注量