给大家分享一个我自己做的停车场车位剩余量模拟显示及仿真,测试成功.
仿真原理图如下(proteus仿真文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- sfr P0M0=0x93;
- sfr P0M1=0x94;
- sfr P1M0=0x91;
- sfr P1M1=0x92;
- sfr P2M0=0x95;
- sfr P2M1=0x96;
- sfr P3M0=0xb1;
- sfr P3M1=0xb2;
- const unsigned char seg7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- sbit car_in=P1^0;
- sbit car_out=P1^1;
- sbit en1=P2^6;
- sbit en2=P2^7;
- void ms_delay(unsigned int t)
- {
- unsigned int i;
- for(t;t>0;t--)
- for(i=110;i>0;i--)
- ;
- }
- void display(int n)
- {
- char b2,b1;
- b2=n/10;
- b1=n%10;
- P0=seg7[b2];
- en2=0;
- ms_delay(10);
- en2=1;
- P0=seg7[b1];
- en1=0;
- ms_delay(10);
- en1=1;
- }
- main()
- {
- int num=99;
- P0M1=0xff;
- P0M0=0xff;
- P1M1=0x03;
- P1M0=0x00;
- display(num);
- while(1)
- {
- if(car_in==0)
- {
- ms_delay(10);
- if(car_in==0)
- {
- num--;
- }
- }
- if(car_out==0)
- {
- ms_delay(10);
- if(car_out==0)
- {
- num++;
- }
- }
- if(num>99)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
停车场车位剩余量模拟显示.zip
(32.95 KB, 下载次数: 116)
|