/**************************************************************************/ /* Program : Termast.c (For RS485) */ /* Description : This program reads the tempature from a 4018. If the */ /* tempature is to high it will trun on Relay D0 of the 4060. if the */ /* tempature is to low it will trun on Relay D1 of the 4060. Both relays*/ /* will turn off when a mean tempature is reached. */ /* */ /* ADAM-4018 is set to address 02 */ /* Baud Rate 38400 */ /* Check Sum NO */ /* */ /* ADAM-4060 is set to address 03 */ /* Baud Rate 38400 */ /* Check Sum NO */ /**************************************************************************/ #include "adam4500.h" void main(void) { int i; unsigned int length; unsigned char data[200]; unsigned int temp; comm_init(1000); //Initialize the comm port buffers comm_open(2,38400L,0,8,1,0); //Open com2 @ 38.4k,8bit,1stop bit,no parity led_init(); // Initialize LED led(0); // turn off LED while(1){ comm_send('#',2); // Transmit '#02' to read Temp. comm_send('0',2); comm_send('2',2); comm_send(13,2); for (i=0;i<200;i++); // Waiting for response comm_get_rec_datas(&length ,&data , 2); //Read in temp from com2 temp=(data[2]-48)*100+(data[3]-48)*10+(data[4]-48);//convert temp if (temp>24){ // check to see if temp is to hot. led(1); //Turn on LED comm_send('@',2); // Transmit '@03D001' to Turn comm_send('0',2); // on D0. comm_send('3',2); comm_send('D',2); comm_send('0',2); comm_send('0',2); comm_send('1',2); comm_send(13,2); while (temp>21){ comm_send('#',2); //Transmit '#02' to read Temp. comm_send('0',2); comm_send('2',2); comm_send(13,2); for (i=0;i<200;i++); // Waiting for response comm_get_rec_datas(&length ,&data , 2); //Read in temp temp=(data[2]-48)*100+(data[3]-48)*10+(data[4]-48); } comm_send('@',2); // Transmit '@03D000 to Turn comm_send('0',2); // off D0. comm_send('3',2); comm_send('D',2); comm_send('0',2); comm_send('0',2); comm_send('0',2); comm_send(13,2); led(0); // Turn off LED } if (temp<19){ // check to see if temp is to cool. led(1); // Turn on LED comm_send('@',2); // Transmit '@03D002' to Turn comm_send('0',2); // on D1. comm_send('3',2); comm_send('D',2); comm_send('0',2); comm_send('0',2); comm_send('2',2); comm_send(13,2); while (temp<21){ comm_send('#',2); // Transmit '#02' to read Temp. comm_send('0',2); comm_send('2',2); comm_send(13,2); for (i=0;i<200;i++); // Waiting for response comm_get_rec_datas(&length ,&data , 2); //Read in temp temp=(data[2]-48)*100+(data[3]-48)*10+(data[4]-48); } comm_send('@',2); // Transmit '@03D000' to Turn comm_send('0',2); // off D1. comm_send('3',2); comm_send('D',2); comm_send('0',2); comm_send('0',2); comm_send('0',2); comm_send(13,2); led(0); // Turn off LED } } comm_exit() }