[程序源码]

PIC单片机写的交通灯程序

[复制链接]
740|1
手机看帖
扫描二维码
随时随地手机跟帖
IversonCar|  楼主 | 2015-8-27 15:12 | 显示全部楼层 |阅读模式
#include<pic.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
uchar H_time=0,L_time=0;
const uchar tab[]={0x0a,0x22,0x11,0x14};
extern uchar code[]={0x00,0x00,0x00,0x00};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=5;y>0;y--);
}
void light(uchar n)
{
uchar i,top,temp;
for(;n>0;n--)
{
PORTC=H_time*16+L_time;
H_time++;L_time++;
temp=0x00;
for(i=0;i<0xff;i++)
{
temp++;
PORTD=temp;
delay(2);
}
}
}
void RGB_light()
{
PORTB=tab[0];
light(7);H_time=0x00;
PORTB=tab[1];
light(2);H_time=0x00;L_time=0x00;
PORTB=tab[2];
light(7);L_time=0x00;
PORTB=tab[3];
light(2);H_time=0x00;L_time=0x00;
PORTB=0X00;

}
void main()
{
TRISD=0;
TRISB=0;
TRISC=0;
while(1)
{
RGB_light();
}

}





没钱买硬件,只能虚拟了


相关帖子

舒斯特尔| | 2015-8-27 16:01 | 显示全部楼层
这样也是一种好的学习方法啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

50

主题

344

帖子

0

粉丝