📄 epp.c.txt
字号:
#include <string.h>
#include <math.h>
#include <stdio.h>
#include "def.h"
#include "2410addr.h"
#include "EPP.h"
#include "2410lib.h"
#include "Lcd.h"
#include "ShuRuFa.h"
#include "2410RTC.h"
#include "_ExtGloVar.h"
extern volatile unsigned char HZK[];
extern unsigned char asc16[][16];
volatile U8 ScreenBuffer1[SCREENH * SCREENW];
volatile U8 ReportBuffer[REPORTHEIGHT * REPORTWIDTH];
volatile int UltrasoundNumber;
int Copies = 1;
unsigned char Resolution = 3;
unsigned char dither[16][16] =
{
0,128,32,160,8,136,40,168,2,130,34,162,10,138,42,170,
192,64,224,96,200,72,232,104,194,66,226,98,202,74,234,106,
48,176,16,144,56,184,24,152,50,178,18,146,58,186,26,154,
240,112,208,80,248,120,216,88,242,114,210,82,250,122,218,90,
12,140,44,172,4,132,36,164,14,142,46,174,6,134,38,166,
204,76,236,108,196,68,228,100,206,78,238,110,198,70,230,102,
60,188,28,156,52,180,20,148,62,190,30,158,54,182,22,150,
252,124,220,92,244,116,212,84,254,126,222,94,246,118,214,86,
3,131,35,163,11,139,43,171,1,129,33,161,9,137,41,169,
195,67,227,99,203,75,235,107,193,65,225,97,201,73,233,105,
51,179,19,147,59,187,27,155,49,177,17,145,57,185,25,153,
243,115,211,83,251,123,219,91,241,113,209,81,249,121,217,89,
15,143,47,175,7,135,39,167,13,141,45,173,5,133,37,165,
207,79,239,111,199,71,231,103,205,77,237,109,197,69,229,101,
63,191,31,159,55,183,23,151,61,189,29,157,53,181,21,149,
255,127,223,95,247,119,215,87,253,125,221,93,245,117,213,85
};
/****************************************************/
/*** ReadBit() ***/
/*** read the require bit and return it ,0 or 1 ***/
/****************************************************/
unsigned int ReadBit( unsigned int variable , int bit)
{ return( variable & ( 1 << bit ) ? 1 : 0 ); }
/****************************************************/
/*** BitReset() ***/
/*** reset the require bit and return the result ***/
/*** byte ***/
/****************************************************/
unsigned int BitReset( unsigned int variable , int bit )
{ return( variable & ( ~( 1 << bit ) ) ); }
/****************************************************/
/*** BitSet() ***/
/*** reset the require bit and return the result ***/
/*** byte ***/
/****************************************************/
unsigned int BitSet( unsigned int variable , int bit )
{ return( variable | ( 1 << bit ) ); }
/***************************************/
/*** InitialPort() ***/
/*** Initialize the port ,terminate from the ***/
/*** current mode and return to compability ***/
/*** mode ***/
/***************************************/
void InitialPort()
{
rGPDDAT = BitReset(rGPDDAT,C_nSelect);
rGPDDAT = BitReset(rGPDDAT,C_nInit);
rGPDDAT = BitSet(rGPDDAT,C_nAutoLF);
rGPDDAT = BitSet(rGPDDAT,C_nStrobe);
Delay(6);
rGPDDAT = BitSet(rGPDDAT,C_nInit);
while( ReadBit(rGPGDAT, S_Busy) );
while( ! ReadBit(rGPGDAT, S_nAck) );
while( ReadBit(rGPGDAT, S_PaperEnd) );
while( ! ReadBit(rGPGDAT, S_Select) );
while( ! ReadBit(rGPGDAT, S_nError) );
}
/**************************************/
/*** SppWrite ***/
/*** Write Data To SPP ***/
/**************************************/
void SppWrite(unsigned char data)
{
// reset the contral bit
rGPDDAT = BitReset(rGPDDAT,C_nSelect);
// startup a data write cycle wait s7 ,s5 low;s6,s4,s3 high
while( ReadBit(rGPGDAT, S_Busy) );
while( ! ReadBit(rGPGDAT, S_Select) );
// write a byte of data to the printer
rGPDDAT &= 0x00ff;
rGPDDAT |= ( data << 8 );
rGPDDAT = BitReset(rGPDDAT, C_nStrobe);
while( !ReadBit(rGPGDAT, S_Busy) );
rGPDDAT = BitSet(rGPDDAT , C_nStrobe);
}
int Check_Printer(void)
{
int CheckResult1 = 0;
unsigned char StringExit[2][30] = {{"Press any key to exit!"},{"按任意键退出!"}};
unsigned char String1[2][45] = {{"Power and cable error!"},{"打印错误! 请检查电源及电缆!"}};
unsigned char String2[2][40] = {{"Paper error! Please load the paper!"},{"打印错误! 请装入纸张!"}};
unsigned char String3[2][40] = {{"Unknown error!"},{"打印错误! 发生未知错误!"}};
Clear_HintRegion();
if( !ReadBit( rGPGDAT, S_PaperEnd) ) CheckResult1 = 1;
else
{
if( ReadBit( rGPGDAT, S_Busy) )
{
PutString(HINTX, HINTY, String1[Language], 1);
PutString(HINTX+300, HINTY, StringExit[Language], 1);
while(Key_Done==0);
Key_Done=0;
Clear_HintRegion();
}
else
{
if( !ReadBit( rGPGDAT, S_Select) )
{
PutString(HINTX, HINTY, String2[Language], 1);
PutString(HINTX+300, HINTY, StringExit[Language], 1);
while(Key_Done==0);
Key_Done=0;
Clear_HintRegion();
}
else
{
PutString(HINTX, HINTY, String3[Language], 1);
PutString(HINTX+300, HINTY, StringExit[Language], 1);
while(Key_Done==0);
Key_Done=0;
Clear_HintRegion();
}
}
}
//CheckResult2 = Check_ID();
//return( (CheckResult1 & CheckResult2) );
return (CheckResult1);
}
/****************************************************/
/*** Read_Pixel() ***/
/*** read data from the memory of the Ultrasonic B ***/
/****************************************************/
void Read_Pixel(unsigned char type)
{
unsigned char *ptr_display;
volatile unsigned char *ptr_buffer;
int i, j;
float k, r = 0.3;
unsigned char temp;
//正向图像
//*
ptr_display=(unsigned char *)(DISPLAY_BUFFER);
ptr_buffer=ScreenBuffer1;
for (j=0; j<SCREENH; j++)
{
for (i=0; i<SCREENW; i+=2)
{
*ptr_buffer= (((*ptr_display)&0x0f)<<4);
ptr_buffer++;
*ptr_buffer= ((*ptr_display)&0xf0) ;
ptr_buffer++;
ptr_display++;
}
ptr_display+=(SCR_XSIZE_TFT_800600-DISPLAY_WIDTH);
}
if (CPUCtrlImg==1)
{
ptr_display=(unsigned char *)(DISPLAY_BUFFER) + IMAGEY*SCR_XSIZE_TFT_800600 + DISPLAY_WIDTH;
ptr_buffer=ScreenBuffer1+IMAGEY*SCREENW + IMAGEX;
for (j=0; j<IMAGEH; j++)
{
for (i=0; i<IMAGEW; i++)
{
if (*ptr_buffer==0) *ptr_buffer=*ptr_display;
ptr_buffer++;
ptr_display++;
}
ptr_buffer+=(SCREENW-IMAGEW);
ptr_display+=(SCR_XSIZE_TFT_800600 -IMAGEW);
}
}
else
{
ptr_display=(unsigned char *)(STORE_BEGIN);
ptr_buffer=ScreenBuffer1+IMAGEY*SCREENW + IMAGEX;
for (j=0; j<IMAGEH; j++)
{
for (i=0; i<IMAGEW; i++)
{
if (*ptr_buffer==0) *ptr_buffer=*ptr_display;
ptr_buffer++;
ptr_display++;
}
ptr_buffer+=(SCREENW-IMAGEW);
}
}
/*
//test
while(symbol == 0)
{
PutString(100, 480, string,0);
if(Key_Done == 1)
{
Key_Done = 0; key = Key_Val;
switch(key)
{
case 0x18:
r += 0.1;
sprintf(str, "r = %d", (int)(r *10));
PutString(100, 500, (unsigned char *)str, 0);
break;
case 0x19:
r -= 0.1;
sprintf(str, "r = %d", (int)(r *10));
PutString(100, 500, (unsigned char *)str, 0);
break;
case 0x0d:
Glib_FilledRectangle(100, 480, 400, 520, 0);
symbol = 1;
break;
}
}
}
*/
k = 255 / pow(255,r); // k=200 灰度参数
//gray correction
for (j=0; j<SCREENH; j++)
{
for (i=0; i<SCREENW; i++)
{
temp = ScreenBuffer1[j*SCREENW+i];
if(temp < 255)
ScreenBuffer1[j*SCREENW+i] = k * pow((float)temp, r);
}
}
//循环中的边界值(h: IMAGEY ~ IMAGEY+256 w: IMAGEX-28 ~ IMAGEX-12)
if (type != 1)
{
for(j = GRAYBARY; j < (GRAYBARY+256); j++)
{
for(i = GRAYBARX; i < (GRAYBARX+GRAYBARW); i ++)
{
*(ScreenBuffer1+j*SCREENW+i) = 255 - (j-GRAYBARY);
}
}
}
}
/****************************************************
void Set_SingalBit(void)
set the register of io
****************************************************/
void Set_SingalBit(void)
{
// bit 15-8 of rGPDDAT is used as data bit(OUTPUT); bit 7,6,2,1 of rGPDDAT is used as control bit(OUTPUT)
rGPDCON &= 0x00000fc3;
rGPDCON |= 0x55555014;
// bit 3,2,1,0 of rGPGDAT is used as status bit.
// first set bit S_Busy,S_PaperEnd,S_Select to the opposite.
rGPGCON &= 0xffffff00;
rGPGCON |= 0x00000055;
rGPGDAT = BitSet(rGPGDAT, S_Busy);
rGPGDAT = BitSet(rGPGDAT, S_PaperEnd);
rGPGDAT = BitReset(rGPGDAT, S_Select);
rGPGCON &= 0xffffff00;
}
/****************************************************/
/*** Send_Command() ***/
/*** send data to the printer ***/
/****************************************************/
/*
void Send_Command(void)
{
int i;
unsigned char PrinterCommand_PCL[167] =
{
esc,'E', // reset escE
// esc,'*','p','9','9','9','x','2','2','5','1','Y',
esc,'&','r','0','F', // flush all pages command
esc,'*','l','1','R', // pixels placement
esc,'&','u','6','0','0','D', // meaure units
esc,'&','l','0','o', // logical page orientation
esc,'&','l','7','H', // paper source (0)
esc,'&','a','0','P', // text orentation
esc,'&','l','2','6','A', // select page size (a4) 40
esc,'&','l','1','X', // copies
esc,'&','l','0','u','0','Z',
esc,'&','l','0','E', // top margin
esc,'*','p','3','x','1','4','Y', // position the cursor
esc,'*','p','0','R', // pattern reference point
esc,'*','c','5','6','1','2','x','8','1','7','7','Y', // image size
esc,'*','p','0','x','1','0','0','Y', //postion the cursor
esc,'*','c','0','T', // set the top left corner(start point) to the current point(0,100)
esc,'*','a','0','p', // text orentation
esc,'%','0','A', // enter pcl mode--use the previous pcl course position
esc,'*','l','2','0','4','O', //logical orentation
esc,'*','v','1','n','1','O', // image transparency
esc,'*','v','1','T', // pattern type
esc,'*','p','1','0','0','x','1','2','9','1','Y', // position the cursor 137
esc,'*','t','6','0','0','R', // resolution
esc,'*','r','0','F', // IMAGE orentation
esc,'*','r','2','0','4','8','S', // image width157
esc,'*','r','1','A', // start raster
esc,'*','b','0','M' // copression mode 167
};
unsigned char PrinterCommand_PJL[57] ={
esc,'%','-','1','2','3','4','5','X','@','P','J','L',cr,lf,
'@','P','J','L',' ','S','E','T',' ','R','E','T','=','O','N',cr,lf,
'@','P','J','L',' ','E','N','T','E','R',' ','L','A','N','G','U','A','G','E','=','P','C','L',cr,lf };
for( i = 0; i < 57; i ++ ) { SppWrite( PrinterCommand_PJL[i] ); }
for( i = 0; i < 43; i ++ ) { SppWrite( PrinterCommand_PCL[i] ); }
SppWrite(Copies+48);
for( i = 44; i < 140; i ++ ) { SppWrite( PrinterCommand_PCL[i] ); }
SppWrite(6+48);
for( i = 141; i < 157; i ++ ) { SppWrite( PrinterCommand_PCL[i] ); }
//SppWrite(N_Image*IMAGEW /1000+48);
//SppWrite(N_Image*IMAGEW /100+48);
//SppWrite(N_Image*IMAGEW /10+48);
//SppWrite(N_Image*IMAGEW %10+48);
for( i = 157; i < 167; i ++ ) { SppWrite( PrinterCommand_PCL[i] ); }
}
*/
/*******************************************
// function: send control command to printer
//style 0:print image 1:print report
********************************************/
void Send_Command(unsigned char style)
{
int i;
unsigned char PrinterCommand_PJL[57] ={
esc,'%','-','1','2','3','4','5','X','@','P','J','L',cr,lf,
'@','P','J','L',' ','S','E','T',' ','R','E','T','=','O','N',cr,lf,
'@','P','J','L',' ','E','N','T','E','R',' ','L','A','N','G','U','A','G','E','=','P','C','L',cr,lf };
//#if (style == 0)
unsigned char PrinterCommand_PCL[168] =
{
esc,'E', // reset escE
// esc,'*','p','9','9','9','x','2','2','5','1','Y',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -