Virtual Integrated Design

Relay Circuit

 

RS232 relay driver

 

RS232 relay controller

 

File 1:

#pragma option +v

// relay.c
// 03/04/2000
// (C) Virtual Integrated Design

#include <16c54.h>
#include <rx12.c>
#include <tx12.c>
#include <delay12.h>

#define address 0x01

void xmit_19200_4mhz(unsigned char);
unsigned char receive_19200_4mhz(void);

unsigned char x @0x0F;
unsigned char y @0x10;

void main(void)
{

 __TRIS(0x1,PORTA); // 0=input 1,2,3=outputs
 __TRIS(0x00,PORTB); // all output
 NOP();
 PORTA=0XB;
 PORTB=0x00;

 while(1)
 {

  x=receive_19200_4mhz();

  if(x==address)
  {
    y=receive_19200_4mhz();
    PORTB=y;
    xmit_19200_4mhz(x);
    xmit_19200_4mhz(y);
    PORTA.3=0; // led on
  }
  else
  {
   PORTA.3=1; // led off
  }

 }

}
//------------------------------------------------------
#include <delay12.lib>

File 2:

#pragma option +v

// rx12.c
// 03/04/2000
// (C) Virtual Integrated Design

#include <16c54.h>
#include <delay12.h>

unsigned char receive_19200_4mhz(void)
{
 unsigned char i, x=0;

 // Start Bit
 while(PORTA.0);
 PORTA.2=1; // debug
 Delay_10xUs_4MHz(7);
 PORTA.2=0; // debug
 NOP();
 NOP();

 // Bits 1-7
 for(i=0;i<7;i++)
 {
   PORTA.2=1; // debug
   if(PORTA.0)
   {
    x|=0x80;
   }
   else
   {
    x|=0x01;
    NOP();
   }
   x=x>>1;
   Delay_10xUs_4MHz(3);
   PORTA.2=0; // debug
 }

 PORTA.2=1; // debug

 // Bit 8
 if(PORTA.0)
 {
  x|=0x80;
 }
 Delay_10xUs_4MHz(5);

 PORTA.2=0; // debug

 return x;
}
/*-----------------------------------*/
#include <delay12.lib>

File 3:

#pragma option +v

// tx12.c
// 03/04/2000
// (C) Virtual Integrated Design

#include <16c54.h>
#include <delay12.h>

void xmit_19200_4mhz(unsigned char t)
{
 unsigned char i;

 // Start Bit
 PORTA.1=0;
 Delay_10xUs_4MHz(3);

 for(i=0;i<8;i++)
 {
  t=t>>1;
  if(STATUS.C)
  {
   PORTA.1=1;
  }
  else
  {
   PORTA.1=0;
   NOP();
   NOP();
   NOP();
  }
  Delay_10xUs_4MHz(3);
  NOP();
  NOP();
 }

 // Stop Bit
 NOP();
 NOP();
 NOP();
 PORTA.1=1;
 Delay_10xUs_4MHz(4);

}
/*-----------------------------------*/
#include <delay12.lib>

Hex File:

:020000040000FA
:08000000520A6A000506020A1B
:080008004505070C260945041B
:08001000000000006900070C6C
:08001800890003061D0A4505DD
:080020000507140AEA05160A9F
:080028000A05000003042A038D
:08003000030C26094504A90296
:080038000B0A45050506EA0567
:08004000050C260945040A0223
:0800480027000008000027005A
:080050000000000000000000A8
:08005800000000000000E702B7
:08006000280A00082B0025040A
:08006800030C26096C00080CD2
:080070008C0003064B0A030497
:080078002B030307410A2505D3
:08008000450A25040000000000
:080088000000030C2609000032
:080090000000AC02370A000079
:08009800000000002505040C26
:0800A00026090008010C05000F
:0800A800000C060000000B0C27
:0800B0002500660001090702AA
:0800B8002F00010C8F0043072B
:0800C0006B0A01090702300080
:0800C80026000F0232091002AC
:0800D000320965046C0A6505A4
:0400D8005A0A0008B8
:0203FE0063009A
:00000001FF
 

Free RS232

 Home | Applications | Industry Links | C++ Builder Stop | Micro Stop | Hex to Ascii Chart