Datasheet
RS485 Slave code:
program RS485_Slave_Example;
uses __Lib_RS485;
var dat : array[20] of byte; // buffer for receving/sending messages
i, j : byte;
var rs485_rxtx_pin : sbit at PORTD.B2; // set transcieve pin
rs485_rxtx_pin_direction : sbit at DDRD.B2; // set transcieve
pin direction
// Interrupt routine
procedure interrupt(); org 0x16;
begin
RS485Slave_Receive(dat);
end;
begin
PORTB := 0; // clear PORTB
PORTC := 0; // clear PORTC
DDRB := 0xFF; // set PORTB as output
DDRC := 0xFF; // set PORTB as output
// Pass pointers to UART functions of used UART module
UART_Wr_Ptr := @UART1_Write;
UART_Rd_Ptr := @UART1_Read;
UART_Rdy_Ptr := @UART1_Data_Ready;
UART_TX_Idle_Ptr := @UART1_TX_Idle;
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
RS485Slave_Init(160); // Intialize MCU as slave, address 160
dat[4] := 0; // ensure that message received flag is 0
dat[5] := 0; // ensure that message received flag is 0
dat[6] := 0; // ensure that error flag is 0
SREG_I := 1; // enable global interrupt
RXCIE := 1; // enable interrupt on UARTs receive
while (TRUE) do
begin
if (dat[5] <> 0) then // if an error detected, signal it by
begin
PORTC := dat[5]; // setting PORTC
347
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6