21 河南理工大学本科课程设计报告
uchar temp; P0=0xe0; P3=0xbf; temp=P0;
temp=temp&0xe0; if(temp!=0xe0) {
Delay5ms(); temp=P0;
temp=temp&0xe0; if(temp!=0xe0)
{
temp=P0; switch(temp)
{
case 0xc0:k=1;break; case 0xa0:k=2;break; case 0x60:k=3;break; }
while(temp!=0xe0)
{
temp=P0;
temp=temp&0xe0; } }
keys(k); }
P0=0xe0; P3=0x7f; temp=P0; temp=temp&0xe0; if(temp!=0xe0) {
Delay5ms(); temp=P0;
temp=temp&0xe0; if(temp!=0xe0) {
21
22 河南理工大学本科课程设计报告
temp=P0;
switch(temp) {
case 0xc0:k=4;break; case 0xa0:k=5;break; case 0x60:k=6;break; }
while(temp!=0xe0) {
temp=P0;
temp=temp&0xe0;
} }
keys(k);
}
return k; }
void timer0() interrupt 1 { TH0=(65536-45872)/256; TL0=(65536-45872)%6; a++; if(k==1) {if(a==20)
{ b++;a=0;}} if(k!=1) {if(a==20) a=0;} key();}
void led_show() {
dl=1;xl=1;nl=1;bl=1; dh=1;xh=1;nh=1;bh=1; dy=1;xy=1;ny=1;by=1; d=(m+n); f=(2*m+n);
g=(2*m+2*n);
22
23 河南理工大学本科课程设计报告
if(b
{
dl=0;xl=0;nl=1;bl=1; dh=1;xh=1;nh=0;bh=0; dy=1;xy=1;ny=1;by=1; }
if(b
dl=1;xl=1;nl=1;bl=1; dh=1;xh=1;nh=1;bh=1; dy=0;xy=0;ny=0;by=0; }
if(b
//南北通
dl=1;xl=1;nl=0;bl=0; dh=0;xh=0;nh=1;bh=1; dy=1;xy=1;ny=1;by=1; }
if(b
dl=1;xl=1;nl=1;bl=1; dh=1;xh=1;nh=1;bh=1; dy=0;xy=0;ny=0;by=0; }
if(b==g) b=0;} void main() {
P1M1=0x00; P1M0=0xff;
TMOD=0x01;
TH0=(65536-45872)/256; TL0=(65536-45872)%6; EA=1; ET0=1; TR0=1; while(k!=1) { key();
P0=wei[0];
23
24 河南理工大学本科课程设计报告
P1=tab[m]; delays(10); P0=wei[1]; P1=tab[m/10]; delays(10); P0=wei[2]; P1=tab[n]; delays(10); P0=wei[3]; P1=tab[n/10];
delays(10);}
while(1) {
if(k==1) {
show(); led_show(); }
if(k==4) {
dl=1;xl=1;nl=1;bl=1; dh=0;xh=0;nh=0;bh=0; dy=1;xy=1;ny=1;by=1;
}}}
24
25 河南理工大学本科课程设计报告
附2 系统原理图
25