📄 printer.c
字号:
/*------------------------------------------------------------------------------
CSAMPLE1.C
Copyright 1995-1999 Keil Software, Inc.
------------------------------------------------------------------------------*/
//#include <reg51.h> /* define 8051 registers */
#include <stdio.h> /* define I/O functions */
#include <math.h>
// 打印机厂家需要的头文件
#include<reg52.h>
#include<string.h>
// 加入自己定义的头文件。
#include "lyj.h"
//加入液晶厂家的显示公用头文件
#include "led.h"
#include "I2C.h"
extern unsigned int getnumber (void);
//unsigned int i=0;
extern void output (unsigned int);
//处理完毕所有的键盘输入;
unsigned int total = 4 ; // 合计需要存储4组
input sinput;
canshu scanshu;
// 建立所有公用的使用参数:
//unsigned char store[12][4];
//input store_sinput[4];
unsigned char screen ; // 屏幕状态,0是主屏,1是打印屏,2是设置屏1,3是设置屏2.
unsigned char bkey ; // 获得的键值
unsigned char Revbuffer[10];
void main (void)
{
// 初始化液晶
LcmInit();
//初始化打印机
intiPri();
//初始化单片机
intiCpu();
restoreConfig();
// intiLed();
// 开机显示画面;
showLcd(0);
while (1)
{
bkey = inputkey();
switch (bkey) //如果有键盘按下
{
case 1: inputnum(0);
break ;
case 2: inputnum(1);
break ;
case 3: inputnum(2);
break ;
case 4: inputnum(3);
break ;
case 5: inputnum(4);
break ;
case 6: inputnum(5);
break ;
case 7: inputnum(6);
break ;
case 8: inputnum(7);
break ;
case 9: inputnum(8);
break ;
case 10: inputnum(9);
break ;
case 11: inputnod(); //输入小数点
break ;
case 12: inputf1(); //输入F1键 存储
break ;
case 13: inputf2(); // 打印。
break ;
case 14: inputf3();
break ;
case 15: inputf4();
break ;
case 16: inputok(); //输入确定键
break ;
case 17: inputesc(); //输入取消键
break ;
case 18: inputback(); //输入backspace 键
break ;
case 19: inputqie(); //切换键
break ;
case 20: inputup(); //向上键
break ;
case 21: inputdown(); //向下键
break ;
case 22: inputlink(); //连接键 无用
break ;
case 23: inputlyj1(); //备用键1
break ;
case 24: inputlyj2(); //备用键2
break ;
default : break ;} //end of switch */
}// end of while
// 所有键盘的处理程序完成。
}// end of main
// 以下是所有的子函数。
//液晶初始化子函数、
/*void intiLed()
{
}*/
//打印机初始化函数
void intiPri()
{
// SP = 0xA0;
// IE = 0x1B;
TH1=0xe8; //波特率2400
TL1=0xe8; //波特率2400
//TH1=253; //波特率9600
TMOD=32; //串口设置,定时器1,方式2
SCON=0xd0; //串口发送方式3
TR1 = 1;
}
// 单片机初始化函数
void intiCpu()
{
screen =0 ; // 屏幕状态,0是主屏,1是设置屏 ,2是打印屏
Page =0;
Col=0; //光标默认位置是0.0
// 输入屏幕5个参数;
sinput.bianma =0;
sinput.num =0;
sinput.price =0;
sinput.nownum =0;
// sinput.total=4; // 合计需要存储4组
// 设置屏幕的6个参数
scanshu.hanghead =0; //起始横坐标
scanshu.liehead =0; //起始纵坐标
scanshu.wide =0; //标签宽度
scanshu.painum=0; //打印排数
scanshu.type =0; //条码类型
scanshu.comm =0; //输出串口
//记住光标的位置,用于响应键盘。
bkey =0;
}
//键盘扫描子程序
unsigned char inputkey ()
{
delay10ms(); //健消除抖动的延时函数
bkey=kbscan(); //键盘扫描函数
delay10ms();
return bkey;
}
// 键盘扫描子程序
unsigned char kbscan()
{
unsigned char sccode,recode;
unsigned char i;
for (i=0;i<4;i++)
{
if(i==0)
{ /*扫描第1行*/
P1 = 0xFF;
line1 = 0;// 发0行扫描。
line2 = 1;
line3 = 1;
line4 = 1;
sccode= P1;
sccode&= 0xFC;
//本行有键按下
if(sccode != 0xFC)
{
delay10ms();
sccode = P1;
sccode&=0xFC;
if(sccode !=0xFC)
{
sccode=P1;
sccode&=0xFC;
switch(sccode)
{
case 0x7C:
recode=1;break;
case 0xBC:
recode=2;break;
case 0xDC:
recode=3;break;
case 0xEC:
recode=4;break;
case 0xF4:
recode=5;break;
case 0xF8:
recode=6;break;
default:
break;
}
return recode;
}
}
}//end of if =0
else if (i == 1)
{
/*扫描第2行*/
P1 = 0xFF;
line1 = 1;// 发1行扫描。
line2 = 0;
line3 = 1;
line4 = 1;
sccode= P1;
sccode&= 0xFC;
//本行有键按下
if(sccode != 0xFC)
{
delay10ms();
sccode = P1;
sccode&=0xFC;
if(sccode !=0xFC)
{
sccode=P1;
sccode&=0xFC;
switch(sccode)
{
case 0x7C:
recode=7;break;
case 0xBC:
recode=8;break;
case 0xDC:
recode=9;break;
case 0xEC:
recode=10;break;
case 0xF4:
recode=11;break;
case 0xF8:
recode=12;break;
default:
break;
}
return recode;
}
}
} // end of if i =1;
else if (i ==2)
{ /*扫描第3行*/
P1 = 0xFF;
line1 = 1;// 发3行扫描。
line2 = 1;
line3 = 0;
line4 = 1;
sccode= P1;
sccode&= 0xFC;
//本行有键按下
if(sccode != 0xFC)
{
delay10ms();
sccode = P1;
sccode&=0xFC;
if(sccode !=0xFC)
{
sccode=P1;
sccode&=0xFC;
switch(sccode)
{
case 0x7C:
recode=13;break;
case 0xBC:
recode=14;break;
case 0xDC:
recode=15;break;
case 0xEC:
recode=16;break;
case 0xF4:
recode=17;break;
case 0xF8:
recode=18;break;
default:
break;
}
return recode;
}
}
} // end of if i ==2;
else if (i ==3)
{
/*扫描第4行*/
P1 = 0xFF;
line1 = 1;// 发4行扫描。
line2 = 1;
line3 = 1;
line4 = 0;
sccode= P1;
sccode&= 0xFC;
//本行有键按下
if(sccode != 0xFC)
{
delay10ms();
sccode = P1;
sccode&=0xFC;
if(sccode !=0xFC)
{
sccode=P1;
sccode&=0xFC;
switch(sccode)
{
case 0x7C:
recode=19;break;
case 0xBC:
recode=20;break;
case 0xDC:
recode=21;break;
case 0xEC:
recode=22;break;
case 0xF4:
recode=23;break;
case 0xF8:
recode=24;break;
default:
break;
}
return recode;
}
}
} // end of if i =3;
else {
return 0;//没有键被按下
}
}// end of for .
line1 = 1;// 发0行扫描。
line2 = 1;
line3 = 1;
line4 = 1;
}// 键盘延时子程序
void delay10ms()
{
unsigned char i;
unsigned char j;
for (j=0xff; j>0; j--)
{
for(i=0xff;i>0;i--)
;
}
} //液晶显示子程序
void showLcd(unsigned int i)
{
unsigned char length;
unsigned char m;
switch (i)
{ case 0: // 显示主屏
screen =0;
Delay(20); //等待复位
// LcmInit();
LcmClear();
Page =0;
Col =16;
LcmPutHZ(18); // input
LcmPutHZ(23);
LcmPutHZ(25);
LcmPutHZ(30);
LcmPutHZ(29);
Page =Page +2; //换行
Col=Col-40;
LcmPutHZ(28); // set 1
LcmPutHZ(14);
LcmPutHZ(29);
LcmPutHZ(1);
Page =Page +2; //换行
Col=Col-32;
LcmPutHZ(28); // set 2
LcmPutHZ(14);
LcmPutHZ(29);
LcmPutHZ(2);
Page=0;
Col =0;
LcmPutHZ(39); //维护光标的位置,显示光标
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -