写了一个 51单片机外部中断程序
来源:互联网 发布:单片机led灯不亮 编辑:程序博客网 时间:2024/05/16 19:22
/*以下是能在keilC 中变异的源码,直接粘贴过去就行,外部中断0(INT0)和外部中断1都有(INT1)*/
/*程序很简单,但是对新手来说还是很实用的*/
/*******************************************************************/
/* */
/* 单片机开发系统演示程序 - INT0 INT1 中断计数 */
/* */
/* 6位数码管显示 */
/* */
/* 作者:曾露337 店铺:http://shop58430712.taobao.com */
/* */
/*【声明】此程序仅用于学习与参考,引用请注明版权和作者信息! */
/* */
/*******************************************************************/
#include < reg51.h >
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code LEDData[ ] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,
0x82,0xF8,0x80,0x90,0xff};
unsigned char data display[8] = {0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x00};
unsigned char code scan_bit[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char count0,count1,temp=0 ;
/********************************************************
* *
* 延时函数 *
* *
********************************************************/
void delay(uint ms)
// 延时子程序
{
uchar k;
while(ms--)
{
for(k = 0; k < 100; k++);
}
}
/********************************************************
* *
* 数据处理与显示函数 *
* *
********************************************************/
void disp_count()
{
char n;
temp=count0;
display[2]=temp/100; //数据处理
temp=temp%100;
display[1]=temp/10;
display[0]=temp%10;
if(display[2]==0) //高位为0,不显示
{
display[2]=0x0a;
if(display[1]==0)
display[1]=0x0a;
}
temp=count1;
display[7]=temp/100; //数据处理
temp=temp%100;
display[6]=temp/10;
display[5]=temp%10;
if(display[7]==0) //高位为0,不显示
{
display[7]=0x0a;
if(display[6]==0)
display[6]=0x0a;
}
for(n=0;n<8;n++)
{
P0 =LEDData[display[n]] ; //显示段码
P2 =scan_bit[n]; //输出位码
delay(1);
P2 = 0xff; //关闭显示
}
}
/********************************************************
* *
* 主程序 *
* *
********************************************************/
void main(void)
{
P0=0xff;
P1=0xff;
P2=0xff;
IT0=0; //低电平触发
// IT0=1; //下降沿触发
IT1=0; //低电平触发
// IT1=1; //下降沿触发
PX0=1;
EA=1;
EX1=1;
EX0=1;
while(1)
{
disp_count();
}
}
/********************************************************
* *
* INT0中断函数 *
* *
********************************************************/
void counter0(void) interrupt 0
{
uchar x;
EX0=0;
count0++;
for(x=0;x<10;x++)
{
disp_count();
}
EX0=1;
}
/********************************************************
* *
* INT1中断函数 *
* *
********************************************************/
void counter1(void) interrupt 2
{
uchar x;
EX1=0;
count1++;
for(x=0;x<10;x++)
{
disp_count();
}
EX1=1;
}
/********************************************************/
- 写了一个 51单片机外部中断程序
- 51单片机(AT89C52)外部中断程序
- 51单片机外部中断
- 测透51汇编 51单片机外部中断模块程序
- 51单片机的外部中断
- 51单片机STC89C52 外部中断
- 51单片机外部中断示例
- 51单片机 外部中断实验
- 51 单片机扩充外部中断
- AVR单片机(ATMEGA16)外部中断程序
- PIC单片机(PIC16F877A)外部中断程序
- 【51单片机】中断程序
- 51单片机外部中断的C51编程
- 51单片机外部中断小练习
- 51单片机外部中断编程实例2
- 51单片机第五弹---外部中断
- [51单片机系列]1.外部中断
- MSP430单片机外部中断
- spring BeanWrapperImpl方便的嵌套属性(list)操作
- 【Shiro】Apache Shiro架构之权限认证(Authorization)
- iOS8 的毛玻璃效果(UIVisualEffectView)
- hdu 1049 Climbing Worm
- java spring定时器(注解)
- 写了一个 51单片机外部中断程序
- 32.Python的单元测试工具——unittest(初级)
- myeclipse 连接mysql 提示 unable to create connection.check your url
- CodeForces 478D-Red-Green Towers
- <C++略识> 之关键字const
- js变量以及其作用域详解
- PHP 原生分页
- Linux内核驱动之GPIO子系统(一)GPIO的使用
- 数据库索引