找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

单片机菜鸟求助,交通灯程序

[复制链接]
admin 发表于 2012-9-2 08:36:19 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include<at89x52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit greenA=P0^0;
sbit redA=P0^1;
sbit yellowA=P0^2;
sbit greenB=P0^3;
sbit redB=P0^4;
sbit yellowB=P0^5;
char value;
char flg=0;
void delay(uint n);
void tongxingA();
void huangdengA();
void hongdengA();
void tongxingB();
void huangdengB();
void hongdengB();
void main()
{
int n;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
IE=0x82;
value=0x01;
P0=0xff;
while(1){
flg++;
if(flg==1){
tongxingA();
hongdengB();
}
if(flg>1){
if(flg<10){
huangdengA();
hongdengB();
}
if(flg==10){
tongxingB();
hongdengA();
}
if(flg>10){
if(flg<20){
huangdengB();
hongdengA();
}}
if(flg==20){
flg=0;
hongdengB();
tongxingA();
}
}
}
}

void timer0_int(void)interrupt 1 using 1
{
static int counter;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(counter++>=20){
counter=0;
flg=1;
}
}
void tongxingA()
{
greenA=0;
redA=1;
yellowA=1;
}
void hongdengA()
{
greenA=1;
redA=0;
yellowA=1;
}
void huangdengA()
{
greenA=1;
redA=1;
yellowA=0;
}
void tongxingB()
{
greenB=0;
redB=1;
yellowB=1;
}
void hongdengB()
{
greenB=1;
redB=0;
yellowB=1;
}
void huangdengB()
{
greenB=1;
redB=1;
yellowB=0;
}
延时貌似有问题,哪位大侠帮帮忙指点下,不胜感激
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 11:59 , Processed in 0.049116 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表