#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,num,num1;
sbit beep=P2^3;
void delay(uint);
void main()
{
temp=0xfe;
while(1)
{
for(num1=0;num1<3;num1++)
{
for(num=0;num<8;num++)
{
P1=temp;
beep=0;
delay(100);
temp=_crol_(temp,1);
P1=0xff;
beep=1;
delay(100);
}
}
for(num1=0;num1<3;num1++)
{
for(num=0;num<8;num++)
{
P1=temp;
beep=0;
delay(100);
temp=_cror_(temp,1);
P1=0xff;
beep=1;
delay(100);
}
}
while(1);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,num,num1;
sbit beep=P2^3;
void delay(uint);
void main()
{
temp=0xfe;
while(1)
{
for(num1=0;num1<3;num1++)
{
for(num=0;num<8;num++)
{
P1=temp;
beep=0;
delay(100);
temp=_crol_(temp,1);
P1=0xff;
beep=1;
delay(100);
}
}
for(num1=0;num1<3;num1++)
{
for(num=0;num<8;num++)
{
P1=temp;
beep=0;
delay(100);
temp=_cror_(temp,1);
P1=0xff;
beep=1;
delay(100);
}
}
while(1);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
矩阵键盘的代码
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
uchar temp,t0,t1,bai,shi,ge,flag,flag1;
uint shu;
void init();
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void main()
{
init();
while(1)
{
if(flag1!=1)
display(7,6,5,bai,shi,ge);
else
display(16,17,18,18,19,20);
}
}
void init()
{
shu=432;
temp=0xfe;
P1=temp;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(flag!=1)
{
if(t0==10)
{
t0=1;
temp=_crol_(temp,1);
P1=temp;
}
}
else
{
if(t0%4==0)
P1=~P1;
if(t0==60)
{
TR0=0;
P1=0xff;
flag1=1;
}
}
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==2)
{
t1=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
flag=1;
t0=0;
P1=0xff;
TR1=0;
}
}
}
void display(uchar aa,uchar bb,uchar cc,uchar ba,uchar sh,uchar g)
{
dula=1;
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[ba];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[sh];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[g];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
uchar temp,t0,t1,bai,shi,ge,flag,flag1;
uint shu;
void init();
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void main()
{
init();
while(1)
{
if(flag1!=1)
display(7,6,5,bai,shi,ge);
else
display(16,17,18,18,19,20);
}
}
void init()
{
shu=432;
temp=0xfe;
P1=temp;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(flag!=1)
{
if(t0==10)
{
t0=1;
temp=_crol_(temp,1);
P1=temp;
}
}
else
{
if(t0%4==0)
P1=~P1;
if(t0==60)
{
TR0=0;
P1=0xff;
flag1=1;
}
}
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==2)
{
t1=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
flag=1;
t0=0;
P1=0xff;
TR1=0;
}
}
}
void display(uchar aa,uchar bb,uchar cc,uchar ba,uchar sh,uchar g)
{
dula=1;
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[ba];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[sh];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[g];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
串口通信代码
#include<reg52.h>
unsigned char flag,a;
void main()
{
TMOD=0x20;//设置定时器1为工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
while(1)
{
/* if(RI==1)
{
RI=0;
P1=SBUF;
}*/
if(flag==1)
{
ES=0;
flag=0;
SBUF='1';//28;
while(!TI);
TI=0;
SBUF='2';//28;
while(!TI);
TI=0;
SBUF='3';//28;
while(!TI);
TI=0;
ES=1;
}
}
}
void ser() interrupt 4
{
RI=0;
// P1=SBUF;
a=SBUF;
flag=1;
}
#include<reg52.h>
unsigned char flag,a;
void main()
{
TMOD=0x20;//设置定时器1为工作方式2
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
while(1)
{
/* if(RI==1)
{
RI=0;
P1=SBUF;
}*/
if(flag==1)
{
ES=0;
flag=0;
SBUF='1';//28;
while(!TI);
TI=0;
SBUF='2';//28;
while(!TI);
TI=0;
SBUF='3';//28;
while(!TI);
TI=0;
ES=1;
}
}
}
void ser() interrupt 4
{
RI=0;
// P1=SBUF;
a=SBUF;
flag=1;
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |