问题描述
- 51单片机交通灯的proteus仿真怎么弄
-
这是我的代码和原理图,目的要求是点亮发光二极管同时数码管计数一段时间,然后换别的二极管亮再计数,程序不知道哪里错了,一运行数码管和发光二极管就不能按要求工作#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit dx_hong=P0^0;
sbit dx_huang=P0^1;
sbit dx_lv=P0^2;
sbit nb_hong=P0^3;
sbit nb_huang=P0^4;
sbit nb_lv=P0^5;
uchar a,shi,ge,num1,num2,num3,num4,num5,num6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge)
{
wela=1;
P2=0xfe;
wela=0;
P1=0xff;
dula=1;
P1=table[shi];
dula=0;
delayms(5);wela=1; P2=0xfd; wela=0; P1=0xff; dula=1; P1=table[ge]; dula=0; delayms(5);
}
void djs(uchar xs)
{
if(num2>xs)
{
num2=0;
}
shi=(xs-num2)/10;
ge=(xs-num2)%10;
display(shi,ge);
}
void init()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;}
void main()
{while(1) { init(); dx_hong=0; dx_huang=1; dx_lv=1; nb_hong=1; nb_huang=1; nb_lv=0; djs(60); dx_hong=1; dx_huang=0; dx_lv=1; nb_hong=1; nb_huang=0; nb_lv=1; djs(30); dx_hong=1; dx_huang=1; dx_lv=0; nb_hong=0; nb_huang=1; nb_lv=1; djs(60); dx_hong=1; dx_huang=0; dx_lv=1; nb_hong=1; nb_huang=0; nb_lv=1; djs(30); }
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==20)
{
num1=0;
num2++;}
}
解决方案
51单片机学习笔记(五)_VSPD+Proteus+串口调试工具+Keil C51实现单片机串口通信仿真
解决方案二:
http://wenku.baidu.com/link?url=QYXlJoOYAspQCkFIFwq6BfuV0wWs1aSwr8aJJd9kpYBgY-elJdzInJi0mjuPITiA2VIp-cFC_srT9hHoP2CepqmG4Ue3gBfG8mxAbn5lmte
http://m.wendangku.net/doc/7d164a90e009581b6bd9ebc9.html