整个程序如下:
#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
#define Uchar unsigned char
#define Uint unsigned int
Uchar x_zb,y_zb;
void WriteData( Uchar dataW );
void WriteCommand( Uchar CommandByte );
void Delay( Uint );
void printfNumber(Uchar x,Uchar y,Uchar Number);
void Locatexy(Uchar,Uchar);
void EnableINT(void);
void DisableINT(void);
void interrupt0(void) interrupt 2 using 3 //定义外部中断1
{
DisableINT();
Delay(20);
printfNumber(16,220,x_zb);
printfNumber(21,220,y_zb);
Delay(20);
EnableINT();
}
void Main( void )
{
DisableINT();
Delay(30);
EnableINT();
while(1)
{
}
}
void EnableINT(void)
{
EA=1; //开所有中断
IT1=1; //外部中断1 边沿触发
EX1=1; //开外部中断1
}
void DisableINT(void)
{
// EA=0; //关所有中断
EX1=0; //关外部中断1
}
void Delay(Uint MS)
{
Uchar us,usn;
while(MS!=0)
{ usn = 4;
while(usn!=0)
{
us=0xf0;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
void WriteCommand( Uchar CommandByte ) {
P1 = CommandByte;
}
void WriteData( Uchar dataW ) {
P1 = dataW;
}
void Locatexy(Uchar x,Uchar y) {
Uint temp;
temp = (Uint)y*40+x;
WriteCommand( 0x29 );
WriteData( (Uchar)(temp & 0xff) );
WriteData( (Uchar)(temp /256 ) );
}
void printfNumber(Uchar x,Uchar y,Uchar Number)
{
Uchar a[3];
Uchar i,j;
a[0]=Number/100;
a[1]=(Number%100)/10;
a[2]=Number%10;
WriteCommand( 0x14 );
for(i=0;i <3;i++)
{
Locatexy(x,y);
WriteCommand( 0x47 );
for(j=0;j <16;j++)
WriteData(a[j%3]);
x++;
}
谢谢!