keil c语言中断怎么写,如何利用keil C实现单片机中断功能

直接访问寄存器和端口

定义

sfr P0 0x80

sfr P1 0x81

sfr ADCON; 0xDE

sbit EA  0x9F

操作

ADCON = 0x08;

P1 = 0xFF;

io_status = P0 ;

EA = 1;

在使用了interrupt 1 关键字之后,会自动生成中断向量

在 ISR中不能 与其他 “后台循环代码”(the background loop code) 共享局部变量,因为连接器会复用 在RAM中这些变量的位置 ,所以它们会有不同的意义,这取决于当前使用的不同的函数复用变量对RAM有限的51来讲很重要。所以,这些函数希望按照一定的顺序执行 而不被中断。

void timer0_int(void) interrupt 1 using 2

{

unsigned char temp1;

unsigned char temp2;

executable C statements;

}

“interrupt”声明表向量生成在(8*n+3),这里,n就是interrupt参数后的那个数字这里,在08H的代码区域 生成LJMP timer0_int这样一条指令。

“using” tells the compiler to switch register banks on entry to an interrupt routine. This “context” switch is the fastest way of

providing a fresh registerbank for an interrupt routine’s local data and is to be preferred to stacking registers for very time-criticalroutines. Note that interrupts of the same priority can share a register bank, since there is no risk that they will interrupt each other.

“using” 告诉编译器 在进入51danpi中断处理器 去切换寄存器的bank。这个”contet”切换是为中断处理程序的局部变量提供一个新鲜的寄存器bank最快的方式。对时序要求严格的程序,是首选的stack寄存器(保存寄存器到stack)方式。

注意:同样优先级别的中断可以共享寄存器bank,因为他们每次将中断没有危险。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值