Micro printer C51 control program

Publisher:美梦小狮子Latest update time:2017-11-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

*This program is the control program of Xinrongda micro printer. The information to be printed is input through computer serial communication control. The printed information is saved in an array with a length of 36. The corresponding results are printed according to the data in the array. The first bit is the start bit, the second bit is the command bit, the third to fifth bits are the address bits, the sixth bit is the device type, the seventh to twenty-second bits are the location description, the twenty-third bit is the event type, the following is the time, and the last bit is the check bit. */

#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; //Set SFR and baud rate


while(1)
{
  if(SEL == 1)
  {
  YLW = 1;
  if(PE == 0)
  {  
  RED = 1;
   Out(0x1b);
   Out(0x40);
    Out(0x1b);
   Out(0x4E);
   Out(0x03); //Binding length 3 lines
   Out(0x1b);
   Out(0x38);
   Out(0x00); //16*16 dot matrix Chinese characters
   Out(0x1b);
   Out(0x56);
   Out(0x02);
    Outn(sd,3,5);
    Outs("# ");
   Out(0x1b);
   Out(0x57);
   Out(0x01);
    if(sd[5] == 0x01)
    {
     Outs("Dual band");
    }
    else if(sd[5] == 0x02)
    {
     Outs("Light cross section");
    }
    else
    {
     Outs("Others");
    }
    Outs("Detector");
   Out(0x0a);
   Out(0x0d); 
    Outn(sd,7,22);
   Out(0x0a);
   Out(0x0d); 
    if(sd[22] == 0x01)
    {
     Outs("Fire alarm");
    }
    else if(sd[22] == 0x02)
    {
     Outs ("Fault");
    }
    else
    {
     Outs("Pending");    }
    Out    (0x0a    );    Out(0x0d);     Out     (    0x1b);     Out (0x56);     Out(0x02); Out(sd[23]);     Out     (sd[24]); Outs (     "     -") ;     Out(     sd[25     ]); ;     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;
}


Reference address:Micro printer C51 control program

Previous article:Four-digit digital temperature gauge
Next article:Timer application example source code

Recommended ReadingLatest update time:2024-11-16 12:47

Introduction to C51 Programming Standards
Introduction: When programming, the first thing to consider is the feasibility of the program, followed by readability, portability, robustness, and testability. This is the general rule. However, many people ignore readability, portability, and robustness (the debuggable methods may be different), which is wrong. 1
[Microcontroller]
Interrupt Architecture of C51 Single Chip Microcomputer
The interrupt system of 80C51 has 5 interrupt sources (8052 has 6), 2 priorities, and can realize two-level interrupt nesting. The structure of the interrupt system of MCS-51 series microcontroller is as follows: Special registers related to the interrupt system: 1) Interrupt enable control register (IE)------Contro
[Microcontroller]
C51 Compiler - Language Extension (4) - Function
Function Declarations Cx51 makes some extensions to standard C. These extensions can be used to: (1) Declare a function as an interrupt procedure (2) Select the register group to use (3) Select the memory mode (4) Sound time can be re-entered (5) Declare external functions To include these extensions or at
[Microcontroller]
c51 special function register definition and function
  The microcontroller C51 language is inherited from the C language. Different from the C language, the C51 language runs on a single-chip microcomputer platform, while the C language runs on an ordinary desktop platform. C51 language has the advantages of clear structure of C language, which is easy to learn, and als
[Microcontroller]
c51 special function register definition and function
51 microcontroller reads and writes the C51 program of AT29C040
Let me introduce to you a c51 program for reading and writing AT29C040 using 51 microcontroller. #include 《reg51.h》 #include 《intrins.h》 unsigned char time; void int_t0(void) interrupt 1 { time++; } unsigned char d; //rec data bit rec(void) { TH0=0;time=0; while (!RI) {if (time》1) return(1);} RI=0; d=SBUF; return(0)
[Microcontroller]
PWM control LED light gradually turns on and off (C51)
/***********************************************************************/ /* ME300B MCU Development System Demonstration Program - PWM Control LED Light Gradually Brightens and Dims */ /* LED Display */                                     /*******************************************************************/ //PWM cont
[Microcontroller]
PID Control C51 Program (2)
This is a typical PID processing program found on the Internet. When using a single-chip microcomputer as a control CPU, please simplify it a little. The specific PID parameters must be determined by the specific object through experiments. Due to the processing speed and RAM resource limitations of the single-chip mi
[Microcontroller]
Design principle diagram of timer based on C51 single chip microcomputer
  As shown in the figure below, two common cathode digital tubes are connected to the P0 and P2 ports of the AT89S51 microcontroller. The P0 port drives the tens digit of the seconds, while the P2 port drives the ones digit of the seconds.   1. Use an 8-core cable to connect the P0.0/AD0 - P0.7/AD7 ports in the "MCU S
[Microcontroller]
Design principle diagram of timer based on C51 single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号