📄 digital.c
字号:
/***************************************************************************
FILE NAME: DIGITAL.C
FILE DESCRIPTION: DIGITAL (Digital I/O)
Sample program that demonstrates how to program digital I/O
Sample program that demonstrates how to read and write the digital I/O.
The program constantly displays the value of the lines on the input port
in the center of the screen. You can enter a value to be sent to the
output port. Wiring the input port lines to the corresponding output
port lines will allow you to change the output lines and view the changes
at the same time.
PROJECT NAME: DIGITAL (Part of DM6430 DOS Driver)
DRIVER VERSION: 1.1
COMPILER: Borland C++ 3.1
TARGET: Real-Mode DOS
Copyright 2003 RTD Embedded Technologies
***************************************************************************/
#include <conio.h>
#include <dos.h>
#include "drvr6430.h"
#include "dio5812.h"
/***************************************************************************
Defines
Change these constants to alter the program parameters.
****************************************************************************/
#define BASE_ADDRESS 768 // Base address of DM6430.
/***************************************************************************
SetProgramScreen()
The SetProgramScreen function initializes the screen.
****************************************************************************/
void SetProgramScreen(void)
{
clrscr();
// Print header and footer.
gotoxy(1,1); cprintf(TitleString6430());
gotoxy(50, 1); cprintf("Digital I/O");
gotoxy(1, 25); cprintf("Press <Esc> to exit. . .");
// Define data window and print labels for the samples.
window(1, 3, 80, 23);
gotoxy(32, 8); cprintf("IN: ");
gotoxy(1, 21); cprintf("Enter value to output (<Esc> to exit): ");
} //SetProgramScreen
int main(void)
{
char C; // Variable for editing output data.
unsigned int DOData; // Data to Digital output.
int ExitProgram; // Exit condition variable.
SetProgramScreen();
SetBaseAddress(BASE_ADDRESS);
InitBoard6430(); // Board initializing.
SetPort0Direction5812(0, 0); // Initializing port 0 for input.
SetPort1Direction5812(0, 1); // Initializing port 1 for output.
ExitProgram = 0;
while (!ExitProgram) { // Run untill <Esc> is pressed.
gotoxy(35, 8); cprintf( "%6d", ReadDIO5812(0, 0) );
// Read the digital input lines.
if (kbhit()) { // If key pressed get value to output.
C = getch();
if (C == 27) // If <Esc> then quit.
ExitProgram = 1;
else if ((C >= 0x30)
& (C <= 0x39)) // C is a digit.
{
gotoxy(42, 21); // Edit digital output data.
putch(C);
ungetch(C);
cscanf("%d", &DOData);
gotoxy(42, 21); clreol();
WriteDIO5812( 0, 1, DOData ); // Write data to digital output.
} //if
} //if
} //while
window(1,1,80,25); // Reset original screen coordinates,
clrscr(); // and clear the screen.
return 0;
} //main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -