|
۱-توضیح در مورد پین ها پورت سری(COM):
DB-9 Connector Pin Out
| Pin |
Signal Name |
Description |
| 1 |
CD |
Carrier Detect |
| 2 |
RXD |
Receive Data |
| 3 |
TXD |
Transmit Data |
| 4 |
DTR |
Data Terminal Ready |
| 5 |
GND |
Signal Ground / Common |
| 6 |
DSR |
Data Set Ready |
| 7 |
RTS |
Request To Send |
| 8 |
CTS |
Clear To Send |
| 9 |
RI |
Ring Indicator |
-معمولا براي انتقال اطلاعات از ۳ پين استفاده مي شود RXD, TXD, GND
-شکل موج انتقال اطلاعات:
 RS-232 Logic Waveform
-برای تبدیل سطح ولتاژ از آی سی max232 استفاده می کنیم.

-يک برنامه به زبان C که يک عدد روي پورت سري مي ريزد.
#include <stdio.h>
#include <conio.h>
#include <bios.h>
void main (void) { clrscr(); /* clear screen */ outportb(0x3F8,0xff); /* send 255 to com1*/ getch(); /* wait for keypress before exiting */ }
-برنامه زير کاراکتر موجود روي پورت را دريافت کرده و روي صفحه نمايش چاپ مي کندو با فشار هر کليد
از صفحه کليد کاراکتر مربوط به ان کليد به پورت انتقال داده مي شود.
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <bios.h>
#define INTR 0X14
#define __CPPARGS ...
#define PORT1 0x3F8 /* Port Address Goes Here */
#define INTVECT 0X0C /* Com Port"s IRQ here (Must also change PIC setting) */
/* Defines Serial Ports Base Address */
/* COM1 0x3F8 */
/* COM2 0x2F8 */
/* COM3 0x3E8 */
/* COM4 0x2E8 */
int bufferin = 0;
int bufferout = 0;
char ch;
char buffer[1025];
void interrupt (*oldport1isr)(__CPPARGS);
void interrupt PORT1INT(__CPPARGS) /* Interrupt Service Routine (ISR) for PORT1 */
{
int c;
do { c = inportb(PORT1 + 5);
if (c & 1) {buffer[bufferin] = inportb(PORT1);
bufferin++;
if (bufferin == 1024) {bufferin = 0;}}
} while (c & 1);
outportb(0x20,0x20);
}
void main(void)
{
int c;
outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */
oldport1isr = getvect(INTVECT); /* Save old Interrupt Vector of later
recovery */
setvect(INTVECT, PORT1INT); /* Set Interrupt Vector Entry */
/* COM1 - 0x0C */
/* COM2 - 0x0B */
/* COM3 - 0x0C */
/* COM4 - 0x0B */
/* PORT 1 - Communication Settings */
outportb(PORT1 + 3 , 0x80); /* SET DLAB ON */
outportb(PORT1 + 0 , 0x0C); /* Set Baud rate - Divisor Latch Low Byte */
/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 57,600 BPS */
/* 0x06 = 19,200 BPS */
/* 0x0C = 9,600 BPS */
/* 0x18 = 4,800 BPS */
/* 0x30 = 2,400 BPS */
outportb(PORT1 + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */
outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 2 , 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */
outportb(0x21,(inportb(0x21) & 0xEF)); /* Set Programmable Interrupt Controller */
/* COM1 (IRQ4) - 0xEF */
/* COM2 (IRQ3) - 0xF7 */
/* COM3 (IRQ4) - 0xEF */
/* COM4 (IRQ3) - 0xF7 */
outportb(PORT1 + 1 , 0x01); /* Interrupt when data received */
printf( "
Sample Comm"s Program. Press ESC to quit
");
do {
if (bufferin != bufferout){ch = buffer[bufferout];
bufferout++;
if (bufferout == 1024) {bufferout = 0;}
printf( "%c",ch);}
if (kbhit()){c = getch();
outportb(PORT1, c);}
} while (c !=27);
outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */
outportb(0x21,(inportb(0x21) | 0x10)); /* MASK IRQ using PIC */
/* COM1 (IRQ4) - 0x10 */
/* COM2 (IRQ3) - 0x08 */
/* COM3 (IRQ4) - 0x10 */
/* COM4 (IRQ3) - 0x08 */
setvect(INTVECT, oldport1isr); /* Restore old interrupt vector */
}
۲-توضیح در مورد پین ها پورت موازي(LPT1 )
<= in DB25 Cent Name of Reg => out pin pin Signal Bit Function Notes ------ ---- ---- -------- --- ----------------------------- => 1 1 -Strobe C0- Set Low pulse >0.5 us to send => 2 2 Data 0 D0 Set to least significant data => 3 3 Data 1 D1 ... => 4 4 Data 2 D2 ... => 5 5 Data 3 D3 ... => 6 6 Data 4 D4 ... => 7 7 Data 5 D5 ... => 8 8 Data 6 D6 ... => 9 9 Data 7 D7 Set to most significant data <= 10 10 -Ack S6+ IRQ Low Pulse ~ 5 uS, after accept <= 11 11 +Busy S7- High for Busy/Offline/Error <= 12 12 +PaperEnd S5+ High for out of paper <= 13 13 +SelectIn S4+ High for printer selected => 14 14 -AutoFd C1- Set Low to autofeed one line <= 15 32 -Error S3+ Low for Error/Offline/PaperEnd => 16 31 -Init C2+ Set Low pulse > 50uS to init => 17 36 -Select C3- Set Low to select printer == 18-25 19-30, Ground 33,17,16
|