селектор
#1

4-х входовьій селектор с индикацией
каждая ножка МК используется как индикатор вьібора и как вход
Код:
#define IN_1 TRISB1
#define IN_2 TRISB2
#define IN_3 TRISB3
#define IN_4 TRISB4
#define INP_1 RB1
#define INP_2 RB2
#define INP_3 RB3
#define INP_4 RB4

#define SEL_STATE (PORTB & 0x1E)
и с некоторой периодичностью обрабатьіваем от єто

Код:
void selector(void) {
    unsigned char n = 0;
    if (selstate != SEL_STATE) {
        selstate = SEL_STATE;
        switch (SEL_STATE) {
            
            case 0x06:
              if (!IN_4) {
                    IN_4 = 1;
                    IN_3 = 0;
                    INP_3 = 0;
                    
                } else {
                    IN_3 = 1;
                    IN_4 = 0;
                    INP_3 = 1;
                    
                }

                break;
            
            case 0x12:
            
                if (!IN_3) {
                    IN_3 = 1;
                    IN_2 = 0;
                    INP_2 = 0;
                    
                } else {
                    IN_2 = 1;
                    IN_3 = 0;
                    INP_2 = 1;
                    
                }
                break;
            
            case 0x18:
            
                if (!IN_2) {
                    IN_2 = 1;
                    IN_1 = 0;
                    INP_1 = 0;
                    
                } else {
                    IN_1 = 1;
                    IN_2 = 0;
                    INP_1 = 1;
                    
                }
                break;
            
            case 0x0c:
            
                if (!IN_1) {
                    IN_1 = 1;
                    IN_4 = 0;
                    INP_4 = 0;
                    
                } else {
                    IN_4 = 1;
                    IN_1 = 0;
                    INP_4 = 1;
                    
                }
                break;
            
            case 0x0a:
            
                if (!IN_2) {
                    IN_2 = 1;
                    IN_4 = 0;
                    INP_4 = 0;
                    
                } else {
                    IN_4 = 1;
                    IN_2 = 0;
                    INP_4 = 1;
                    
                }
                break;
            
            case 0x14:
               if (!IN_3) {
                    IN_3 = 1;
                    IN_1 = 0;
                    INP_1 = 0;
                    
                } else {
                    IN_1 = 1;
                    IN_3 = 0;
                    INP_1 = 1;

                }
                break;
            
            
            case 0x0e:
            sel=3;
            break;
            
            case 0x16:
            sel=2;
            break;
            
            case 0x1a:
            sel=1;
            break;
            
            case 0x1c:
            sel=0;
            break;
            

        }

        S_data_send(sel); // установка мультиплексора
        
    }

}

не покидает ощущение. что можно бьіло-б сделать проще Sad
Ответ


Сообщения в этой теме
селектор - от wired - 01-04-2017, 01:53 PM
RE: селектор - от Altor Audio - 01-05-2017, 02:06 AM
RE: селектор - от Altor Audio - 01-05-2017, 02:46 AM
RE: селектор - от wired - 01-05-2017, 02:54 AM
RE: селектор - от EDWARD - 01-05-2017, 06:22 AM
RE: селектор - от wired - 01-05-2017, 06:38 AM
RE: селектор - от Altor Audio - 01-05-2017, 07:22 AM
RE: селектор - от wired - 01-05-2017, 07:24 AM
RE: селектор - от Altor Audio - 01-05-2017, 01:31 PM
RE: селектор - от wired - 01-25-2017, 12:43 AM
RE: селектор - от Altor Audio - 01-25-2017, 08:20 AM
RE: селектор - от wired - 01-25-2017, 08:58 AM
RE: селектор - от wired - 01-25-2017, 02:47 PM
RE: селектор - от Altor Audio - 01-26-2017, 01:25 AM
RE: селектор - от wired - 01-26-2017, 01:57 AM
RE: селектор - от wired - 04-27-2017, 07:03 AM

Перейти к форуму:


Пользователи, просматривающие эту тему: 2 Гость(ей)