微型打印机C51控制程序
扫描二维码
随时随地手机看文章
*本程序为新荣达微型打印机的控制程序,通过计算机串行通讯控制输入要打印的信息,打印信息用长度为36的数组保存,在根据数组中的数据打印相应的结果,第一位为起始位,第二位为命令位,第三~五位为地址位,第六位为器件类型,第七~二十二位为位置描述,第二十三位为事件类型,后面的是时间,最后一位是校验位。*/
#i nclude
#define UCHAR unsigned char
#define UINT unsigned int
#define TIME1 1000
#define TIME2 200
#define LEN 35
.......
extern UCHAR sd[36]={0x9a,0x01,0x30,0x30,0x31,0x01,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,"050707000000"};
void Delay(UCHAR m)
{
while(--m);
}
void DelayInt(UINT n)
{
while(--n);
}
void Out(char sa)
{
STB=1;
while(BUSY);
Delay(5);
P0 = sa;
STB = 0;
Delay(4);
STB = 1;
}
void Outs(char ss[])
{
char i=0;
while(ss[i]!=0x00)
{
Out(ss[i]);
i++;
}
}
void Outn(char ss[],UCHAR x,UCHAR y)
{
char i;
for(i=x-1;i {
Out(ss[i]);
}
}
void OutSerial(char sb)
{
ES = 0;
SBUF = sb;
while(!TI);
TI = 0;
ES = 1;
}
void main()
{
UCHAR j;
for(j=1;j<=TIME2;j++)
{
DelayInt(TIME1);
}
SCON = 0x50;
T2CON = 0x34;
RCAP2H = 0xff;
RCAP2L = 0xb2;
PS = 1;
IE = 0xb1; //设置SFR和波特率
while(1)
{
if(SEL == 1)
{
YLW = 1;
if(PE == 0)
{
RED = 1;
Out(0x1b);
Out(0x40);
Out(0x1b);
Out(0x4E);
Out(0x03); //装订长3行
Out(0x1b);
Out(0x38);
Out(0x00); //16*16点阵汉字
Out(0x1b);
Out(0x56);
Out(0x02);
Outn(sd,3,5);
Outs("# ");
Out(0x1b);
Out(0x57);
Out(0x01);
if(sd[5] == 0x01)
{
Outs("双波段");
}
else if(sd[5] == 0x02)
{
Outs("光截面");
}
else
{
Outs("其他");
}
Outs("探测器");
Out(0x0a);
Out(0x0d);
Outn(sd,7,22);
Out(0x0a);
Out(0x0d);
if(sd[22] == 0x01)
{
Outs("火警");
}
else if(sd[22] == 0x02)
{
Outs("故障");
}
else
{
Outs("待定");
}
Out(0x0a);
Out(0x0d);
Out(0x1b);
Out(0x56);
Out(0x02);
Out(sd[23]);
Out(sd[24]);
Outs("-");
Out(sd[25]);
Out(sd[26]);
Outs("-");
Out(sd[27]);
Out(sd[28]);
Outs(" ");
Out(sd[29]);
Out(sd[30]);
Outs(":");
Out(sd[31]);
Out(sd[32]);
Outs(":");
Out(sd[33]);
Out(sd[34]);
Out(0x1b);
Out(0x57);
Out(0x01);
Out(0x0a);
Out(0x0d);
Outs("********************");
Out(0x0a);
Out(0x0d); }
else
{
RED = 0;
}
}
else
{
YLW = 0;
}
}
}
void SerialInt() interrupt 4 //using 1
{
char sum,sa;
char i;
ES = 0;
if(RI)
{
RI = 0;
for(i=0;i {
sd[i] = sd[i+1];
}
sd[LEN] = SBUF;
sa = 0x9a;
if(sd[0] == sa)
{
sum = 0;
for(i=1;i {
sum=sum+sd[i];
}
if(sum == sd[LEN])
{
OutSerial(0xa0);
}
}
}
if(TI)
{
TI = 0;
}
ES = 1;
}