*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;
}
Previous article:Four-digit digital temperature gauge
Next article:Timer application example source code
Recommended ReadingLatest update time:2024-11-16 12:47
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Live broadcast tonight at 20:00 [Developing AI intelligent robots based on TI's newly released Robotics SDK] Admission at 19:30
- 【Short-term weather forecast system】v0.0.1 implementation
- Talk about the serial port RS485 interface of MSP430F149
- First release, unboxing post? All the boards I applied for were received~
- Various short-range wireless communication technologies
- Sincerely recruit fire protection engineers
- Can anyone tell me what "crossing zero" means?
- [2022 Digi-Key Innovation Design Competition] Material Unboxing - STM32H745I-DISCO
- How to generate HPS_0.h after Quartus 17.1
- STM32MP157A-DK1 Review - 1. Unboxing, Development Board and SOC, etc.