Professional Documents
Culture Documents
David Vernon
PC Interfacing
Communications and
Windows Programming,
William Buchanan, Addison
Wesley
Microcomputer Interfacing
and Applications,
M. A. Mustafa, Newnes
Motivation
Microprocessor Architecture
Typical PC Memory
Copyright Map
2007 David Vernon (www.vernon.eu)
Microprocessor Architecture
Typical isolated I/O Memory Map
Prototyped in dos.h
Microsoft C++
unsigned char value;
value = _inp(PORTADDRESS);
Prototyped in conio.h
Prototyped in dos.h
Microsoft C++
unsigned int value;
value = _inpw(PORTADDRESS);
Prototyped in conio.h
Prototyped in dos.h
Microsoft C++
unsigned char value;
_outp(PORTADDRESS,value);
Prototyped in conio.h
Prototyped in dos.h
Microsoft C++
unsigned int value;
_outw(PORTADDRESS, value);
Prototyped in conio.h
1111101000001011000001111111111111100000111111
1100011001111010100111111111111
Message is AppL
Copyright 2007 David Vernon (www.vernon.eu)
Serial Interfaces: RS-232
Parity
Simple form of error coding
A parity bit is added to transmitted data to make the
number of 1s (in the data) either even (even parity) or odd
(odd parity)
A single parity bit can only detect an odd number of errors
(why?)
1 Frame Ground FG This ground normally connects the outer sheath of the cable to
the earth ground
2 Transmit Data TD Data is sent from the DTE (computer or terminal) to a DCE via TD
5 Clear to Send CTS DCE sets this active to inform the DTE that it is ready to receive
data
6 Data Set Ready DSR Signals that the DCE is ready to communicate
Hardware interrupts:
INT
Reset
RESET active low
#include <stdio.h>
#include <conio.h>
int main(void){
int far *ptr; /* 20-bit pointer */
ptr = (int far *) 0x0400000; /* 0040:0000 */
clrscr();
printf(COM1: %04x\n, *ptr);
printf(COM2: %04x\n, *(ptr+1));
printf(COM3: %04x\n, *(ptr+2));
printf(COM4: %04x\n, *(ptr+3));
return(0);
}
#include<stdio.h>
#include <conio.h> /* included for getch */
#include <dos.h> /* included for inputb and outputb */
void setup_serial(void);
void send_character(int ch);
int main(void)
{
int ch;
puts("Transmitter program. Please enter text (Cntl-D to end)");
setup_serial();
do
{
ch=getch();
send_character(ch);
} while (ch!=4);
return(0);
}
outportb(TXDATA,0x0C);
outportb(TXDATA+1,0x00);
outportb(TXDATA,(char) ch);
} Copyright 2007 David Vernon (www.vernon.eu)
Serial Interfaces: RS-232
/* receive.c */
void setup_serial(void);
int get_character(void);
int main(void)
{
int inchar;
setup_serial();
do
{
inchar=get_character();
putchar(inchar);
} while (inchar!=4);
return(0);
}
outportb(TXDATA,0x0C);
outportb(TXDATA+1,0x00);
int get_character(void)
{
int status;
/* Repeat until bit 1 in LSR is set */
do {
status = inportb(LSR) & 0x01;
} while (status!=0x01);
return( (int)inportb(TXDATA));
}
Copyright 2007 David Vernon (www.vernon.eu)
Copyright 2007 David Vernon (www.vernon.eu)
Serial Interfaces: RS-422
Signal levels 0 to +5V
Uses differential amplifiers at both transmitting
and receiving ends to achieve high noise
immunity
Up to 10 Mbps over distance of 1.2km
Common descriptors
Device descriptors
Configuration descriptors
Interface Descriptors
Endpoint descriptors
String descriptors
(Text and Figures based on W. Buchanan, PC Interfacing Communications and Windows Programming)
Copyright 2007 David Vernon (www.vernon.eu)
Digital I/O
Digital I/O can be achieved using the
Programmable Peripheral Interface (PPI) device
Intel 8255 IC
40 pins
Normally mapped into the isolated I/O memory map of a PC
TTL voltage compatibility (5.5V maximum input)
Maximum current source / sink: 1mA
RD Read
WR Write
A1 Address line to select I/O port or control register
A0
RESET low input on RESET initializes the device
CS chip select (low to activate the device)
int main(void)
{
unsigned char i=0;
outportb(CNTRL_REG, 0x90); /* what does this do? */
do
{
i = inportb(PORTA);
outportb(PORTB, i);
my_delay(1); /* wait 1 second */
printf(Input value is %d\n, i);
} while (i != 0xff);
return(0);
}
Copyright 2007 David Vernon (www.vernon.eu)
Digital I/O
void my_delay(int secs)
{
time_t oldtime, newtime;
time(&oldtime);
do {
time(&newtime);
} while ((newtime-oldtime)<secs);
}
This allows more than one channel (more than one analogue
input) to be connected to the ADC