前言:
当前大家对“c语言interrupt关键字”大约比较讲究,朋友们都想要剖析一些“c语言interrupt关键字”的相关内容。那么小编同时在网络上汇集了一些对于“c语言interrupt关键字””的相关文章,希望兄弟们能喜欢,看官们快快来了解一下吧!/main.c#include <reg52.h>#include "display.h"void T0_Init(void);void EX1_Init(void);void display_Service();unsigned int numCnt =0;void main(){ T0_Init(); EX1_Init(); EA = 1; while(1) { display_Service(); }}//外部中断1初始化void EX1_Init(void){ //设置触发方式 外部中断0 IT1=1;//设置下降沿触发TCON EX1=1;//IE //EA =1;}void EX1_ISR(void) interrupt 2{ EX1 = 0; numCnt++; if(numCnt>9999) numCnt = 0; EX1 = 1; }void display_Service(){ ledbuf[0] = numCnt/1000; ledbuf[1] = numCnt/100%10; ledbuf[2] = numCnt/10%10; ledbuf[3] = numCnt%10;}void T0_Init(void) //1毫秒@12.000MHz{ TMOD &= 0xF0; //设置定时器模式 GATE C/T M1 M0 TMOD |= 0x01; //设置定时器模式 TL0 = 0x18; //设置定时初值65536-50000)%256 TH0 = 0xFC; //设置定时初值65536-50000)/256 TF0 = 0; //清除TF0标志 ET0 = 1;//定时器0的中断开关 //EA = 1;//中断总开关 TR0 = 1; //定时器0开始计时}/*****************************************1.中断服务函数一定是一个没有返回值的函数2.中断服务函数一定是没有参数的函数3.中断服务函数名后跟关键字 interrupt4.interrupt n 0-4 5个中断源 8*n+0003H0003H INT0 000BH T0 0013H INT1 001BH T1 0023H ES5.中断服务函数不能被主程序或者其它程序所调用6. n后面跟using m (0-3)工作寄存器组*****************************************/void T0_ISR(void) interrupt 1{ TR0 = 0; Display(); TL0 = 0x18; //设置定时初值65536-50000)%256 TH0 = 0xFC; //设置定时初值65536-50000)/256 TR0 = 1;}
//display.c#include <reg52.h>#include "intrins.h"#include "display.h"unsigned char code leddata[]={0xDD,0x05,0x9B,0x97,0x47,0xD6,0xDE,0x85,0xDF,0xC7,0x02,0x00,0xCB};//数码管断码表从0,1,2,3,4,5,6,7,8,9,-,无,Punsigned char ledbuf[]={8,8,9,9};//数据显示缓冲区unsigned char code PLACE_CODE[]={0xFB,0xDF,0xBF,0x7F};//位选信号void Display(){ static unsigned char i=0; //1.送段码 //2.送位码 //3.延时1ms小于10ms //4.消隐 switch(i) { case 0: GPI0_DIG = 0x00; GPI0_DIG = leddata[ledbuf[0]]; GPIO_PLACE = PLACE_CODE[0]; i++; break; case 1: GPI0_DIG = 0x00; GPI0_DIG = leddata[ledbuf[1]]; GPIO_PLACE = PLACE_CODE[1]; i++; break; case 2: GPI0_DIG = 0x00; GPI0_DIG = leddata[ledbuf[2]]; GPIO_PLACE = PLACE_CODE[2]; i++; break; case 3: GPI0_DIG = 0x00; GPI0_DIG = leddata[ledbuf[3]]; GPIO_PLACE = PLACE_CODE[3]; i=0; break; default:break; }}
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #c语言interrupt关键字