103 lines
2.1 KiB
C
103 lines
2.1 KiB
C
#include "device_ring_buffer.h"
|
|
#include "device_adc.h"
|
|
#include "device_address.h"
|
|
#include "UART.h"
|
|
#include "modbus.h"
|
|
#include "timer.h"
|
|
#include "gpio.h"
|
|
|
|
|
|
//èíèöèàëèçàöèÿ
|
|
void gpio_init(void)
|
|
{
|
|
//Óñòàíîâêà ïèíîâ pin_coils â ðåæèì âûõîäà - 1
|
|
DDRD |= (1 « PIN_COIL1);
|
|
DDRD |= (1 « PIN_COIL2);
|
|
DDRD |= (1 « PIN_COIL3);
|
|
DDRD |= (1 « PIN_COIL4);
|
|
|
|
//Óñòàíîâêà ïèíîâ pin_discrete_inputs â ðåæèì âõîäà - 0
|
|
DDRB &= ~(1 « PIN_DISCRETE_INPUT_1);
|
|
DDRB &= ~(1 « PIN_DISCRETE_INPUT_2);
|
|
DDRB &= ~(1 « PIN_DISCRETE_INPUT_3);
|
|
DDRB &= ~(1 « PIN_DISCRETE_INPUT_4);
|
|
}
|
|
|
|
//÷òåíèå
|
|
uint8_t gpio_read(uint8_t pin)
|
|
{
|
|
switch (pin)
|
|
{
|
|
//÷òåíèå pin_coils
|
|
case PIN_COIL1:
|
|
return (PIND & (1 « PIN_COIL1)) » PIN_COIL1; // ×òåíèå çíà÷åíèÿ íà ïèíå è ñäâèã âïðàâî íà íîìåð ïèíà
|
|
case PIN_COIL2:
|
|
return (PIND & (1 « PIN_COIL2)) » PIN_COIL2;
|
|
case PIN_COIL3:
|
|
return (PIND & (1 « PIN_COIL3)) » PIN_COIL3;
|
|
case PIN_COIL4:
|
|
return (PIND & (1 « PIN_COIL4)) » PIN_COIL4;
|
|
|
|
//÷òåíèå pin_discrete_inputs
|
|
case PIN_DISCRETE_INPUT_1:
|
|
return (PINB & (1 « PIN_DISCRETE_INPUT_1)) » PIN_DISCRETE_INPUT_1;
|
|
case PIN_DISCRETE_INPUT_2:
|
|
return (PINB & (1 « PIN_DISCRETE_INPUT_2)) » PIN_DISCRETE_INPUT_2;
|
|
case PIN_DISCRETE_INPUT_3:
|
|
return (PINB & (1 « PIN_DISCRETE_INPUT_3)) » PIN_DISCRETE_INPUT_3;
|
|
case PIN_DISCRETE_INPUT_4:
|
|
return (PINB & (1 « PIN_DISCRETE_INPUT_4)) » PIN_DISCRETE_INPUT_4;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
//çàïèñü
|
|
void gpio_write(uint8_t pin, uint8_t value)
|
|
{
|
|
switch (pin)
|
|
{
|
|
case PIN_COIL1:
|
|
if (value != 0x0000)
|
|
{
|
|
PORTD |= (1 « PIN_COIL1);
|
|
}
|
|
else
|
|
{
|
|
PORTD &= ~(1 « PIN_COIL1);
|
|
}
|
|
break;
|
|
case PIN_COIL2:
|
|
if (value != 0x0000)
|
|
{
|
|
PORTD |= (1 « PIN_COIL2);
|
|
}
|
|
else
|
|
{
|
|
PORTD &= ~(1 « PIN_COIL2);
|
|
}
|
|
break;
|
|
case PIN_COIL3:
|
|
if (value != 0x0000)
|
|
{
|
|
PORTD |= (1 « PIN_COIL3);
|
|
}
|
|
else
|
|
{
|
|
PORTD &= ~(1 « PIN_COIL3);
|
|
}
|
|
break;
|
|
case PIN_COIL4:
|
|
if (value != 0x0000)
|
|
{
|
|
PORTD |= (1 « PIN_COIL4);
|
|
}
|
|
else
|
|
{
|
|
PORTD &= ~(1 « PIN_COIL4);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
} |