The source program and scheme of making a micro printer with a single chip microcomputer system

Publisher:熙风细雨Latest update time:2015-03-13 Source: dqjsw Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//The idea of ​​​​the single-chip system printer program is as follows: 

// Printing specification (16×16 dot matrix), the printer executes the microcontroller n-dot paper moving instruction: 0x1B-0x4A-n. Move forward n dot lines, the value of n is between 1-255.
// Set the n-dot line spacing: 0x1B-0x31-n. The value of n is between 0-255,
// When using the ESC/K command to print dot matrix graphics, usually set n=0. When printing text, usually set n=3.

//-----------------------Function declaration--------------------------------------------------------
#include"stdio.h"
#include"absacc.h"
#include"reg51.h"
//-----------------------LCD interface pin declaration---------------------------------------------------------
sbit STB=P3^0; //Output, read data at the rising edge of the data strobe trigger pulse.
sbit BUSY=P3^1; //Input, "high" means the printer is "busy" and cannot receive data. sbit ACK=
P3^2; //Input, the "low" level of the acknowledge pulse indicates that the data has been received and is ready to receive the next data.
sbit ERR=P3^3; //Input, pull up to "high" level through a resistor, indicating that the printer has no fault.
sbit SEL=P3^4; //Input, pull up to "high" level through a resistor, indicating that the printer is online.
#define DATA_OUT P1 //P1 is the data port

bit printer_ERR=0; //Printer fault flag: 0 means normal, 1 means fault
bit printer_online=1; //Printer first flag: 1 means online, 0 means offline
#define check_ERR() printer_ERR=~ERR //Check if the printer has an error
#define check_online() printer_online=SEL //Check if the printer is online
//-----------------------Define each command word--------------------------------------------------------
#define printer_init() SEND_2BYTE(0x1B,0x40) //Initialize the printer
#define enter_hangzimode() SEND_2BYTE(0x1C,0x26) //Enter Chinese character printing command: 0x1C-0x26.
#define exit_hangzimode() SEND_2BYTE(0x1C,0x2E) //Exit Chinese character printing command: 0x1C-0x2E.
#define setting_LARGEhz() SEND_2BYTE(0x1C,0x0E) //The printed Chinese characters will be doubled in the horizontal direction, and the vertical direction will not be changed.
#define cancel_LARGEhz() SEND_2BYTE(0x1C,0x14) //Cancel double-width printing of Chinese characters:.
#define select_muster1() SEND_2BYTE(0x1B,0x36) //Select character set 1:.
#define select_muster2() SEND_2BYTE(0x1B-0x37) //Select character set 2:.
#define change_row() SEND_BYTE(0x0A) //Line break:.
#define change_page() SEND_BYTE(0xOC) //Page break:.
#define made_CZtable() SEND_BYTE(0x0B) //Execute vertical table making: 0x0B.
#define made_SPtable() SEND_BYTE(0x09) //Execute horizontal table making: 0x0B.
#define setting_rowLG() SEND_BYTE(0x0E) //Double width printing in a row: 0x0E.
#define cancel_rowLG() SEND_BYTE(0x14) //Cancel double width printing in a row: 0x14.
#define renew_char_set() SEND_2BYTE(0x1B,0x3A) //Restore characters in the character set: 0x1B-0x3A.
#define enter() SEND_BYTE(0x0D) //Enter: 0x0D.
#define delete_row() SEND_BYTE(0x18) //Delete a row: 0x18.
#define delete_byte() SEND_BYTE(0x7F) //Delete a byte: 0x7F.
#define execute_NULL() SEND_BYTE(00) //(4) NULL: 00.
//Set Chinese character dot matrix printing specifications (16×16 dot matrix): 0x1C-0x69-n
//Set Chinese character dot matrix: n=0, 16×16 dot matrix
//n=1, 8×16 dot matrix?
//n=2, 16×8 dot matrix
//n=3, 8×8 dot matrix.
#define setting_HZmode(n) SEND_2BYTE(0x1C,0x69);SEND_BYTE(n)
//Execute n-dot paper walking: 0x1B-0x4A-n. Go forward n dot rows, the value of n is in the range of 1-255.
#define goahead_nrow(n) SEND_2BYTE(0x1B,0x4A);SEND_BYTE(n)
//Set n-dot line spacing: 0x1B-0x31-n. The value of n is between 0 and 255.
//When using the ESC/K command to print dot matrix graphics, n=0 is usually set. When printing text, n=3 is usually set.
#define setting_rowgap(n) SEND_2BYTE(0x1B,0x31);SEND_BYTE(n)
//--------------------------------------------------------------------------------------------------
// Function name: SEND_BYTE
// Entry parameter: ndata
// Function function: Send 1BYTE data
//--------------------------------------------------------------------------------------------------
void SEND_BYTE(unsigned char ndata)
             {
              STB=1;
     while(BUSY);
        DATA_OUT=ndata;
     STB=0;
     STB=1;
     }

Reference address:The source program and scheme of making a micro printer with a single chip microcomputer system

Previous article:Principles of Hardware Circuit Design for Single Chip Microcomputer Application System
Next article:STC MCU IO pin damage dynamic self-test program

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号