#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