永发信息网

单片机AT89C51、P2口位码控制、用定时器的方法、IF语句输入、实现0~9的加一计数显示、求延时0.5秒的程序

答案:2  悬赏:50  手机版
解决时间 2021-05-18 21:55
  • 提问者网友:相思似海深
  • 2021-05-18 03:49
单片机AT89C51、P2口位码控制、用定时器的方法、IF语句输入、实现0~9的加一计数显示、求延时0.5秒的程序
最佳答案
  • 五星知识达人网友:爱难随人意
  • 2021-05-18 04:50

#include < reg51.h >
#include < intrins.h >


unsigned char code Bmp510[]=
{
0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00,0x82,0xFF,0x80,0x00,0x00,0xC6,0xA1,0x91,
0x89,0x86,0x00,0x42,0x81,0x89,0x89,0x76,0x00,0x10,0x2C,0x22,0xFF,0xA0,0x00,0x4F,
0x89,0x89,0x89,0x71,0x00,0x7E,0x89,0x89,0x8B,0x70,0x00,0x03,0x01,0xF9,0x07,0x01,
0x00,0x76,0x89,0x89,0x89,0x76,0x00,0x0E,0xD1,0x91,0x91,0x7E,0x00,0x80,0xF8,0x27,
0x3C,0xE0,0x80,0x81,0xFF,0x89,0x89,0x76,0x00,0x7E,0x81,0x81,0x81,0x43,0x00,0x81,
0xFF,0x81,0x81,0x7E,0x00,0x81,0xFF,0x89,0x9D,0xC3,0x00,0x81,0xFF,0x89,0x1D,0x03,
0x00,0x3C,0x42,0x81,0x91,0x73,0x10,0x81,0xFF,0x08,0x08,0xFF,0x81,0x81,0x81,0xFF,
0x81,0x81,0x00,0x80,0x01,0x01,0xFF,0x01,0x01,0x81,0xFF,0x89,0x34,0xC3,0x81,0x81,
0xFF,0x81,0x80,0x80,0xC0,0xFF,0x0F,0xF0,0x0F,0xFF,0x00,0x81,0xFF,0x8C,0x31,0xFF,
0x01,0x7E,0x81,0x81,0x81,0x7E,0x00,0x81,0xFF,0x89,0x09,0x06,0x00,0x7E,0xA1,0xA1,
0xC1,0x7E,0x00,0x81,0xFF,0x89,0x19,0xE6,0x80,0xC6,0x89,0x89,0x91,0x63,0x00,0x03,
0x81,0xFF,0x81,0x03,0x00,0x01,0x7F,0x80,0x80,0x7F,0x01,0x01,0x1F,0xE0,0x38,0x07,
0x01,0x07,0xF8,0x0F,0xF8,0x07,0x00,0x81,0xE7,0x18,0xE7,0x81,0x00,0x01,0x87,0xF8,
0x87,0x01,0x00,0x83,0xE1,0x99,0x87,0xC1,
};
unsigned char code col_s[8]={1,2,4,8,16,32,64,128,};
unsigned char count = 0;
unsigned char col = 0;
unsigned char timer1s_flag = 0;
void delayms(unsigned char ms);
void delay(unsigned char t);


unsigned int ttt;

void main()
{
TMOD=0x01 ;
TH0=0xed ;
TL0=0xff ;
EA=1;
ET0=1;
TR0=1 ;

while(1)
{
if(timer1s_flag>=50){
timer1s_flag = 0;
count++;
count %= 10;
}
}
}



// 定时器0中断服务程序.

void timer0() interrupt 1 using 2
{
TH0=0xed ;
TL0=0xff ;
ttt++;
//if(ttt>=1000)
{
ttt = 0;
timer1s_flag++;
P1 = 0;
//P0 = ~col_s[col];
P0 = col;
P1 = Bmp510[count*6+col];
col++;
col %= 6;
}

}


这个程序时实现8*8点阵led显示的 0~9 循环显示。间隔500ms


全部回答
  • 1楼网友:未来江山和你
  • 2021-05-18 05:18

#include "REG51.H"

unsigned char tag = 0; unsigned char count = 0;

void INT_0(void) interrupt 1 { count ++; if( count >= 10 ) { count = 0; tag ++; if( tag >= 10 ) { tag = 0; } } }

void Delay() { int i; for( i = 0; i < 0xff; i ++ ) { } }

main() { unsigned char Table[] = { 0x40, 0x4f, 0x24, 0x30,0x19, 0x12, 0x02, 0x78, 0x00, 0x10 }; TMOD = 0x01; TH0 = 0x3c; TL0 = 0xb0; EA = 1; ET0 = 1; TR0 = 1; while(1) { P2 = Table[tag]; Delay(); } }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯