Приложение 1. Основная программа.
#include <8051.h>
#include <intrpt.h>
#include <float.h>
/* 206 => 0x61 207 => 0xE1 271=>9D */
const int speed=172; /* это должно быть 200 */
const int test_speed=2; /* 0.5==2 */
static int a @ 0x18;
/* static int flag @ 0x18;*/
/* static int flag1 @ 0x1a;*/
static bit unsigned char Usvic_Ok @ 0x50;
static bit unsigned char PK_Vpr @ 0x51;
static bit unsigned char Vpr_Ok @ 0x52;
static bit unsigned char Vmd_Ok @ 0x53;
static bit unsigned char PO_Ok @ 0x54;
/*--- номер выводимого параметра 0=Sl206,1=Sl207,2=Sl271 -*/
static unsigned char NomParam @ 0x1c;
static unsigned char BaitV @ 0x2a;
/*------------Выходное слово SlVmd 206 ------------------*/
static unsigned long SlVmd @ 0x10;
static unsigned char SlVmd_1 @ 0x10;
static unsigned char SlVmd_2 @ 0x11;
static unsigned char SlVmd_3 @ 0x12;
static unsigned char SlVmd_4 @ 0x13;
/*------------Выходное слово SlVpr 207 -------------------*/
static unsigned long SlVpr @ 0x3c;
static unsigned char SlVpr_1 @ 0x3c;
static unsigned char SlVpr_2 @ 0x3d;
static unsigned char SlVpr_3 @ 0x3e;
static unsigned char SlVpr_4 @ 0x3f;
/*------------Выходное слово SlDs 271 --------------------*/
static unsigned long SlDs @ 0x38;
static unsigned char SlDs_1 @ 0x38;
static unsigned char SlDs_2 @ 0x39;
static unsigned char SlDs_3 @ 0x3a;
static unsigned char SlDs_4 @ 0x3b;
/*------------Выходное слово для ЦАП CapSlowo -------------*/
static unsigned int CapSlowo @ 0x28;
static unsigned char CapSlowo0 @ 0x28;
static unsigned char CapSlowo1 @ 0x29;
/*------- Рабочая область стеков ------------------*/
/* static unsigned long Stec @ 0x28;*/
static bit unsigned char Test_Pr @ 0x40;
/*--------- Сохранение переведенных скоростей ----------------*/
static unsigned int StecVprd @ 0x30;
static unsigned int StecVmdd @ 0x32;
/*--------- Int вводимых скорости ----------------------------*/
static unsigned int Vprg @ 0x20;
static unsigned int Vmdg @ 0x24;
/*--------- Int переведенных скорости ------------------------*/
static unsigned int Vprd @ 0x22;
static unsigned int Vmdd @ 0x26;
/*------- Рабочее слово SlRab -------------------------*/
static unsigned long SlRab @ 0x2c;
static unsigned char SlRab_4 @ 0x2c;
static unsigned char SlRab_3 @ 0x2d;
static unsigned char SlRab_2 @ 0x2e;
static unsigned char SlRab_1 @ 0x2f;
static unsigned char Adress @ 0x2f;/* адреса (206/207/271)*/
static bit unsigned char SlRab_bit31 @ 0x67;
static bit unsigned char SlRab_bit30 @ 0x66;
static bit unsigned char SlRab_bit29 @ 0x65;
static bit unsigned char SlRab_bit28 @ 0x64;
static bit unsigned char SlRab_bit27 @ 0x63;
static bit unsigned char SlRab_bit26 @ 0x62;
static bit unsigned char SlRab_bit25 @ 0x61;
static bit unsigned char SlRab_bit24 @ 0x60;
static bit unsigned char SlRab_bit23 @ 0x6f;
static bit unsigned char SlRab_bit22 @ 0x6e;
static bit unsigned char SlRab_bit21 @ 0x6d;
static bit unsigned char SlRab_bit20 @ 0x6c;
static bit unsigned char SlRab_bit19 @ 0x6b;
static bit unsigned char SlRab_bit18 @ 0x6a;
static bit unsigned char SlRab_bit17 @ 0x69;
static bit unsigned char SlRab_bit16 @ 0x68;
static bit unsigned char SlRab_bit15 @ 0x77;
static bit unsigned char SlRab_bit14 @ 0x76;
static bit unsigned char SlRab_bit13 @ 0x75;
static bit unsigned char SlRab_bit12 @ 0x74;
static bit unsigned char SlRab_bit11 @ 0x73;
static bit unsigned char SlRab_bit10 @ 0x72;
static bit unsigned char SlRab_bit9 @ 0x71;
static bit unsigned char SlRab_bit8 @ 0x70;
static bit unsigned char SlRab_bit7 @ 0x7f;
static bit unsigned char SlRab_bit6 @ 0x7e;
static bit unsigned char SlRab_bit5 @ 0x7d;
static bit unsigned char SlRab_bit4 @ 0x7c;
static bit unsigned char SlRab_bit3 @ 0x7b;
static bit unsigned char SlRab_bit2 @ 0x7a;
static bit unsigned char SlRab_bit1 @ 0x79;
static bit unsigned char SlRab_bit0 @ 0x78;
/*-- Входные битовые Скорость Vpr Grey -----------------------*/
static bit unsigned char Vprg_bit9 @ 0x01;
static bit unsigned char Vprg_bit8 @ 0x00;
static bit unsigned char Vprg_bit7 @ 0x0f;
static bit unsigned char Vprg_bit6 @ 0x0e;
static bit unsigned char Vprg_bit5 @ 0x0d;
static bit unsigned char Vprg_bit4 @ 0x0c;
static bit unsigned char Vprg_bit3 @ 0x0b;
static bit unsigned char Vprg_bit2 @ 0x0a;
static bit unsigned char Vprg_bit1 @ 0x09;
static bit unsigned char Vprg_bit0 @ 0x08;
/*-- Выходные битовые Скорость Vpr Din -----------------------*/
static bit unsigned char Vprd_bit9 @ 0x11;
static bit unsigned char Vprd_bit8 @ 0x10;
static bit unsigned char Vprd_bit7 @ 0x1f;
static bit unsigned char Vprd_bit6 @ 0x1e;
static bit unsigned char Vprd_bit5 @ 0x1d;
static bit unsigned char Vprd_bit4 @ 0x1c;
static bit unsigned char Vprd_bit3 @ 0x1b;
static bit unsigned char Vprd_bit2 @ 0x1a;
static bit unsigned char Vprd_bit1 @ 0x19;
static bit unsigned char Vprd_bit0 @ 0x18;
/*-- Входные битовые Скорость Vmd Grey -----------------------*/
static bit unsigned char Vmdg_bit9 @ 0x21;
static bit unsigned char Vmdg_bit8 @ 0x20;
static bit unsigned char Vmdg_bit7 @ 0x2f;
static bit unsigned char Vmdg_bit6 @ 0x2e;
static bit unsigned char Vmdg_bit5 @ 0x2d;
static bit unsigned char Vmdg_bit4 @ 0x2c;
static bit unsigned char Vmdg_bit3 @ 0x2b;
static bit unsigned char Vmdg_bit2 @ 0x2a;
static bit unsigned char Vmdg_bit1 @ 0x29;
static bit unsigned char Vmdg_bit0 @ 0x28;
/*-- Выходные битовые Скорость Vmd Din -----------------------*/
static bit unsigned char Vmdd_bit9 @ 0x31;
static bit unsigned char Vmdd_bit8 @ 0x30;
static bit unsigned char Vmdd_bit7 @ 0x3f;
static bit unsigned char Vmdd_bit6 @ 0x3e;
static bit unsigned char Vmdd_bit5 @ 0x3d;
static bit unsigned char Vmdd_bit4 @ 0x3c;
static bit unsigned char Vmdd_bit3 @ 0x3b;
static bit unsigned char Vmdd_bit2 @ 0x3a;
static bit unsigned char Vmdd_bit1 @ 0x39;
static bit unsigned char Vmdd_bit0 @ 0x38;
/*------------------------------------------------------------------------*/
/* Процедура записи бита четности для SlRab */
/*------------------------------------------------------------------------*/
void CalcChetSl(void){
SlRab_bit31=1;
SlRab_bit31=SlRab_bit31^SlRab_bit0^SlRab_bit1^SlRab_bit2;
SlRab_bit31=SlRab_bit31^SlRab_bit3^SlRab_bit4^SlRab_bit5;
SlRab_bit31=SlRab_bit31^SlRab_bit6^SlRab_bit7^SlRab_bit8;
SlRab_bit31=SlRab_bit31^SlRab_bit9^SlRab_bit10^SlRab_bit11;
SlRab_bit31=SlRab_bit31^SlRab_bit12^SlRab_bit13^SlRab_bit14;
SlRab_bit31=SlRab_bit31^SlRab_bit15^SlRab_bit16^SlRab_bit17;
SlRab_bit31=SlRab_bit31^SlRab_bit18^SlRab_bit19^SlRab_bit20;
SlRab_bit31=SlRab_bit31^SlRab_bit21^SlRab_bit22^SlRab_bit23;
SlRab_bit31=SlRab_bit31^SlRab_bit24^SlRab_bit25^SlRab_bit26;
SlRab_bit31=SlRab_bit31^SlRab_bit27^SlRab_bit28^SlRab_bit29;
SlRab_bit31=SlRab_bit31^SlRab_bit30;
}
/*------------------------------------------------------------------------*/
/* Процедура перевода из грея в двоичную допустимую скорость */
/*------------------------------------------------------------------------*/
void Perevod_Md(void){
Vmdd=0;
Vmdd_bit9=Vmdg_bit9;
Vmdd_bit8=Vmdg_bit8^Vmdd_bit9;
Vmdd_bit7=Vmdg_bit7^Vmdd_bit8;
Vmdd_bit6=Vmdg_bit6^Vmdd_bit7;
Vmdd_bit5=Vmdg_bit5^Vmdd_bit6;
Vmdd_bit4=Vmdg_bit4^Vmdd_bit5;
Vmdd_bit3=Vmdg_bit3^Vmdd_bit4;
Vmdd_bit2=Vmdg_bit2^Vmdd_bit3;
Vmdd_bit1=Vmdg_bit1^Vmdd_bit2;
Vmdd_bit0=Vmdg_bit0^Vmdd_bit1;
}
/*------------------------------------------------------------------------*/
/* Процедура перевода из грея в двоичную предельную скорость */
/*------------------------------------------------------------------------*/
void Perevod_Pr(void){
Vprd=0;
Vprd_bit9=Vprg_bit9;
Vprd_bit8=Vprg_bit8^Vprd_bit9;
Vprd_bit7=Vprg_bit7^Vprd_bit8;
Vprd_bit6=Vprg_bit6^Vprd_bit7;
Vprd_bit5=Vprg_bit5^Vprd_bit6;
Vprd_bit4=Vprg_bit4^Vprd_bit5;
Vprd_bit3=Vprg_bit3^Vprd_bit4;
Vprd_bit2=Vprg_bit2^Vprd_bit3;
Vprd_bit1=Vprg_bit1^Vprd_bit2;
Vprd_bit0=Vprg_bit0^Vprd_bit1;
}
/*------------------------------------------------------------------------*/
/* Процедура расстановки состояний */
/*------------------------------------------------------------------------*/
void Priznak_Work(bit unsigned char a,bit unsigned char b){
SlRab_bit30=a;
SlRab_bit29=b;
}
/*------------------------------------------------------------------------*/
/* Процедура расстановки идентифткатора */
/*------------------------------------------------------------------------*/
void Priznak_Usvic(viod){
SlRab_bit8=0;/* Признак */
SlRab_bit9=1;/* от УСВИЦ-250 */
}
/*------------------------------------------------------------------------*/
/* Процедура имтация входных данных */
/*------------------------------------------------------------------------*/
void ImVxodMd(void){
Vmdg=344;
}
/*------------------------------------------------------------------------*/
/* Процедура имтация входных данных */
/*------------------------------------------------------------------------*/
void ImVxodPr(void){
Vprg=172;
}
/*------------------------------------------------------------------------*/
/* Процедура проверки на отказ Vmd */
/*------------------------------------------------------------------------*/
void Cikl_Otkaz_Vmd(void){
int c=3,St;
Vmd_Ok=0;
T1=0;
do
{
/* vvodvmd();*/
ImVxodMd(); /* имитация входа */
Perevod_Md();/* перевод из грея в двоичную */
St=StecVmdd;
if ((St+test_speed>Vmdd)&&(St-test_speed<Vmdd))
{
StecVmdd=Vmdd;
break;
}
if (c==0)
{
Vmd_Ok=1;
T1=1;
break;
}
c--;
}
while(c>(-1));
}
/*------------------------------------------------------------------------*/
/* Процедура проверки на отказ Vpr */
/*------------------------------------------------------------------------*/
void Cikl_Otkaz_Vpr(void){
int b=3,St;
Vpr_Ok=0;
RXD=0;
do
{
/* vvodvpr(); */
ImVxodPr(); /* имитация входа */
Perevod_Pr();/* перевод из грея в двоичную */
St=StecVprd;
if ((St+test_speed>Vprd)&&(St-test_speed<Vprd))
{
StecVprd=Vprd;
break;
}
if (b==0)
{
Vpr_Ok=1;
RXD=1;
break;
}
b--;
}
while(b>(-1));
}
/*------------------------------------------------------------------------*/
/* Процедура маштабирование для ЦАП с соответствием 1==0.63 */
/*------------------------------------------------------------------------*/
void Machtab(unsigned int V1){
double rab1;
rab1=(double)V1;
rab1*=0.63;
CapSlowo=0;
CapSlowo=(unsigned int)rab1;
CapSlowo0<<=6;
}
/*------------------------------------------------------------------------*/
/* Процедура формирование слова с соответствием с РТМ */
/*------------------------------------------------------------------------*/
void FormPTM(unsigned int V1){
double rab2;
SlRab=0;
rab2=(double)V1;
rab2/=0.11575;
SlRab=(unsigned long)rab2;
rab2-=(double)SlRab;
if (rab2>0.5) SlRab++;
SlRab<<=12;
}
/*------------------------------------------------------------------------*/
/* Процедура тест контроля ПО */
/*------------------------------------------------------------------------*/
void TestControlPO(void){
int Vprd1=0,Vmdd1=0,Vprg1=0,Vmdg1=0;
PO_Ok=Vmd_Ok=Vpr_Ok=0;
Vprg1=Vprg; /* сохраняем Vprg */
Vmdg1=Vmdg; /* сохраняем Vmdg */
Vprd1=Vprd; /* сохраняем Vprd */
Vmdd1=Vmdd; /* сохраняем Vmdd */
Vmdg=Vprg=speed;
Perevod_Md();
Perevod_Pr();
if (Vmdd!=200) { PO_Ok=1; Vmd_Ok=1; }
if (Vprd!=200) { PO_Ok=1; Vpr_Ok=1; }
/*----------------------------- 206 --------------------------------------*/
SlRab=0;
FormPTM(Vprd);
Adress=0x61;
Priznak_Usvic();/* признак от УСВИЦ-250 */
Priznak_Work(1,0);/* признак тест */
CalcChetSl();/* Подсчет четности */
if(SlRab!=1080820321) { PO_Ok=1; Vpr_Ok=1; }
/*----------------------------- 207 --------------------------------------*/
SlRab=0;
FormPTM(Vmdd);
Adress=0xe1;
Priznak_Usvic();/* признак от УСВИЦ-250 */
Priznak_Work(1,0);/* признак тест */
CalcChetSl();/* Подсчет четности */
if(SlRab!=3228304097) { PO_Ok=1; Vmd_Ok=1; }
SlRab=0;
/*------------------- востанавливаем состояния --------------------------*/
Vprg=Vprg1; /* востанавливаем Vprg */
Vmdg=Vmdg1; /* востанавливаем Vmdg */
Vprd=Vprd1; /* востанавливаем Vprd */
Vmdd=Vmdd1; /* востанавливаем Vmdd */
}
/*------------------------------------------------------------------------*/
/* Процедура проверки скорости < 50км(200), => - нет вычисленных данных */
/*------------------------------------------------------------------------*/
void If_Speed(unsigned int V){
if(V<200) Priznak_Work(0,1); /* признак нет вычисленных данных */
}
/*------------------------------------------------------------------------*/
/* Запуск таймера */
/*------------------------------------------------------------------------*/
void Zapusk(void){
/*---------- Чистка рабочих областей параметров--------------*/
SlRab=0;NomParam=0;
/*------------- Запуск таймера --------------------------*/
asm(" mov TCON,#1 ");
asm(" anl IP,#0 ");
asm(" orl IP,#2 ");
asm(" mov TMOD,#01 ");
asm(" mov a,#0eah "); /* число для загрузки таймера */
asm(" mov TH0,a "); /* 65536-20*36-685+67, где старшая часть */
asm(" mov a,#0d3h "); /* равна eah, а младшая - d3h */
asm(" mov TL0,a ");
asm(" setb TCON.4 ");
asm(" anl IE,#0 ");
asm(" orl IE,#82h ");
}
/*------------------------------------------------------------------------*/
/* Процедура растановки признаков проверок */
/*------------------------------------------------------------------------*/
void Priznak_Test(void){
if((PK_Vpr==0) && (Vpr_Ok==0) && (Vmd_Ok==0) && (PO_Ok==0))
SlRab_bit28=0;
else SlRab_bit28=1;
SlRab_bit27=PK_Vpr;
SlRab_bit26=Vpr_Ok;
SlRab_bit25=Vmd_Ok;
SlRab_bit24=PO_Ok;
}
/*------------------------------------------------------------------------*/
/* Процедура разовой команды ТЕСТ КОНТРОЛЬ */
/*------------------------------------------------------------------------*/
void Test_Kontrol(void){