Datasheet

char dat[10]; // buffer for receving/send-
ing messages
char i,j;
sbit RS485_rxtx_pin at PORTD.B2; // set transcieve pin
sbit RS485_rxtx_pin_direction at DDRD.B2; // set transcieve pin
direction
// Interrupt routine
void interrupt() org 0x16 {
RS485Master_Receive(dat);
}
void main(){
long cnt = 0;
PORTA = 0; // clear PORTA
PORTB = 0; // clear PORTB
PORTC = 0; // clear PORTC
DDRA = 0xFF; // set PORTA as output
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 = UART1_TX_Idle;
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
RS485Master_Init(); // initialize MCU as Master
dat[0] = 0xAA;
dat[1] = 0xF0;
dat[2] = 0x0F;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,1,160);
SREG_I = 1; // enable global interrupt
RXCIE = 1; // enable interrupt on usart receive
while (1){
// upon completed valid message receiving
// data[4] is set to 255
cnt++;
397
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6