當前位置:歷史故事大全網 - 歷史天氣 - 求51單片機控制2個數碼管的程序

求51單片機控制2個數碼管的程序

兩只數碼管段碼分別由P0,P2輸出控制,P0是十位,P2是個位。P3.2,P3.4分別接兩只按鍵,P32.清0,P3.4計數。

以上程序來自《單片機C語言程序設計實訓100例——基於8051+Proteus仿真》

#include <reg52.h>

#define uchar unsigned char

#define uint unsigned int

uchar DSY_CODE[]=

{

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

};

uchar Count = 0;

void main()

{

P0 = 0x00;

P2 = 0x00;

TMOD = 0x06;

TH0=255;

TL0=255;

ET0=1;

EX0=1;

EA =1;

IP =0x02;

IT0=1;

TR0=1;

while(1)

{

P0 = DSY_CODE[Count/10];

P2 = DSY_CODE[Count%10];

}

}

void Clear_Counter() interrupt 0

{

Count = 0;

}

void Key_Counter() interrupt 1

{

Count = (Count + 1) %100;

}

  • 上一篇:簡述跨國公司的作用?
  • 下一篇:少林拳法怎麽練
  • copyright 2024歷史故事大全網