Академический Документы
Профессиональный Документы
Культура Документы
com/print/51874
Board Description
HW description
PCB;
microcontroller Microchip (18f2455 -see the Datasheet) with 32 Kb off flash memory, 256
byte of Eeprom memory and controller USB;
Optocoupler for input (TPL4N25-4).
USB Connector
Relays. We can mount two type of relay, one with maximum 30Vcc (or
125Vac) or another with 230Vac, 2A contact.
Schematics
Fig. 1
Fig. 2
Firmware description
The board firmware receives a command from the PC (using the get function) elaborate the
command (by ProcessIO function) and executes the command(toggle the relay or read the
input).
This is and example of the source code of the firmware:
void main(void)
{
/* A7 A6 A5 A4 A3 A2 A1 A0 */
/* 1 1 1 1 1 1 0 0 */
LATA &= 0x0; TRISA &= 0xFC; /* configure port A of uC */
/* B7 B6 B5 B4 B3 B2 B1 B0 */
/* 1 1 1 1 1 1 1 1 */
LATB &= 0x0; TRISB &= 0xFF; /* configure port B of uC */
/* C7 C6 C5 C4 C3 C2 C1 C0 */
/* 0 0 1 1 1 1 0 0 */
LATC &= 0x0; TRISC &= 0x3C; /* configure porta C of uC */
InitializeSystem();
mLED_1_Off();
MSB_num_restart = ReadEEPROM(0x20);
LSB_num_restart = RedEEPROM(0x21);
if ((MSB_num_restart == 0xFF)&(LSB_num_restart == 0xFF)){
/* blank eeprom */
MSB_num_restart = 0 ;
LSB_num_restart = 0 ;
WriteEEPROM ( 0x20, 0);
WriteEEPROM ( 0x21, 0);
}
else
{
if (LSB_num_restart == 0xFF){
MSB_num_restart = MSB_num_restart +1;
WriteEEPROM ( 0x20, MSB_num_restart);
WriteEEPROM ( 0x21, 0);
LSB_num_restart = 0;
}
else
{
LSB_num_restart = LSB_num_restart +1;
WriteEEPROM ( 0x21, LSB_num_restart);
}
}
EnablePullups(); /* enable pull-up on PORTB */
while(1)
{
USBTasks(); /* USB Tasks */
ProcessIO(); /* See user\user.c & .h */
}
}
void ProcessIO(void)
{
if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return;
if(getsUSBUSART(input_buffer,1)){
...
if(input_buffer[0] == '6') /* 0x36 */ {
if(mUSBUSARTIsTxTrfReady()){
mRele_1_On(); /* turn on relay number 1*/
putrsUSBUSART("I"); /* acknoledge */
}
}
...
}
}
The ProcessIO() function waits for a command. On this example when the board receives the "6"
character on virtual RS232 (the USB) the first relay will turn on and answer with "I" character.
You can also read how many time the board has been turned on, this counter is saved on the
eeprom memory inside the PIC microcontroller.
Software description
Here is an example of software written with Visual Basic. From left ToolBox import the
"SerialPort" control. We will use 3 functions of this control, which are: Open, Write, Read
To read the answer from the board and to acknowledge the command received
use the SerialPort.Read function
Command protocol
You can also read how many time the board has been powered up:
Send w = 0x77 = 119 => Read the Most significant part of number of restart
Send z = 0x7A = 122 => Read the Least significant part of number of restart
Attachment Size
SW_PC_Relay_USB.zip 289.38 KB
Trademarks