微型打印機(jī)C51控制程序
*本程序?yàn)樾聵s達(dá)微型打印機(jī)的控制程序,通過計(jì)算機(jī)串行通訊控制輸入要打印的信息,打印信息用長度為36的數(shù)組保存,在根據(jù)數(shù)組中的數(shù)據(jù)打印相應(yīng)的結(jié)果,第一位為起始位,第二位為命令位,第三~五位為地址位,第六位為器件類型,第七~二十二位為位置描述,第二十三位為事件類型,后面的是時(shí)間,最后一位是校驗(yàn)位。*/
#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; //設(shè)置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點(diǎn)陣漢字
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;
}