C51单片机程序编写
发布网友
发布时间:2022-04-25 22:23
我来回答
共2个回答
热心网友
时间:2022-06-18 03:14
#include"reg52.h"
sbit Buzz = P1^6;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
bit flagoff = 0;
bit flagon = 1;
bit Startinterval = 0;
bit flag1s = 0;
bit flag2s,flag3s,flag4s,flag5s;
unsigned char index;
unsigned char flagtime = 0;
unsigned char flag2sec = 0;
unsigned char code LedChar[] = {
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E
};
unsigned char T0RH = 0;
unsigned char T0RL = 0;
void BuzzOn();
void ConfigTimer0(unsigned int ms);
void delay(unsigned int ms);
void main()
{
EA = 1;
ADDR0 = 0;
ADDR1 = 0;
ADDR2 = 0;
ADDR3 = 1;
ConfigTimer0(1);
P0 = LedChar[2];
while(1)
{
BuzzOn();
}
}
void BuzzOn()
{
if((flag2sec==0)&&(Startinterval==0))
{
Buzz = ~Buzz;
delay(10);
ENLED = 0;
}
if((flag2sec==1)&&(Startinterval==1))
{
Buzz = 1;
flag2sec = 1;
ENLED = 1;
}
}
void ConfigTimer0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200 / 12;
tmp = (tmp * ms) / 1000;
tmp = 65536 - tmp;
T0RH = (unsigned char)(tmp>>8);
T0RL = (unsigned char)tmp;
TMOD &= 0XF0;
TMOD |= 0X01;
TH0 = T0RH;
TL0 = T0RL;
ET0 = 1;
TR0 = 1;
}
void delay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=10;j>0;j--);
}
void InterruptTimer0() interrupt 1
{
static unsigned int count = 0;
static unsigned int j = 0;
TH0 = T0RH;
TL0 = T0RL;
if(Startinterval==0)
{
count++;
if(count==2000)
{
flag2sec = 1;
count = 0;
Startinterval = 1;
}
}
if(Startinterval==1)
{
j++;
if(flag1s==0)
{
if(j>=1000)
{
j = 0;
index = 1;
flag1s = 1;
flag2s = 0;
flag3s = 1;
flag4s = 1;
flag5s = 1;
Startinterval = 0;
flag2sec = 0;
}
}
if(flag2s==0)
{
if(j>=2000)
{
j = 0;
index = 2;
flag2s = 1;
flag3s = 0;
Startinterval = 0;
flag2sec = 0;
}
}
if(flag3s==0)
{
if(j>=3000)
{
j = 0;
index = 3;
flag3s = 1;
flag4s = 0;
Startinterval = 0;
flag2sec = 0;
}
}
if(flag4s==0)
{
if(j>=4000)
{
j = 0;
index = 4;
flag4s = 1;
flag5s = 0;
Startinterval = 0;
flag2sec = 0;
}
}
if(flag5s==0)
{
if(j>=5000)
{
j = 0;
index = 5;
flag5s = 1;
flag1s = 0;
Startinterval = 0;
flag2sec = 0;
}
}
}
}
热心网友
时间:2022-06-18 03:14
外婆后膜走咯饿了咯吸墨器我走咯哦lzlz