免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
./-/ F41x_External_Interrupts.c/-/ Copyright 2007 Silicon Laboratories, Inc./ / Program Description:/ This software shows the necessary configuration to use External Interrupt 0/ (/INT0) or External Interrupt 1 (/INT1) as an interrupt source. The code/ executes the initialization routines and then spins in an infinite while()/ loop. If the button on P1.4 (on the target board) is pressed, then the/ edge-triggered /INT0 input on P0.0 will cause an interrupt and toggle the/ LED./ Pinout:/ P0.0 - /INT0/ P0.1 - /INT1/ P1.4 - SW1 (Switch 1)/ P1.5 - SW2 (Switch 2)/ P2.1 - LED1/ P2.3 - LED2/ How To Test:/ 1) Compile and download code to a F41x target board./ 2) On the target board, connect P1.4 and P1.5 signals on J5 to P0.0/ for /INT0 and P0.1 for /INT1./ 3) Press the switches. Every time a switch is pressed, the P2.1 or P2.3/ LED should toggle./ Target: C8051F41x/ Tool chain: Keil C51 7.50 / Keil EVAL C51/ Command Line: None/ Release 1.0/ -Initial Revision (SM)/ -19 JUN 2007/-/ Include Files/-#include /-/ Global Constants/-#define SYSCLK 24500000 / Clock speed in Hzsbit SW1 = P14; / Push-button switch on boardsbit SW2 = P15; / Push-button switch on boardsbit LED1 = P21; / Green LEDsbit LED2 = P23; / Green LED/-/ Function Prototypes/-void Oscillator_Init (void); / Configure the system clockvoid Port_Init (void); / Configure the Crossbar and GPIOvoid Ext_Interrupt_Init (void); / Configure External Interrupts (/INT0 / and /INT1)/-/ MAIN Routine/-void main (void) PCA0MD &= 0x40; / Disable Watchdog timer Oscillator_Init(); / Initialize the system clock Port_Init (); / Initialize crossbar and GPIO Ext_Interrupt_Init(); / Initialize External Interrupts EA = 1; while(1); / Infinite while loop waiting for / an interrupt from /INT0 or /INT1/-/ Initialization Subroutines/-/-/ Oscillator_Init/-/ Return Value : None/ Parameters : None/ This routine initializes the system clock to use the precision internal/ oscillator as its clock source./-void Oscillator_Init (void) OSCICN = 0x87; / Set internal oscillator to run / at its maximum frequency/-/ Port_Init/-/ Return Value : None/ Parameters : None/ This function configures the crossbar and GPIO ports./ Pinout:/ P0.0 - digital open-drain /INT0/ P0.1 - digital open-drain /INT1/ P1.4 - digital open-drain SW1 (Switch 1)/ P1.5 - digital open-drain SW2 (Switch 2)/ P2.1 - digital push-pull LED1/ P2.3 - digital push-pull LED2/-void Port_Init (void) XBR1 = 0x40; / Enable crossbar and weak pullups P2MDOUT = 0x0A; / LED1 and LED2 are push-pull outputs/-/ Ext_Interrupt_Init/-/ Return Value : None/ Parameters : None/ This function configures and enables /INT0 and /INT1 (External Interrupts)/ as negative edge-triggered./-void Ext_Interrupt_Init (void) TCON = 0x05; / /INT 0 and /INT 1 are edge triggered IT01CF = 0x10; / /INT0 active low; /INT0 on P0.0; / /INT1 active low; /INT1 on P0.1 EX0 = 1; / Enable /INT0 interrupts EX1 = 1; / Enable /INT1 interrupts/-/ Interrupt Service Routines/-/-/ /INT0 ISR/-/ Whenever a negative edge appears on P0.0, LED1 is toggled./ The interrupt pending flag is automatically cleared by vectoring to the ISR/-void INT0_ISR (void) interrupt 0 LED1 = !LED1;/-/ /INT1 ISR/-/ Whenever a negative edge appears
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- NLRP3-IN-87-生命科学试剂-MCE
- (2026年)教师教学工作自查报告范本
- 高中生物动物生态系统能量流动观察实验设计分析训练试题及答案
- 初中英语阅读理解记叙文情节发展分析技巧训练试题及答案
- 2026年玻璃磨边工(中级)职业技能等级认定预测试题
- 建筑红色模板课件
- 2026年湖南长沙市一中博雅学校春季学期期末考试七年级英语试卷卷
- 湖南怀化市2026-2027学年高一上学期11月期中考试地理试卷
- 健身房拥挤踩踏防范手册
- 新能源汽车电池安全充电站建设方案
- 2025年英语专业四级考试真题及答案解析
- 05SFG04防倒塌棚架设计
- 加油站视频监控系统管理指南
- 钢筋模板混凝土施工方案
- 码头装卸作业管理制度
- 山地工程建材无人机吊运施工方案
- 2026年哈姆雷特题库及答案
- 2026年呼吸内科(正-副高)考试历年机考真题集附完整答案详解(名师系列)
- 2026年产科副主任医师职称答辩实务题
- 新生儿职业暴露防控体系构建与实践
- 战场急救六大技术
评论
0/150
提交评论