单片机/MCU论坛
直播中

徐天文

未满1年用户 6经验值
擅长:嵌入式技术
私信 关注
[讨论]

使用Keil建立完整的工程,并使用外部中断0触发数码管显示903

#include <reg51.h>

unsigned char code SEG_CODE[] = {

0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,

0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71

};

sbit WEI1 = P2^0;

sbit WEI2 = P2^1;

sbit WEI3 = P2^2;

void EX0_Init() {

IT0 = 1;  

EX0 = 1;  

EA = 1;

}

void Delay(unsigned int x) {

unsigned int i, j;

for (i = 0; i < x; i++)

    for (j = 0; j < 110; j++);

}

void Display(unsigned char num1, unsigned char num2, unsigned char num3) {

WEI1 = 0;

P0 = SEG_CODE[num1];

Delay(1000);

WEI1 = 1;



WEI2 = 0;

P0 = SEG_CODE[num2];

Delay(1000);

WEI2 = 1;



WEI3 = 0;

P0 = SEG_CODE[num3];

Delay(1000);

WEI3 = 1;

}

void EX0_ISR() interrupt 1 {

Display(9, 0, 3);

}

void main() {

EX0_Init();



while (1) {

}

}

更多回帖

发帖
×
20
完善资料,
赚取积分