#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORT1 0x2E8 /* Port Address Goes Here */
/* Defines Serial Ports Base Address */
/* COM4 0x2E8 */
#define INTVECT 0x0B /* Com Port's IRQ here */
/* (Must also change PIC setting) */
int bufferin = 0;
int bufferout = 0;
char ch;
char buffer[1025];
void interrupt PORT1INT() /* 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 for */
/* later recovery */
setvect(INTVECT, PORT1INT); /* Set Interrupt Vector Entry */
/* COM1 - 0x0C */
/* COM2 - 0x0B */
/* COM3 - 0x0C */
/* COM4 - 0x0B */
outportb(PORT1 +3 , 0x80); /* SET DLAB ON */
outportb(PORT1 +0, 0x03); /* Set Baud rate - Divisor Latch Low Byte */
/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 56,700 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) & 0xF7)); /* 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("\nSample Comm's Program. Press ESC to quit \n");
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) | 0x08)); /* MASK IRQ using PIC */
/* COM1 (IRQ4) - 0x10 */
/* COM2 (IRQ3) - 0x08 */
/* COM3 (IRQ4) - 0x10 */
/* COM4 (IRQ3) - 0x08 */
setvect(INTVECT, oldport1isr); /* Restore old interrupt vector */
}
所以我必须使用COM4串口将一些数据从UART发送到UART,我这里有一个小程序作为例子但是无法弄清楚为什么我不能在Visual Studion中编译它(C ++ Win32项目)
有什么想法吗?我还必须使用RQ3实现一个计时器。
答案 0 :(得分:0)
无法编译,因为操作系统会管理对硬件的访问。您的示例在第一行说明了它适用的操作系统,而不是Windows。
至于你的第二个主张,你没有。 IRQ3不用于Windows程序中的计时器。 StackOverflow上有很多关于计时器的答案,所以先检查一下。