| | |
UART problem!
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
Hello I'm doing a program about UART in Borland C. And I have a few questions. This is the code:
The program reads char data from the COM1 port, and finds if there's any errors.
My question is how to simplify this program, or write it in different way. I need to present two different codes and I don't have idea for the second one.
Thanks!!!
C Syntax (Toggle Plain Text)
#include <iostream.h> #include <dos.h> #include <conio.h> #include <stdio.h> #define COM1 0x3F8 int main(void) { clrscr(); // outportb( COM1 + 1, 0 ); outportb( COM1 + 3, 0x83); outportb( COM1, 0x0C); outportb( COM1 + 1, 0x00); outportb( COM1 + 3, 0x03); char ans; char readValue; do { readValue = inportb( COM1 + 5 ); if ( readValue & 0x80 ) { printf("ERROR!"); continue; } if ( readValue & 1 ) { readValue = inportb( COM1 ); printf("%c", readValue); } if ( kbhit() ) { ans = getch(); outportb( COM1, ans ); } } while ( ans != 27 ); return 0; }
My question is how to simplify this program, or write it in different way. I need to present two different codes and I don't have idea for the second one.
Thanks!!!
0
#2 27 Days Ago
Does the second program have to do the same thing as the first but must be written differently?
You could always do a switch on
You could always do a switch on
readValue instead of the if tree. ![]() |
Other Threads in the C Forum
- Previous Thread: Pthread support in Vxworks
- Next Thread: 32 bits/64 bits case
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






