大家好,我写了个小程序发现现Pb5口的外部中断不能用,麻烦各位给找找原因
man.c
#include<stm8s003k3.h>
#include"typedefine.h"
#include"stm8s_it.h"
int Dis_temp[]={0x02,0x7a,0x44,0x50,0x38,0x90,0x80,0x5b, 0x00,0x10};
void Px_init(void);
void Delay(int);
void main()
{
EXTI_CR1=0x00;
Px_init();
PB_ODR=0xff;
/*while(1)
{
if(PB5_IN==0)
PC_ODR=0x44;
} */
}
void Px_init()
{
//PA3初始化:输入带上拉中断
PA3_M=0;
PA3_CR1=1;
PA3_CR2=1;
/* PB init */
PB7_M=0; //PB7输入上拉带中断
PB7_CR1=1;
PB7_CR2=1;
PB6_M=0; //PB6输入上拉带中断
PB6_CR1=1;
PB6_CR2=1;
PB5_M=0; //PB5输入上拉带中断
PB5_CR1=1;
PB5_CR2=1;
PB3_M=1; //PB3-PB2为推挽输出
PB3_CR1=1;
PB3_CR2=0;
PB2_M=1;
PB2_CR1=1;
PB2_CR2=0;
PB1_M=1;
PB1_CR1=1;
PB1_CR2=0;
//PB0作为A/D口,设置为
/* PC口设置为输出带上拉, */
PC_ODR=0x00;
PC_DDR=0xff;
PC_CR1=0xff;
PC_CR2=0x00;
/* PD口设置 */
PD3_M=1; //PD3设置为输出带上拉
PD3_CR1=1;
PD3_CR2=1;
PD2_M=1; //PD2设置为输出带上拉
PD2_CR1=1;
PD2_CR2=1;
//PD1默认为Swim模式
PD0_M=1; //PD0设置为输出带上拉
PD0_CR1=1;
PD0_CR2=1;
}
void Delay(int a)
{
long int i,j;
for(i=0;i<a;i++)
for(j=0;j<28000;j++)
{
#asm
nop
nop
nop
nop
#endasm
}
}
interrupt.c
/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
* Copyright (c) 2007 STMicroelectronics
*/
#include<stm8s003k3.h>
#include"typedefine.h"
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
return;
}
@far @interrupt void PB_Exit(void)
{
PC_ODR=0x7a;
}
extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, PB_Exit}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
|
|