Подключение датчика SSI

Конструктор
Offline
Зарегистрирован: 02.01.2017

Всем привет!

По работе возникла необходимость подключиться к датчику - угловому энкодеру с выходом SSI, только не с токовыми петлями (интерфейс RS-422), а с уровнями ТТЛ CLOCK и DATA.

Датчик был еле живой, а осциллограф почти мёртвый, поэтому предложенные на форуме решения с переключениями линии порта и delaymicroseconds особого результата не дали.

В итоге подключил датчик к порту SPI (CLOCK на CLK, а DATA на MISO). В "помощнике" CodeVision указал режим работы интерфейса SPI (в том числе частоту обмена). После подбора режима (два бита в регистре настройки) датчик стал стабильно откликаться. Правда сигнал DATA с датчика был слабоват по амплитуде, его пришлось пропустить через транзисторный ключ.

Длина слова с датчика была 12 бит, потому организовал два считывания подряд - всё прекрасно заработало.

Если будет интересно принесу с работы и выложу сюда программку.

 

Конструктор
Offline
Зарегистрирован: 02.01.2017
Выкладываю код (черновой вариант - много лишнего закоментировано).

Модуль main.c

/*******************************************************
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
© Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 09.02.2018
Author  : 
Company : 
Comments: 


Chip type               : ATmega328P
Program type            : Application
AVR Core Clock frequency: 16,000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*******************************************************/

#include <mega328p.h>
#include <UART.c>
// SPI functions
#include <spi.h>

// Declare your global variables here


#define NOP10   #asm("NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP")
#define NOP20   NOP10
#define NOP30   NOP10 NOP10 NOP10
#define NOP40   NOP20 NOP20
#define NOP50   NOP20 NOP20 NOP10
#define DelayHigh NOP50 NOP50 NOP50
#define DelayLow  NOP50 NOP50
//#define ClockHigh PORTB = PORTB | 0b00000001; NOP50 *TempAdr = PINB; TempAdr++;
//#define ClockLow  PORTB = PORTB & 0b11111110; NOP50  NOP30

#define ClockHigh PORTB = PORTB | 0b00000001; DelayHigh  
#define ClockLow  PORTB = PORTB & 0b11111110; *TempAdr = PINB; TempAdr++; DelayLow  


#define ClockTime ClockLow ClockHigh

char InputData[20];

// Standard Input/Output functions
//#include <stdio.h>


char ReadLineSSI(char *TempPointer)
{

char *TempAdr;
TempAdr = TempPointer;

    #asm("cli")           // Запрет прерываний


ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime

ClockTime
ClockTime
ClockTime
ClockTime
ClockTime
ClockTime

PORTB = PORTB | 0b00000001; // Возврат линии в ожидание

return 'Y';
}

char TestSub(char *InDat)
{

 char *TempAdr;
 TempAdr = InDat;
 
 *TempAdr = 'S';
 TempAdr++;
 *TempAdr = 'D';

#asm("sei")          // Разрешение прерываний

 return 'Y';

}


void main(void)
{
// Declare your local variables here
int TempInt;
char Byte1;
char Byte2;


// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=(1<<CLKPCE);
CLKPR=(0<<CLKPCE) | (0<<CLKPS3) | (0<<CLKPS2) | (0<<CLKPS1) | (0<<CLKPS0);
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Function: Bit7=In Bit6=In Bit5=Out Bit4=In Bit3=Out Bit2=Out Bit1=In Bit0=In 
DDRB=(0<<DDB7) | (0<<DDB6) | (1<<DDB5) | (0<<DDB4) | (1<<DDB3) | (1<<DDB2) | (0<<DDB1) | (0<<DDB0);
// State: Bit7=T Bit6=T Bit5=0 Bit4=T Bit3=0 Bit2=0 Bit1=T Bit0=T 
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Port C initialization
// Function: Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
DDRC=(0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
// State: Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
PORTC=(0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

// Port D initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (0<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (0<<WGM00);
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (0<<CS00);
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Disconnected
// OC1B output: Disconnected
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=(0<<EXCLK) | (0<<AS2);
TCCR2A=(0<<COM2A1) | (0<<COM2A0) | (0<<COM2B1) | (0<<COM2B0) | (0<<WGM21) | (0<<WGM20);
TCCR2B=(0<<WGM22) | (0<<CS22) | (0<<CS21) | (0<<CS20);
TCNT2=0x00;
OCR2A=0x00;
OCR2B=0x00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (0<<TOIE0);

// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=(0<<ICIE1) | (0<<OCIE1B) | (0<<OCIE1A) | (0<<TOIE1);

// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=(0<<OCIE2B) | (0<<OCIE2A) | (0<<TOIE2);

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: Off
// Interrupt on any change on pins PCINT16-23: Off
EICRA=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
EIMSK=(0<<INT1) | (0<<INT0);
PCICR=(0<<PCIE2) | (0<<PCIE1) | (0<<PCIE0);

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART0 Mode: Asynchronous
// USART Baud Rate: 9600
UCSR0A=(0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (0<<UPE0) | (0<<U2X0) | (0<<MPCM0);
UCSR0B=(0<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (1<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80);
UCSR0C=(0<<UMSEL01) | (0<<UMSEL00) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0);
UBRR0H=0x00;
UBRR0L=0x67;

// Analog Comparator initialization
// Analog Comparator: Off
// The Analog Comparator's positive input is
// connected to the AIN0 pin
// The Analog Comparator's negative input is
// connected to the AIN1 pin
ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
ADCSRB=(0<<ACME);
// Digital input buffer on AIN0: On
// Digital input buffer on AIN1: On
DIDR1=(0<<AIN0D) | (0<<AIN1D);

// ADC initialization
// ADC disabled
ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);




// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 125,000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=(0<<SPIE) | (1<<SPE) | (0<<DORD) | (1<<MSTR) | (1<<CPOL) | (1<<CPHA) | (1<<SPR1) | (1<<SPR0);
SPSR=(0<<SPI2X);

/*
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 4000,000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=(0<<SPIE) | (1<<SPE) | (0<<DORD) | (1<<MSTR) | (0<<CPOL) | (1<<CPHA) | (0<<SPR1) | (0<<SPR0);
SPSR=(0<<SPI2X);

*/

/*
 // SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250,000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=(0<<SPIE) | (1<<SPE) | (0<<DORD) | (1<<MSTR) | (0<<CPOL) | (0<<CPHA) | (1<<SPR1) | (0<<SPR0);
SPSR=(0<<SPI2X);
*/

// TWI initialization
// TWI disabled
TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);


while (1)
      {
      // Place your code here
            SendSign(10);
//            SendSign(13);             
            SendSign('B');
            SendSign('E');
            SendSign('G');
            SendSign('I');
            SendSign('N');
            SendSign(':');
            SendSign(' ');
            
            
              
//            InputData[0] = 'a';
//            InputData[1] = 'b';
           
//            SendSign(InputData[0]);
//            SendSign(InputData[1]);           
           
//            ReadData();
//           SendSign('Q');
//           SendByte(143);
//           SendTwoByte(12345);
            
//            TestSub(InputData);

/*
            for(TempInt=0; TempInt<=20; TempInt++)
            {
                InputData[TempInt] = 0;
            }
*/

/*            
            ReadLineSSI(InputData);
            
            for(TempInt=0; TempInt<=19; TempInt++)
            {
                InputData[TempInt] = InputData[TempInt] & 0b00000010;
                SendSign(InputData[TempInt] + 0x30);    
            }
*/


/* Start transmission */
//SPDR = cData;
SPDR = 0b01010101;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
;

            Byte1=SPDR;


            SPDR = 0b01010101;
// Wait for transmission complete 
while(!(SPSR & (1<<SPIF)))
;
//            Byte2=SPDR;
            
            
            
            SendByte(Byte1);
//            SendByte(Byte2);


            SendByte(SPDR);
            
            
            
//            DelayHigh
            
//            SendSign('E');
//            SendSign(InputData[0]);
//            SendSign(InputData[1]);
            Delay(2);   

      }
}

 

 

Конструктор
Offline
Зарегистрирован: 02.01.2017
Модуль UART.c

/*******************************************************
Модуль приёма-передачи данных по UART для отладки
*******************************************************/

void Delay(char DelayCount)
{
int i;
int y;
         
for (y = 0;y < DelayCount; y++)
    {
       for (i=0;i<20000;i++)
        {
        i++;
        i--;
        };
    };
};

void SendSign(char SendingSign)
{
//    while (    USART_Flag==0)
//    {}
//    
//    USART_Flag=0;
    
    
//    while ( !( UCSR0A & (1<<UDRE0)) );
    while ( !( UCSR0A & 0b00100000) ) 
    ;
    UDR0 = SendingSign;
}

void SendByte(char SendingByte)
{
 char Sign1;
 char Sign2;
 char Temp;
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign1 = Temp - 10*SendingByte;
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign2 = Temp - 10*SendingByte;
 
 SendSign(SendingByte+0x30);
 SendSign(Sign2+0x30);
 SendSign(Sign1+0x30);
 SendSign(10);
 SendSign(13);   
}



void SendTwoByteBin(unsigned int SendingByte)
{
 char SendBit[16];
 int i;
 unsigned int Temp;
  
  
//  SendSign(0x23);
//i=5;
//SendSign(i+0x30);
 
  SendSign(0x23);
 
     for (i = 0; i <= 15; i++) 
     {
//        SendSign(0x23);
//        SendSign(i+0x30);
//        SendSign(0x3D);
        Temp = SendingByte;
        SendingByte = SendingByte/2;
        SendBit[i]=Temp-2*SendingByte; 
//        SendSign(SendBit[i]+0x30);
     };

//  SendSign(0x23);


//  SendSign(13);

      for (Temp = 0; Temp < 32000; Temp++) 
     {
        Temp++;
        Temp--;
     };

 
// SendSign(10);
// SendSign(13);
//  SendSign(13);
  
  
        for (i = 15; i >=0; i--) 
     {
        SendSign(SendBit[i]+0x30);
     };

 SendSign(10);
 SendSign(13);

     
}


 void SendTwoByte(unsigned int SendingByte)
{
 char Sign1;
 char Sign2;
 char Sign3;
 char Sign4;
 unsigned int Temp;
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign1 = Temp - 10*SendingByte;
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign2 = Temp - 10*SendingByte;
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign3 = Temp - 10*SendingByte; 
 
 Temp = SendingByte;
 SendingByte = SendingByte/10;
 Sign4 = Temp - 10*SendingByte;
 
 SendSign(SendingByte+0x30);
 SendSign(Sign4+0x30);
 SendSign(Sign3+0x30);
 SendSign(Sign2+0x30);
 SendSign(Sign1+0x30);
 SendSign(10);
 SendSign(13);   
}


//void TestTable(void)
//{
//    int i;
//    char Temp;
//     
//    for (i=0; i<8; i++)
//    {
//        SendSign(0x23);
//        SendSign(i+0x30);
//        SendSign(0x3D);
//        Temp=CodeTable[i];
//        SendSign(Temp+0x30);
//        
//        SendSign(10);
//        SendSign(13); 
//    };
//
//}


char USART_Receive_Char( void )
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) )
;
/* Get and return received data from buffer */
return UDR0;
}


//int USART_Receive_Code( void )
//{
//    unsigned int TempNum = 0;
//    char TempChar;
//    
//    do
//    {
//        TempChar = USART_Receive_Char();
//        if (TempChar >= 0x30 & TempChar <= 0x39)
//        {
//            TempNum = TempNum * 10 +  TempChar - 0x30;
//         };     
//    
//    }
//while (TempChar != 10);
//}


//void SendString(int InputString)
//{
//
////char *CurrentString = InputString;
//
////char MyStr = InputString;
//SendSign(InputString);
//SendSign(InputString +2 );
//
//}

void SendInputData(void)
{

char *str = "abc";
//*str = "tes";

char Test[20];
//*Test="trd";

//SendString(*str);

//char s1[100];
//puts("drt");
//gets(s1);
//String TXD_String = "27IN.01";

//char TXD_String[] = "27IN.01";
//TXD_String[] = "27IN.01";
//SendString(TXD_String);
//SendString("27IN.01");

}



void TestSendString(char *Temp)
{

char *TempAdr;



SendSign(*Temp);

SendSign(10);
SendSign(13); 

TempAdr = Temp;
SendSign(*TempAdr);
TempAdr++;
SendSign(*TempAdr);
TempAdr++;
SendSign(*TempAdr);
TempAdr++;
SendSign(*TempAdr);
TempAdr++;
SendSign(*TempAdr);



}

void SendString(char *Temp, int CurrentValue)
{

//char FullChar[] = *Temp;
char *TempAdr;
char TempChar;
int i;



//SendSign(*Temp);

//SendSign(10);
//SendSign(13); 

TempAdr = Temp;
TempChar = *TempAdr;

//i = strlen ("ddf");

//do  {
//SendSign(*TempAdr);
//TempAdr++;
//
//    }
//while (*TempAdr != "#");

//for (i=0;i<4;i++)
//{
//SendSign(*TempAdr);
//TempAdr++;
//
//}; 


while (TempChar != 0) 
{
SendSign(TempChar);
TempAdr++;
TempChar = *TempAdr;
};

SendSign(' ');
SendSign('=');
SendSign(' ');
SendSign(CurrentValue + 48);
//SendSign(10);


}


//void TestCall(void)
//{
//
//TestSendString("sbls");
//}

 void SendStringOnly(char *Temp)
{

//char FullChar[] = *Temp;
char *TempAdr;
char TempChar;
int i;



//SendSign(*Temp);

//SendSign(10);
//SendSign(13); 

TempAdr = Temp;
TempChar = *TempAdr;

//i = strlen ("ddf");

//do  {
//SendSign(*TempAdr);
//TempAdr++;
//
//    }
//while (*TempAdr != "#");

//for (i=0;i<4;i++)
//{
//SendSign(*TempAdr);
//TempAdr++;
//
//}; 


//while (TempChar != '#')
while (TempChar != 0)  
{
SendSign(TempChar);
TempAdr++;
TempChar = *TempAdr;
};

//SendSign(10);


}

/*
void SendInternalVariables (void)
{
SendString("    InvertorSwitchOnCondition    ", InvertorSwitchOnCondition);
SendSign(10);
SendSign(13);

SendString("    StateMode                    ", StateMode);
SendString("    LastStateMode                ", LastStateMode);
SendSign(10);
SendSign(13);


}
*/

/*
void SendOutputVariables (void)
{
SendString("    LED_MotorOverHeating    ", LED_MotorOverHeating);
SendString("    LED_InvertorOverHeating ", LED_InvertorOverHeating);
SendSign(10);
SendSign(13);
SendString("    LED_InvertorFaulting    ", LED_InvertorFaulting);
SendString("    LED_Signaling           ", LED_Signaling);
SendSign(10);
SendSign(13);
SendString("    Out_SwitchOnInvertor    ", Out_SwitchOnInvertor);
SendString("    Out_StabileSpeed        ", Out_StabileSpeed);
SendSign(10);
SendSign(13);
SendString("    Out_TransitModeReady    ", Out_TransitModeReady);
SendString("    Out_ElectricalDriveReady", Out_ElectricalDriveReady);
SendSign(10);
SendSign(13);
SendString("    Out_InvertorSTOP        ", Out_InvertorSTOP);
SendString("    Out_ElectricalDriveFault", Out_ElectricalDriveFault);
SendSign(10);
SendSign(13);


}
*/
void SendNumber(unsigned int InputNumber)
{
unsigned char CharArray[5];
unsigned int TempNumber = InputNumber;
unsigned int TempNumberInt;
int i;

//TempNumberInt = fmod(TempNumber,10);

//SendSign(TempNumber + 48);
//SendSign(10);
//SendSign(13);

TempNumberInt = TempNumber/10;
//SendSign(TempNumber + 48);
//SendSign(10);
//SendSign(13);

//SendSign(TempNumberInt + 48);
//SendSign(10);
//SendSign(13);


CharArray[0] = TempNumber - 10 * TempNumberInt;
TempNumber = TempNumberInt;
//SendSign(CharArray[0]+48);
//SendSign(10);
//SendSign(13);


TempNumberInt = TempNumber/10;
CharArray[1] = TempNumber - 10 * TempNumberInt;
TempNumber = TempNumberInt;
//SendSign(CharArray[1]+48);

TempNumberInt = TempNumber/10;
CharArray[2] = TempNumber - 10 * TempNumberInt;
TempNumber = TempNumberInt;
//SendSign(CharArray[2]+48);

TempNumberInt = TempNumber/10;
CharArray[3] = TempNumber - 10 * TempNumberInt;
TempNumber = TempNumberInt;
//SendSign(CharArray[3]+48);

TempNumberInt = TempNumber/10;
CharArray[4] = TempNumber - 10 * TempNumberInt;
TempNumber = TempNumberInt;
//SendSign(CharArray[4]+48);

for (i=4; i>=0; i--)
    {
        SendSign(CharArray[i]+48);    
    };
//SendSign(10);
//SendSign(13);

}

/*
void SendVariables(void)
{
 unsigned int TempInt;
 unsigned int TempIN27 = IN27;
 SendStringOnly("    IN27 = ");
 SendNumber(IN27);
 SendSign(10);
 SendSign(13);


//TempInt = IN27;
//SendStringOnly("    TempInt = ");
//SendNumber(TempInt);
//SendSign(10);
//SendSign(13);
 
 
TempInt = TempIN27 & 1;
//SendStringOnly("    TempInt = ");
//SendNumber(TempInt);
//SendSign(10);
//SendSign(13);
//  SendString("    TEST", TempInt);
  
  
// return;  
 SendString("    27IN_01 POHOD.POLOZH.", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_02 MESTNOE UPR. ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_03 VKL.INV.RAZR.", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_04 INV.VKLUCHEN ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendSign(10);
 SendSign(13);   
 SendString("    27IN_05 ZASTOPORENO  ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_06 RASSTOPORENO ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_07 VKL. INVERTOR", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_08 VKL. 1       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendSign(10);
 SendSign(13);   
 SendString("    27IN_09 VKL. 2       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_10 VKL. 3       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_11 VKL. 4       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_12 VKL. 5       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendSign(10);
 SendSign(13);   
 SendString("    27IN_13 REZHIM PAZ   ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_14 REZERV       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_15 REZERV       ", TempInt);
 TempIN27 = TempIN27 >> 1;
 TempInt = TempIN27 & 1;
 SendString("    27IN_16 REZERV       ", TempInt);
 SendSign(10);
 SendSign(13);   
 SendString("    S1 INDIKACIYA", PanelSwitch1Code); 
 SendString("            S2 REZHIM    ", PanelSwitch2Code); 
 SendString("            S3 VKL.INV.  ", PanelSwitch3Code); 
 SendSign(10);
 SendSign(13);   
}
*/

unsigned char USART_Receive(void)
{
    /* Wait for data to be received */
    while ( !(UCSR0A & (1<<RXC0)) )
    ;
    /* Get and return received data from buffer */
    return UDR0;
}


/*
void ReceiveString(void)
{


unsigned char CharArray[20];
unsigned char CurrentChar;
int CharArrayPointer = 0;
int i;
unsigned int TempCode = 0;
//                    SendStringOnly("Point 1");
//                    SendSign(10);
//                    SendSign(13);
//        SendSign(13);         
//        SendString("Begin#", 0);
//        SendSign(13); 

do  {
    CharArray [CharArrayPointer] = USART_Receive();
    }
while (CharArray [CharArrayPointer] != 10 && CharArray [CharArrayPointer++] != 13);

//        SendSign(13);
//        SendString("Begin#", 1);
//        SendSign(13);  

for (i=0;i<=CharArrayPointer-1;i++)
    {
               
//        SendSign(CharArrayPointer+48);
//        SendSign(13);
//        SendString("Begin#", 2);
//        SendSign(13);  
        SendSign(CharArray [i]);
    };

//                    SendStringOnly("Point 2");
                    SendSign(10);
                    SendSign(13);

//SendSign(USART_Receive());

//SendSign(10);
//SendSign(13);

if (CharArray[0]=='2' && CharArray[1]=='7' && 
     CharArray[2]=='i' && CharArray[3]=='n' &&
     CharArray[4]=='=')
    {
        i = 5;
        while (CharArray[i] !=10 && CharArray[i] != 13 && i < 10)
        { 
            TempCode = TempCode * 10 + CharArray[i] - 48;
            i++;
        };
//    SendNumber(TempCode);
    IN27 = TempCode;

    SendVariables();
      
           
    };

 

if (CharArray[0]=='s' && CharArray[1]=='1' && 
     CharArray[2]=='=')
    {
        if (CharArray[4] ==10 || CharArray[4] == 13)
            {
                if (CharArray[3] >=48 && CharArray[3]<=54)
                {
                    PanelSwitch1Code = CharArray[3] - 48;
                        SendVariables();    
                }
                else
                {
                    SendStringOnly("Error!");
                    SendSign(10);
                    SendSign(13);
                };
            }
            else
            {
                SendStringOnly("Error!");
                SendSign(10);
                SendSign(13);
            };

    };

if (CharArray[0]=='s' && CharArray[1]=='2' && 
     CharArray[2]=='=')
    {
        if (CharArray[4] ==10 || CharArray[4] == 13)
            {
                if (CharArray[3] >=48 && CharArray[3]<=54)
                {
                    PanelSwitch2Code = CharArray[3] - 48;
                    SendVariables();    
                }
                else
                {
                    SendStringOnly("Error!");
                    SendSign(10);
                    SendSign(13);
                };
            }
            else
            {
                SendStringOnly("Error!");
                SendSign(10);
                SendSign(13);
            };

    };
    
if (CharArray[0]=='s' && CharArray[1]=='3' && 
     CharArray[2]=='=')
    {
        if (CharArray[4] ==10 || CharArray[4] == 13)
            {
                if (CharArray[3] >=48 && CharArray[3]<=49)
                {
                    PanelSwitch3Code = CharArray[3] - 48;
                    SendVariables();    
                }
                else
                {
                    SendStringOnly("Error!");
                    SendSign(10);
                    SendSign(13);
                };
            }
            else
            {
                SendStringOnly("Error!");
                SendSign(10);
                SendSign(13);
            };

    };    

StateMachine();    
SendInternalVariables();
SendOutputVariables();

//SendVariables();    
}
*/


void TestReceiveTransmit (void)
{



}


 

Arhat109-2
Offline
Зарегистрирован: 24.09.2015

Пасибки. А то всё "поможите, сами мы не местные" .. хоть один полезный топик на тыщу. :)

KulibinOrsk
Offline
Зарегистрирован: 11.06.2017

Приветствую.
Есть интерес к SSI. Готов отблагодарить. Выходи на связь.