#define uchar unsigned char
#define uint unsigned int
#include <reg52h>
#include <stdioh>
#include <absacch>
#include <mathh>
#include <stringh>
#include <ctypeh>
#include <stdlibh>
#define PIN XBYTE[0x8000]
#define POUT XBYTE[0x9000]
sbit PRINTSTB =P1^6;
sbit DOG=P1^7;
bdata char pinvalue;
sbit PRINTBUSY=pinvalue^7;
sbit PRINTSEL =pinvalue^6;
sbit PRINTERR =pinvalue^5;
sbit PRINTACK =pinvalue^4;
void PrintString(uchar String1,uchar String2);
void initprint(void);
void print(uchar a);
void initprint(void) //打印机初始化子程序
{
pinvalue=PIN;
if((PRINTSEL==1)&&(PRINTERR==1))
{
print(0x1b); print(0x40); print(0x1b); print(0x38); print(0x4);
}
}
void print(uchar a) //打印字符a
{
pinvalue=PIN;
if((PRINTSEL==0)||(PRINTERR==0)) return;
for(;;) {
DOG=~DOG;
pinvalue=PIN;
if(PRINTBUSY==0) break;
}
DOG=~DOG;
POUT=a;
PRINTSTB=1; PRINTSTB=1; PRINTSTB=1; PRINTSTB=1;
PRINTSTB=0; PRINTSTB=0; PRINTSTB=0; PRINTSTB=0;
PRINTSTB=1;
}
void PrintString(uchar String) //打印字符串后回车
{
uchar CH;
for (;;) {
DOG=~DOG;
CH=String;
if (CH==0) { print(0x0d); break; }
print(CH);
String++;
}
initprint();
}
希望对你有点帮助!
使用<>的都是C编译器内部自带的H文件!而自定义的H文件上用""
你是刚学单片机编程的新手吧
reg52h引用的外部资源文件,这个文件包括了硬件信息和外部模块提供的可使用的函数和变量的说明。可以用文本方式打开reg52h,仔细研究下,会有一些写程序的体会。
absacch :利用它可十分方便地实现对任何内存空间的直接 *** 作
楼上可以得到图形,就是循环太多了点,加判断应该更好点。
public class Test {
public static void main(String[] args){
int size=9;
for(int i=size;i>0;i=i-2){
for(int j=0;j<=size;j++){
if(j>i/2&&j<=size-i/2)Systemoutprint("");
else Systemoutprint(" ");
}
Systemoutprintln("");
}
}
}
/ A simple quine (self-printing program), in standard C /
/ Note: in designing this quine, we have tried to make the code clear
and readable, not concise and obscure as many quines are, so that
the general principle can be made clear at the expense of length
In a nutshell: use the same data structure (called "progdata"
below) to output the program code (which it represents) and its own
textual representation /
#include <stdioh>
void quote(const char s)
/ This function takes a character string s and prints the
textual representation of s as it might appear formatted
in C code /
{
int i;
printf(" \"");
for (i=0; s[i]; ++i) {
/ Certain characters are quoted /
if (s[i] == '\\')
printf("\\\\");
else if (s[i] == '"')
printf("\\\"");
else if (s[i] == '\n')
printf("\\n");
/ Others are just printed as such /
else
printf("%c", s[i]);
/ Also insert occasional line breaks /
if (i % 48 == 47)
printf("\"\n \"");
}
printf("\"");
}
/ What follows is a string representation of the program code,
from beginning to end (formatted as per the quote() function
above), except that the string _itself_ is coded as two
consecutive '@' characters /
const char progdata[] =
"/ A simple quine (self-printing program), in st"
"andard C /\n\n/ Note: in designing this quine, "
"we have tried to make the code clear\n and read"
"able, not concise and obscure as many quines are"
", so that\n the general principle can be made c"
"lear at the expense of length\n In a nutshell:"
" use the same data structure (called \"progdata\"\n"
" below) to output the program code (which it r"
"epresents) and its own\n textual representation"
" /\n\n#include <stdioh>\n\nvoid quote(const char "
"s)\n / This function takes a character stri"
"ng s and prints the\n textual representati"
"on of s as it might appear formatted\n in "
"C code /\n{\n int i;\n\n printf(\" \\\"\");\n "
" for (i=0; s[i]; ++i) {\n / Certain cha"
"racters are quoted /\n if (s[i] == '\\\\')"
"\n printf(\"\\\\\\\\\");\n else if (s["
"i] == '\"')\n printf(\"\\\\\\\"\");\n e"
"lse if (s[i] == '\\n')\n printf(\"\\\\n\");"
"\n / Others are just printed as such /\n"
" else\n printf(\"%c\", s[i]);\n "
" / Also insert occasional line breaks /\n "
" if (i % 48 == 47)\n printf(\"\\\"\\"
"n \\\"\");\n }\n printf(\"\\\"\");\n}\n\n/ What fo"
"llows is a string representation of the program "
"code,\n from beginning to end (formatted as per"
" the quote() function\n above), except that the"
" string _itself_ is coded as two\n consecutive "
"'@' characters /\nconst char progdata[] =\n@@;\n\n"
"int main(void)\n / The program itself /\n"
"{\n int i;\n\n / Print the program code, cha"
"racter by character /\n for (i=0; progdata[i"
"]; ++i) {\n if (progdata[i] == '@' && prog"
"data[i+1] == '@')\n / We encounter tw"
"o '@' signs, so we must print the quoted\n "
" form of the program code /\n {\n "
" quote(progdata); / Quote all /\n"
" i++; / Skip second '"
"@' /\n } else\n printf(\"%c\", p"
"rogdata[i]); / Print character /\n }\n r"
"eturn 0;\n}\n";
int main(void)
/ The program itself /
{
int i;
/ Print the program code, character by character /
for (i=0; progdata[i]; ++i) {
if (progdata[i] == '@' && progdata[i+1] == '@')
/ We encounter two '@' signs, so we must print the quoted
form of the program code /
{
quote(progdata); / Quote all /
i++; / Skip second '@' /
} else
printf("%c", progdata[i]); / Print character /
}
return 0;
}
以上就是关于微打印机C程序全部的内容,包括:微打印机C程序、Java编程:编一个能打印如下图形的Java源程序 急啊、、、、最近发现一个可能比较有趣的问题,如何编程使程序显示结果为其本身源码。程序执行结果就是打印出其源码。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)