

流水灯

源程序
#include<reg52.h>
#include <intrins.h>
typedef unsigned char uchar;
void delay(uchar t)
{
uchar i=100,j=100,k=100;
while(t--)
{
while(i--)
{
while(j--)
{ while(k--);
}
}
}
}
void main()
{
uchar LED;
LED = 0x7f;
P1 = LED;
while(1)
{
delay(500);
LED = _cror_(LED,1); //点亮下一个LED
P1 = LED;
}
}

数码管的程序:
#include<reg52.h>
#define unchar unsigned char
#define unint unsigned int
unchar code tabol[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unchar tmap,nmb;
void shuma_key();
unchar keyscan();
sbit P30=P3^0;
sbit P31=P3^1;
sbit P32=P3^2;
sbit P33=P3^3;
sbit D1=P1^0;
sbit D2=P1^1;
sbit D3=P1^2;
sbit D4=P1^3;
sbit P20=P2^0;//位选
sbit P21=P2^1;
sbit P22=P2^2;
sbit P37=P3^7;//段选
void delay(unint z)
{
unint x,y;
for(x=z;x>0;x--)
for(y=210;y>0;y--);
}void main()
{
while(1)
{
keyscan();
shuma_key();
}
}
unchar keyscan()
{
tmap=P3;
tmap=tmap&0x0f;
if(tmap!=0X0f)
delay(10);
{
tmap=tmap&0x0f;
if(tmap!=0X0f)
{
switch(tmap)
{
case 0x0e:nmb=1;
break;
case 0x0d:nmb=2;
break;
case 0x0b:nmb=3;
break;
case 0x07:nmb=4;
break;
}
}
while(tmap!=0x0f)
{
tmap=P3;
tmap=tmap&0x0f;
}
}
return nmb;
}
void shuma_key()
{
if(nmb==1)
{
P2=0X0;
P37=1;
P0=tabol[1];
P37=0;
D1=0;
}
if(nmb==2)
{
P2=0X01;
P37=1;
P0=tabol[2];
P37=0;
D2=0;
}
if(nmb==3)
{
P2=0X02;
P37=1;
P0=tabol[3];
P37=0;
D3=0;
}
if(nmb==4)
{
P2=0X03;
P37=1;
P0=tabol[4];
P37=0;
D4=0;
}
}

回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
基于MSPM0L1306的MODBUS-RTU协议通讯实验被打赏50分 | |
每周了解几个硬件知识+485硬件知识分享被打赏10分 | |
【换取手持示波器】树莓派PICOW网页烟花被打赏18分 | |
【换取手持示波器】树莓派PICO逻辑分析仪被打赏16分 | |
【分享评测,赢取加热台】教你五分钟本地部署蒸馏版本的DeepSeekR1-7B被打赏12分 | |
【换取手持示波器】蓝牙音箱更换电池被打赏8分 | |
【换取手持示波器】鼠标更换微动开关被打赏10分 | |
【我要开发板】4.传感器移植被打赏50分 | |
【换取手持数字示波器】RISC-VGCC使用-fno-omit-frame-pointer编译选项实现栈回溯被打赏29分 | |
【分享评测,赢取加热台】+开关电源简述被打赏7分 |