#include <reg52.h>
#include "51hei.H"
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit laba=P2^2;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char ch;a;
bit read_flag= 0 ;
void init_serialcom( void )
{
SCON = 0x50 ; //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x80 ; //SMOD=1;
TH1 = 0xFA ; //Baud:9600 fosc=11.0592MHz
IE |= 0x90 ; //Enable Serial Interrupt
TR1 = 1 ; // timer 1 run
TI=1;
}
unsigned char Im[4]={0x00,0x00,0x00,0x00};
uchar show[2]={0,0};
unsigned long m,Tc;
unsigned char IrOK;
void delay(uchar i)
{
uchar j,k;
P0=0xFF; //消隐
wela=1;
wela=0;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void display()
{
P0=table[show[0]];
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
delay(1);
P0=table[show[1]];
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delay(1);
}
//串口接收中断函数
void serial () interrupt 4 using 3
{
if (RI)
{
RI = 0 ;
ch=SBUF;
read_flag= 1 ; //就置位取数标志
}
}
/*演示主程序*/
void main(void)
{
unsigned int a;
guandz();
init_serialcom(); //初始化串口
while ( 1 )
{
if (read_flag) //如果取数标志已置位,就将读到的数从串口发出
{
read_flag= 0 ; //取数标志清0
Im[2]=ch;
}
show[1]=Im[2] & 0x0F; //取键码的低四位
show[0]=Im[2] >> 4;
for(a=10;a>0;a--)
{
display();
}
}
}
红色部分不是很懂, 假设 Im[2] =0xf0; show[1]=Im[2] & 0x0F = ?? show[0]=Im[2] >> 4=??
显示为什么是循环10次?
|