UART problem!

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 40
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster

UART problem!

 
0
  #1
Oct 31st, 2009
Hello I'm doing a program about UART in Borland C. And I have a few questions. This is the code:
  1. #include <iostream.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5.  
  6. #define COM1 0x3F8
  7.  
  8. int main(void)
  9. {
  10. clrscr();
  11.  
  12. // outportb( COM1 + 1, 0 );
  13. outportb( COM1 + 3, 0x83);
  14. outportb( COM1, 0x0C);
  15. outportb( COM1 + 1, 0x00);
  16. outportb( COM1 + 3, 0x03);
  17.  
  18. char ans;
  19. char readValue;
  20.  
  21. do
  22. {
  23.  
  24. readValue = inportb( COM1 + 5 );
  25.  
  26. if ( readValue & 0x80 )
  27. {
  28. printf("ERROR!");
  29. continue;
  30. }
  31.  
  32. if ( readValue & 1 )
  33. {
  34. readValue = inportb( COM1 );
  35. printf("%c", readValue);
  36. }
  37.  
  38. if ( kbhit() )
  39. {
  40. ans = getch();
  41. outportb( COM1, ans );
  42. }
  43.  
  44.  
  45. } while ( ans != 27 );
  46.  
  47.  
  48. return 0;
  49.  
  50. }
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!!!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,873
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 56
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
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 readValue instead of the if tree.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 40
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster
 
0
  #3
Oct 31st, 2009
Yes the second one should do the same as the first one, only I need it written with different commands or simply in different way.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 40
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster
 
0
  #4
Nov 3rd, 2009
Can someone give me some example?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 350 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC