📄 _io.c
字号:
/* this is the _io.c module, all the IO operation is done here. */
/* specification */
/* the system include the following module: */
/* _main.c
_edit.c
_io.c
_rs485.c */
/* define the include file */
#include <reg52.h>
#include "_main.h"
#include "_io.h"
#include "_edit.h"
#include "_accform.h"
#include "_predit.h"
#include "_prmain.h"
/* define the start interface hz form. */
uchar code ADSTART[14]={25,43,9,2,35,0,23,14,12,29,38,24,41,39};
uchar code ADTELCODE[17]={11,12,13,14,0,7,5,5,10,2,6,7,1,2,6,1,2};
/* define the process information form. */
uchar code ADPROINFO[3][6]={
50,35,51,52,53,54, /* wire no or wire knot. */
49,55,56,57,58,49, /* the process finish. */
7,60,61,62,63,64}; /* the cutter sensor damage. */
/* the function declear. */
bit Cutter_Reset();
void Cutter_Movedist(uchar d_dist, bit d_movedirect, bit acckind);
/* Define the module level declarations. */
uchar g_outsw; /* the output switch variable. */
uchar g_pagecnter; /* the screen page change counter. */
uchar g_itemcnter; /* the item counter. */
idata uchar g_keytimer; /* the key pressed timer. */
idata uchar g_systemsta; /* the system status register. */
idata uchar g_thvalue; /* the TH0 value for Timer0. */
idata uchar g_tlvalue; /* the TL0 value for Timer0. */
idata uchar g_onrunflag; /* the system is on process flag. */
idata uchar g_currentradius; /* for wire rad auto detect. */
bit g_keypress; /* the flag of key pressed. */
bit g_alarmflag; /* the system alarm flag. */
bit g_radiusverify; /* the wire radius verify flag. */
bit g_fin_or_troub; /* finish process or have trouble. */
bit g_wireshort; /* the wire short flag. */
bit g_selnumber; /* press number key when sel sta. */
bit g_lamponflag; /* in alarm, show the lamp status. */
/* the program begin here. */
/***************************************************************************
NAME: Init_Io
FUNCTION: This procedure will initialize the Io status
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Init_Io()
{
uint i;
uchar j;
AD_STOPIN = 1; /* key hand signal input enable. */
AD_POSIN = 1; /* the cutter axle position detect signal input enable. */
AD_LAMPIN = 1; /* sensor lamp status signal input enable. */
AD_485TR = CN_RE_EN;/* the MAX487E receive enable. */
IE = 0x00; /* disable all the interrupt. */
ES = 0; /* serial interrupt disable. */
Delay_Set(CN_10ms);
EA = 0; /* interrupt disable. */
g_outsw = CN_MENTOFF; /* initialize the output. */
g_char_ptr = (uchar xdata *)AD_OUTPUT; /* point to the output port. */
*g_char_ptr = g_outsw; /* all the output signal off. */
g_alarmflag = FALSE; /* the current is not the alarm status. */
g_radiusverify = FALSE; /* default not verify the wire radius. */
g_onrunflag = CN_STOPWORK; /* default not the process status. */
g_fin_or_troub = TRUE; /* default the process can finish. */
g_char_ptr = (uchar xdata *)AD_CUMOTOR;
*g_char_ptr = CN_CUTOPENHG; /* cutter motor open ready. */
g_char_ptr = (uchar xdata *)AD_WFMOTOR;
*g_char_ptr = CN_DBMOTDISA; /* front and back motor disable. */
g_keypress = FALSE; /* default, there is no key pressed. */
g_keytimer = 0; /* the key pressed timer is set 0. */
g_pagecnter = 0; /* default is the 0 page. */
g_itemcnter = 8; /* it is not any item highlight. */
g_systemsta = CN_SELSTA; /* the system select status. */
g_uint_ptr = (uint xdata *)AD_PROGCNTER;
i = *g_uint_ptr;
if(i>=CN_PROGTOTAL) /* the system is used first. */
{
for(j=0;j<2;j++)
{
*g_uint_ptr = 0; /* set 0 */
g_uint_ptr++;
}
}
g_char_ptr = (uchar xdata *)AD_MACHNO;
j = *g_char_ptr;
if(j>=CN_MAXMACHNO) /* the system No register overflow */
{
*g_char_ptr = 0;
}
g_char_ptr = (uchar xdata *)AD_TOMACH;
*g_char_ptr = 0; /* default,the to machine No is 0. */
g_uint_ptr = (uint xdata *)AD_STARTTRAN;
for(j=0;j<4;j++)
{
*g_uint_ptr = 0; /* set the start and last value is 0 */
g_uint_ptr++;
}
}
/***************************************************************************
NAME: Process_Refresh
FUNCTION: This procedure will refresh the system flag in process status.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Process_Refresh()
{
AD_STOPIN = 1; /* key hand signal input enable. */
AD_POSIN = 1; /* the cutter axle position detect signal input enable. */
AD_LAMPIN = 1; /* sensor lamp status signal input enable. */
AD_485TR = CN_RE_EN; /* receive enable. */
ES = 0; /* serial interrupt disable. */
PX0 = 0; /* EX_0 low interrupt grade.*/
IT0 = 0; /* EX_0 volatge trigger mode.*/
EX0 = 1; /* EX0 interrupt enable. */
PT0 = 1; /* Timer0 high interrupt grade. */
ET0 = 1; /* Timer0 Interruption enabled. */
ET1 = 0; /* Timer1 interrupt disable. */
TR1 = 0; /* stop the Timer1. */
EA = 1;
}
/***************************************************************************
NAME: Init_Timer0
FUNCTION: This procedure will initialize the Timer0
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Init_Timer0()
{
TMOD = 0x21; /* Choose mode 1 for Timer0. */
PT0 = 1; /* Timer0 high interrupt grade. */
ET0 = 1; /* Timer0 Interruption enabled. */
EA = 1; /* CPU Interruption enabled. */
TR0 = 0; /* stop Timer0. */
}
/***************************************************************************
NAME: Init_EX0
FUNCTION: This procedure will initialize the EX0 interrupt.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Init_EX0()
{
PX0 = 0; /* EX_0 low interrupt grade. */
IT0 = 0; /* EX_0 volatge trigger mode. */
EX0 = 0; /* close EX_0 interrupt. */
IE0 = 0; /* clear the EX0 interrupt apply_flag. */
}
/***************************************************************************
NAME: Disable_Timer0
FUNCTION: This procedure will disable the Timer0
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Disable_Timer0()
{
TMOD = 0x21; /* Choose mode 1 for Timer0. */
PT0 = 1; /* Timer0 high interrupt grade. */
ET0 = 0; /* Timer0 Interruption disabled. */
EA = 1; /* CPU Interruption enabled. */
TR0 = 0; /* stop Timer0. */
}
/***************************************************************************
NAME: Cr_Inst_Data
FUNCTION: This procedure write instrument or data to the crystal screen.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Cr_Inst_Data( bit flag, uchar indata )
{
uchar i;
uchar xdata *d_crystptr;
AD_CR_RS = flag; /* select data or instrument. */
AD_CR_E = 1;
AD_CR_RW = CN_CR_WR; /* write enable. */
d_crystptr = (uchar xdata *)AD_CRYSTAL; /* point to the crystal screen. */
*d_crystptr = indata;
i = 1; /* delay */
AD_CR_E = 0;
i = 2; /* delay */
AD_CR_RW = CN_CR_RD; /* read enable. */
}
/***************************************************************************
NAME: Show_Crystal
FUNCTION: This procedure show the crystal screen.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Show_Crystal()
{
bit flag;
uchar indata;
flag = CN_CR_IN; /* crystal instrument input. */
indata = CN_CRSHON; /* show the crystal screen. */
AD_CR_A2 = 0; AD_CR_A1 = 0;
Cr_Inst_Data(flag,indata); /* the 1st segment show on. */
AD_CR_A2 = 0; AD_CR_A1 = 1;
Cr_Inst_Data(flag,indata); /* the 2nd segment show on. */
AD_CR_A2 = 1; AD_CR_A1 = 0;
Cr_Inst_Data(flag,indata); /* the 3rd segment show on. */
}
/***************************************************************************
NAME: Init_Crystal
FUNCTION: This procedure initialize the crystal screen.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Init_Crystal()
{
bit flag;
uchar indata;
uchar i,j,k;
/* the display RAM0 is the first line. */
flag = CN_CR_IN;
indata = 0x0C0;
AD_CR_A2 = 0; AD_CR_A1 = 0;
Cr_Inst_Data(flag,indata);
AD_CR_A2 = 0; AD_CR_A1 = 1;
Cr_Inst_Data(flag,indata);
AD_CR_A2 = 1; AD_CR_A1 = 0;
Cr_Inst_Data(flag,indata);
/* all the unit write 0x00 */
for(i=0;i<8;i++)
{
for(j=0;j<3;j++)
{
if(0==j)
{AD_CR_A2 = 0; AD_CR_A1 = 0;}
else if(1==j)
{AD_CR_A2 = 0; AD_CR_A1 = 1;}
else if(2==j)
{AD_CR_A2 = 1; AD_CR_A1 = 0;}
flag = CN_CR_IN;
indata = CN_CR_XSTA+i;
Cr_Inst_Data(flag,indata); /* the X start address. */
indata = CN_CR_YSTA;
Cr_Inst_Data(flag,indata); /* the Y start address. */
Reset_Watchdog();
for(k=0;k<64;k++)
{
flag = CN_CR_DA;
indata = 0x00; /* show the all white. */
Cr_Inst_Data(flag,indata);
}
}
}
Show_Crystal();
}
/***************************************************************************
NAME: Start_Interface
FUNCTION: This procedure will show the start interface.
INPUTS: NONE
OUTPUTS: NONE
***************************************************************************/
void Start_Interface()
{
bit flag;
uchar indata;
uchar x,y;
uchar i,j,n;
uchar code *d_hzptr;
for(i=0;i<14;i++) /* the start interface have 14 hz. */
{
Reset_Watchdog();
if(0==i || 8==i)
{
if(0==i)
{ x=1; y=32; } /* the 1st line,the 1st hz. */
else {x=4; y=48;} /* the 2nd line,the 1st hz. */
j = 0;
AD_CR_A2 = 0; AD_CR_A1 = 0;
flag = CN_CR_IN;
indata = CN_CR_XSTA+x;
Cr_Inst_Data(flag,indata); /* write the x start address. */
indata = CN_CR_YSTA+y;
Cr_Inst_Data(flag,indata); /* write the y start address. */
}
d_hzptr=&ADHZLIB[(uint)(ADSTART[i])*32]; /* get the hz offset address. */
for(n=0;n<32;)
{
flag = CN_CR_DA;
indata = *d_hzptr;
Cr_Inst_Data(flag,indata); /* write the hz dot array */
d_hzptr++;
n++;
if(16==n)
{
x++;
flag = CN_CR_IN;
indata = CN_CR_XSTA+x;
Cr_Inst_Data(flag,indata);
indata = CN_CR_YSTA+y;
Cr_Inst_Data(flag,indata);
}
}
x--;
y=y+16;
if(y>=64)
{
y=0;
j++;
if(1==j)
{AD_CR_A2 = 0; AD_CR_A1 = 1;}
else if(2==j)
{AD_CR_A2 = 1; AD_CR_A1 = 0;}
}
flag = CN_CR_IN;
indata = CN_CR_XSTA+x;
Cr_Inst_Data(flag,indata);
indata = CN_CR_YSTA+y;
Cr_Inst_Data(flag,indata);
}
/* the following show the telephone code. */
AD_CR_A2 = 0; AD_CR_A1 = 0;
flag = CN_CR_IN;
indata = CN_CR_XSTA+7;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -