| | |
UART problem!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 40
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 Oct 31st, 2009
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
Views: 350 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






