⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pd3keyint.c

📁 ATmega16应用例子
💻 C
字号:
/*********************************************************************
	微 雪 电 子   WaveShare   http://www.waveShare.net            	
		                                                        
目    的:   建立PD3Key中断使用程序
	
目标系统:   基于AVR单片机
		                                                                
应用软件:   ICCAVR
		                                                                
版    本:   Version 1.0                                                          
		                                                                
圆版时间:   2005-06-25
	
开发人员:   SEE

说	 明:   若用于商业用途,请保留此段文字或注明代码来源
	
	深 圳 微 雪 电 子 保 留 所 有 的 版 权     
*********************************************************************/

/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新记录:

----------------------------------------------------------------------
实验内容:
使用查询检测PD3Key,如果有按键按下,则使蜂鸣器鸣叫,否则不鸣叫。
----------------------------------------------------------------------
硬件连接:	
将“Buzzer”引针与“PB3” 引针使用短路帽相连。
----------------------------------------------------------------------
注意事项: 
详见M16SD说明书
		
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/

#include <iom16v.h>
#include "D:\ICC_H\CmmICC.H"

#define DISP_DDR	DDRB
#define DISP_PORT  	PORTB
#define IN_PD3		cbi(DDRD,3)		//PD3
#define SET_PD3		sbi(PORTD,3)
#define GET_PD3		gbi(PIND,3)

/*--------------------------------------------------------------------
函数名称:
函数功能:
注意事项:
提示说明:
输    入:
返    回:
--------------------------------------------------------------------*/
#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
	GICR &= 0b01111111;		   	// disable int1 interrupt
	DISP_PORT++;
	delay50ms(4);
	GICR |= 0b10000000; 		// enable int1 interrupt
}
/*--------------------------------------------------------------------
函数名称:
函数功能:
注意事项:
提示说明:
输    入:
返    回:
--------------------------------------------------------------------*/
void int1_init()
{
 	IN_PD3; 					// set PD3/INT1 as input
	SET_PD3;					// set PD3/INT1 output high level,avoid triggering
	MCUCR |= 0b11110011;		// set PD3/INT1 as low level active
	GICR  |= 0b10000000;		// enable global interrupt
	SEI();	 	  				// enable external interrupt
}
/*--------------------------------------------------------------------
函数名称:
函数功能:
注意事项:
提示说明:
输    入:
返    回:
--------------------------------------------------------------------*/
void main(void)
{
	DISP_DDR  = 0xFF;
	DISP_PORT = 0x00;
	int1_init();
	asm("sleep");				// set mcu as sleep modle
	while(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -