51单片机制作霓虹灯的程序+电路图
时间:11-30
来源:互联网
点击:
霓虹灯的电路图:
霓虹灯的51单片机程序:
#include
#define uchar unsigned char
#define uint unsigned int
sbit RED_LED = P1^0; //端口定义.
sbit GREEN_LED = P1^1;
sbit YELLOW_LED = P1^2;
uint flicker,i,n;
void int0()
{
TMOD=0x01;
TH0=0x3C;
TL0=0xAF;
TR0=1; //启动定时器。
ET0=1; //开定时器中断.
EA=1; //开总中断
}
void main() //主函数。
{
n=0;
i=0;
GREEN_LED=1;
YELLOW_LED=1;
flicker=0;
int0();
while(1)
{
if(0<=n&&n<20)
{
YELLOW_LED=1;
GREEN_LED=1;
RED_LED=flicker;
}
if(20<=n&&n<40)
{
RED_LED=1;
YELLOW_LED=1;
GREEN_LED=flicker;
}
if(40<=n&&n<60)
{
RED_LED=1;
GREEN_LED=1;
YELLOW_LED=flicker;
if(n==59)
n=0;
}
}
}
void Time0() interrupt 1
{
TR0=0;
i++;
if(i==10)
{
flicker=~flicker;
i=0;
n++;
}
TH0=0x3C;
TL0=0xAF;
TR0=1;
}
下面是另一个用51单片机的霓虹灯2:
如果网页复制的代码无法编译成功可以从:http://www.51hei.com/f/nhddpj_c.rar 这个链接下载
#include
#define uchar unsigned char
#define uint unsigned int
uchar ss[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x00,0xff,0x00,0xff,0x00,0x01,0x03,0x06,
0x0c,0x18,0x30,0x60,0xc0,0x80,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0x01,0x03,0x07,
0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,0x00,
0xff,0x00,0xff,0x00,0x01,0x03,0x07,0x0f,
0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,0xff,
0x00,0xff,0x00,0xff,0x00,0x78,0xf0,0xff,
0x00,0xff,0x00,0x80,0x40,0x20,0x10,0x08,
0x04,0x02,0x01,0xff,0x00,0xff,0x00,0xff,
0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,
0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
/*数组中为霓虹灯闪烁花样,单流水,双流水,三流水,四流水和倒流*/
uint m,n,i;
void delay(m)
{
while(m--)
for(i=0;i<120;i++);
}
void main() //主函数。
{
while(1)
{
P1=ss[n];
P3=ss[n];
delay(400);
P1=0x00;
n++;
if(n==96)
n=0;
}
}
霓虹灯的51单片机程序:
#include
#define uchar unsigned char
#define uint unsigned int
sbit RED_LED = P1^0; //端口定义.
sbit GREEN_LED = P1^1;
sbit YELLOW_LED = P1^2;
uint flicker,i,n;
void int0()
{
TMOD=0x01;
TH0=0x3C;
TL0=0xAF;
TR0=1; //启动定时器。
ET0=1; //开定时器中断.
EA=1; //开总中断
}
void main() //主函数。
{
n=0;
i=0;
GREEN_LED=1;
YELLOW_LED=1;
flicker=0;
int0();
while(1)
{
if(0<=n&&n<20)
{
YELLOW_LED=1;
GREEN_LED=1;
RED_LED=flicker;
}
if(20<=n&&n<40)
{
RED_LED=1;
YELLOW_LED=1;
GREEN_LED=flicker;
}
if(40<=n&&n<60)
{
RED_LED=1;
GREEN_LED=1;
YELLOW_LED=flicker;
if(n==59)
n=0;
}
}
}
void Time0() interrupt 1
{
TR0=0;
i++;
if(i==10)
{
flicker=~flicker;
i=0;
n++;
}
TH0=0x3C;
TL0=0xAF;
TR0=1;
}
下面是另一个用51单片机的霓虹灯2:
如果网页复制的代码无法编译成功可以从:http://www.51hei.com/f/nhddpj_c.rar 这个链接下载
#include
#define uchar unsigned char
#define uint unsigned int
uchar ss[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x00,0xff,0x00,0xff,0x00,0x01,0x03,0x06,
0x0c,0x18,0x30,0x60,0xc0,0x80,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0x01,0x03,0x07,
0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,0x00,
0xff,0x00,0xff,0x00,0x01,0x03,0x07,0x0f,
0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,0xff,
0x00,0xff,0x00,0xff,0x00,0x78,0xf0,0xff,
0x00,0xff,0x00,0x80,0x40,0x20,0x10,0x08,
0x04,0x02,0x01,0xff,0x00,0xff,0x00,0xff,
0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,
0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
/*数组中为霓虹灯闪烁花样,单流水,双流水,三流水,四流水和倒流*/
uint m,n,i;
void delay(m)
{
while(m--)
for(i=0;i<120;i++);
}
void main() //主函数。
{
while(1)
{
P1=ss[n];
P3=ss[n];
delay(400);
P1=0x00;
n++;
if(n==96)
n=0;
}
}
51单片机霓虹 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)