单片机实验期末考试-使用两个外部中断控制8只LED显示的电路

来源:互联网 发布:mac 删除输入法记忆 编辑:程序博客网 时间:2024/05/01 12:12

在51单片机的某一IO口上接8只LED,在外部中断0输入P3.2(INT0)引脚接一只按钮开关K1,在外部中断1输入P3,.3(INT1)引脚接一只按钮开关K2。要求K1和K2未按下时,8只LED呈流水灯逐一动态显示【方向自定义】,当K1按下时,8只LED奇数偶数位交替闪烁,按下K2时,8只LED以特定时间间隔动态的显示你的学号,多个学号以特定花型。

#include "SST89x5x4.h"#include "Intrins.h"unsigned int arr1[8] = {0x03, 0x01 , 0x04, 0x01, 0x04, 0x00, 0x04, 0x02};unsigned int arr2[8] = {0x03, 0x01 , 0x04, 0x01, 0x04, 0x00, 0x05, 0x08};void delay(){unsigned int x;for(x = 0; x < 0xFFFF; x++);}void int0_isr() interrupt 0{unsigned char j;for(j = 0; j < 4; j++){P1 = 0xAA;delay();P1 = ~P1;delay();}}void int2_isr() interrupt 2{unsigned char j;for(j = 0; j < 8; j++){P1 = arr1[j];delay();delay();delay();}P1 = 0xFF;delay();delay();delay();for(j = 0; j < 8; j++){P1 = arr2[j];delay();delay();delay();}}void LSD(){int i;P1 = 0x01;delay();for(i = 0; i < 7; i++){P1 = _crol_(P1, 1);delay();}}void main(){P1 = 0x00;IT0 = 1;EX0 = 1;IT1 = 1;EX1 = 1;EA = 1;while(1){LSD();}}


0 0
原创粉丝点击