📄 s_utility.c
字号:
if (x>tmpXY[4][0]) {
if (x-tmpXY[4][0]>15) {
goto ReStartFlag;
}
} else {
if (tmpXY[4][0]-x>15) {
goto ReStartFlag;
}
}
x=(tmpXY[2][0]+tmpXY[1][0])/2;
if (x>tmpXY[4][0]) {
if (x-tmpXY[4][0]>15) {
goto ReStartFlag;
}
} else {
if (tmpXY[4][0]-x>15) {
goto ReStartFlag;
}
}
checkDone = TRUE;
while (CheckLCDLevel()==0);
loop--;
//}
}
}
SetDotWidth(1, 0);
rv = SetFactors();
*(P_U8)M328_PFSEL &= ~(0x02); // add by nie 2005/07/18
*(P_U32)M328_IMR &= 0x00EFFFFF;
Memory_val();
return(PPSM_OK);
}
void Memory_val(void){
U16 i;
U16 count;
U32 address;
count=*(P_U16)(CALIBADD+0x18);
ram_perase_sector(5);
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD, (U16)xIn[0]);
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+2, (U16)yIn[0]);
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+4, (U16)xIn[1]);
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+6, (U16)yIn[1]);
/*for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+8, (U16)(xFactor>>16));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x0A, (U16)(xFactor));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x0C, (U16)(xOffset>>16));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x0E, (U16)(xOffset));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x10, (U16)(yFactor>>16));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x12, (U16)(yFactor));*/
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x14, (U16)0x0001);
if ( count!=0) {
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x18, (U16)count);
}
/*for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x1A, (U16)(yOffset>>16));
for (i=0;i<1000;i++);
ram_pwrite_word(CALIBADD+0x1C, (U16)(yOffset)); */
}
void RecieveDataFrom_Uart1Register(void){
U16 Uart1ReceiveVal;
U16 i;
U32 temploop;
temploop=0;
comm_start:
Uart1ReceiveVal=*(P_U16)0xFFFFF904;
if ( Uart1ReceiveVal & 0x6000 ) {
if ( (SCI_IQHead==SCI_IQTail) && (UART_Flags & SCI_IQDIRTY) ) {
}
SCI_IQ[SCI_IQHead++] = (U8)Uart1ReceiveVal;
if ( SCI_IQHead >= SCI_IQSIZE ) SCI_IQHead = 0;
UART_Flags |= SCI_IQDIRTY;
temploop++;
if (temploop > 0xA024) {
return; ///////// 06/17/03
}
goto comm_start;
}
}
void RecieveDataFrom_Uart2Register(void){
U16 Uart2ReceiveVal;
U16 i;
U32 temploop;
temploop=0;
uart2comm_start:
Uart2ReceiveVal=*(P_U16)0xFFFFF914;
if ( Uart2ReceiveVal & 0x6000 ) {
if ( (SCI_IQHead==SCI_IQTail) && (UART_Flags & SCI_IQDIRTY) ) {
}
SCI_IQ[SCI_IQHead++] = (U8)Uart2ReceiveVal;
if ( SCI_IQHead >= SCI_IQSIZE ) SCI_IQHead = 0;
UART_Flags |= SCI_IQDIRTY;
temploop++;
if (temploop > 0xA024) {
return; ///////// 06/17/03
}
goto uart2comm_start;
}
}
unsigned char UART_Getc( void )
{
unsigned char temp;
U32 tmp;
tmp=*(P_U32)0xFFFFF304;
*(P_U32)0xFFFFF304=0x00FFFFFF;
temp = SCI_IQ[SCI_IQTail];
SCI_IQ[SCI_IQTail]=0;
SCI_IQTail++;
if ( SCI_IQTail >= SCI_IQSIZE ) SCI_IQTail = 0;
if ( SCI_IQTail == SCI_IQHead )
UART_Flags = UART_Flags & (~SCI_IQDIRTY);
*(P_U32)0xFFFFF304=tmp;
return temp;
}
void Uart2SendDataPacket (unsigned char *ptr,unsigned int len ){
U16 Uart2ReceiveVal;
U8 UartDataVal,loop;
U16 UartTxstatus;
U16 i;
U32 n;
U16 j;
U16 temploop;
loop=1;
temploop=0;
while (loop) {
Uart2ReceiveVal=*(P_U16)0xFFFFF914;
UartTxstatus=*(P_U16)0xFFFFF916;
if ( Uart2ReceiveVal & 0x2000 ) { // RDR is full?
RecieveDataFrom_Uart2Register();
} else if ( UartTxstatus & 0x2000) {
if (len >1024 ) return;
n=0;
while (len) {
UartTxstatus=*(P_U16)0xFFFFF916;
Uart2ReceiveVal=*(P_U16)0xFFFFF914;
if ( Uart2ReceiveVal & 0x2000 ) { // RDR is full?
RecieveDataFrom_Uart2Register();
for (j=20000;j>0;j--);
} else if ( UartTxstatus & 0x2000 ) { // TDR is empty?
*(P_U8)0xFFFFF917 = *ptr++;
len--;
} else {
n++;
if (n==0xFFFFF) return;
}
}
loop--;
return;
}
for (i=0x100;i>0;i--);
temploop++;
if ( temploop>1024 ) return;
}
}
void ResetPacketReceiving( void )
{
PacketStatus |= PS_START;
BufferIndex = 0;
}
void ClearSCI_IQ(void )
{
U32 i;
for (i=0;i<SCI_IQSIZE;i++) {
SCI_IQ[i]=0;
}
SCI_IQHead=0;
SCI_IQTail=0;
}
void ClearPacketBuffer(void ){
U16 i;
for (i=0;i<256;i++) {
PacketBuffer[i]=0;
}
}
void UARTRecieveData(void){
U16 i;
U8 ch;
if ((UART_Flags & SCI_IQDIRTY) && ( PacketStatus & PS_START) && (BufferIndex<SCI_IQSIZE)) {
ch=UART_Getc();
/**************************************/
//通讯测试2
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
//数据包格式:BB BB 0A 30 31 32 33 34 35 36 37 38 39 8D 1A
// |----|--|-----------------------------|--|--|
// 包头 命令 数据 校验|包尾
//包头
if (BufferIndex==0) {
if(ch!=0xBB) {
CodeIndex=0;
PacketLength=0;
ResetPacketReceiving();
return;
}
CheckSum=0;
}else if (BufferIndex==1){
if(ch!=0xBB) {
CodeIndex=0;
PacketLength=0;
ResetPacketReceiving();
return;
}
//命令/长度
}else if (BufferIndex==2){
CodeIndex=ch;
PacketLength=ch;
//数据
}else if (BufferIndex>2 && BufferIndex<13) {
PacketBuffer[BufferIndex-3]=ch;
//校验
}else if (BufferIndex==13) {
if (ch==CheckSum) {
ResetPacketReceiving();
PacketStatus |= PS_READY;
return;
} else {
ResetPacketReceiving();
PacketLength=0;
CodeIndex=0;
return;
}
}
CheckSum=CheckSum+ch;
BufferIndex++;
/**************************************************/
}
}
U16 DataPocket(U8 command1,P_U8 addr,U8 command2,P_U8 data)
{
U8 i,l;
U16 j;
U8 tmp;
ASDPacket[0]=command1;
i=0;
l=0;
while (l< 6) {
i++;
ASDPacket[i]=*(P_U8)addr;
addr++;
l++;
}
i++;
ASDPacket[i]=command2;
i++;
tmp=0;
ASDPacket[i]=0xEE;
i++;
tmp=Cal_CRC(ASDPacket,9);
ASDPacket[i]=tmp;
i++;
return i;
}
void Uart_Init(unsigned char com)
{
if (com==2) {
*(P_U16)0xFFFFF910=0xE1BE;
*(P_U8)0xFFFFF916=0xEA;
*(P_U16)0xFFFFF918=0;
*(P_U16)0xFFFFF91C=0x000F;
} else if (com==1) {
*(P_U16)0xFFFFF900=0xE1BE;
*(P_U8)0xFFFFF906=0xEA;
*(P_U16)0xFFFFF908=0;
}
}
STATUS UART_Configure(unsigned char mode,unsigned int baudRate,unsigned parity,unsigned char stopBits,unsigned char charLen, unsigned char com )
{
switch (baudRate) {
case UART_600_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0726;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0726;
}
break;
case UART_1200_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0626;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0626;
}
break;
case UART_2400_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0526;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0526;
}
break;
case UART_4800_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0426;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0426;
}
break;
case UART_9600_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0326;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0326;
}
break;
case UART_19200_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0226;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0226;
}
break;
case UART_38400_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0126;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0126;
}
break;
case UART_76800_BPS :
if (com==2 ) {
*(P_U16)0xFFFFF912=0x0538;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0538;
}
break;
case UART_28800_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0338;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0338;
}
break;
case UART_57600_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0238;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0238;
}
break;
case UART_115200_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0138;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0138;
}
break;
case UART_230400_BPS :
if (com==2) {
*(P_U16)0xFFFFF912=0x0038;
} else if (com==1) {
*(P_U16)0xFFFFF902=0x0038;
}
break;
default :
break;
}
switch (parity) {
case NO_PARITY :
if (com==2) {
*(P_U16)0xFFFFF910 &=0xF7FF;
} else if (com==1) {
*(P_U16)0xFFFFF900 &=0xF7FF;
}
break;
case ODD_PARITY :
if (com==2) {
*(P_U16)0xFFFFF910 |=0x0C00;
} else if (com==1) {
*(P_U16)0xFFFFF900 |=0x0C00;
}
break;
case EVEN_PARITY :
if (com==2) {
*(P_U16)0xFFFFF910 |=0x0800;
*(P_U16)0xFFFFF910 &=0xFBFF;
} else if (com==1) {
*(P_U16)0xFFFFF900 |=0x0800;
*(P_U16)0xFFFFF900 &=0xFBFF;
}
break;
default : break;
}
switch (stopBits) {
case ONE_STOP_BIT :
if (com==2) {
*(P_U16)0xFFFFF910 &=0xFDFF;
} else if (com==1) {
*(P_U16)0xFFFFF900 &=0xFDFF;
}
break;
case TWO_STOP_BIT :
if (com==2) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -