By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

paralell port: I have got few errors on this piece of code below, please help

P: 6
Expand|Select|Wrap|Line Numbers
  1. #include <dos.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <time.h>
  5.  
  6. #define PORTADDRESS 0x378 /* Enter Your Port Address Here */
  7.  
  8. #define DATA PORTADDRESS+0
  9. #define STATUS PORTADDRESS+1
  10. #define CONTROL PORTADDRESS+2
  11.  
  12. void lcd_init(void);
  13. void lcd_write(char char2write);
  14. void lcd_putch(char char2write);
  15. void lcd_puts(char * str2write);
  16. void lcd_goto(int row, int column);
  17. void lcd_clear(void);
  18. void lcd_home(void);
  19. void lcd_cursor(int cursor);
  20. void lcd_entry_mode(int mode);
  21.  
  22.  
  23. void main(void)
  24. {
  25. lcd_init();
  26. lcd_goto(1,1);
  27. lcd_puts("Welcome To");
  28. lcd_goto(1,0);
  29. lcd_puts("electroSofts.com");
  30.  
  31. while(!kbhit() ) //wait until a key is pressed...
  32. {}
  33.  
  34. }
  35.  
  36. void lcd_init()
  37. {
  38.  
  39. outportb(CONTROL, inportb(CONTROL) & 0xDF);
  40. //config data pins as output
  41.  
  42. outportb(CONTROL, inportb(CONTROL) | 0x08);
  43. //RS is made high: control (register select)
  44.  
  45. lcd_write(0x0f);
  46. delay(20);
  47. lcd_write( 0x01);
  48. delay(20);
  49. lcd_write( 0x38);
  50. delay(20);
  51.  
  52. }
  53.  
  54. void lcd_write(char char2write)
  55. {
  56.  
  57. outportb(DATA, char2write);
  58. outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
  59. delay(2);
  60. outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
  61. delay(2);
  62.  
  63. }
  64.  
  65. void lcd_putch(char char2write)
  66. {
  67.  
  68. outportb(CONTROL, inportb(CONTROL) & 0xF7);
  69. //RS=low: data
  70. lcd_write(char2write);
  71.  
  72. }
  73.  
  74. void lcd_puts(char *str2write)
  75. {
  76.  
  77. outportb(CONTROL, inportb(CONTROL) & 0xF7);
  78. //RS=low: data
  79. while(*str2write)
  80. lcd_write(*(str2write++));
  81.  
  82. }
  83.  
  84. void lcd_goto(int row, int column)
  85. {
  86.  
  87. outportb(CONTROL, inportb(CONTROL) | 0x08);
  88. if(row==2) column+=0x40;
  89. /* Add these if you are using LCD module with 4 columns
  90. if(row==2) column+=0x14;
  91. if(row==3) column+=0x54;
  92. */
  93. lcd_write(0x80 | column);
  94.  
  95. }
  96.  
  97. void lcd_clear()
  98. {
  99.  
  100. outportb(CONTROL, inportb(CONTROL) | 0x08);
  101. lcd_write(0x01);
  102.  
  103. }
  104.  
  105. void lcd_home()
  106. {
  107.  
  108. outportb(CONTROL, inportb(CONTROL) | 0x08);
  109. lcd_write(0x02);
  110.  
  111. }
  112.  
  113. void lcd_entry_mode(int mode)
  114. {
  115.  
  116. /*
  117. if you dont call this function, entry mode sets to 2 by default.
  118. mode: 0 - cursor left shift, no text shift
  119. 1 - no cursor shift, text right shift
  120. 2 - cursor right shift, no text shift
  121. 3 - no cursor shift, text left shift
  122. */
  123. outportb(CONTROL, inportb(CONTROL) | 0x08);
  124. lcd_write(0x04 + (mode%4));
  125.  
  126. }
  127.  
  128. void lcd_cursor(int cursor)
  129. {
  130.  
  131. /*
  132. set cursor: 0 - no cursor, no blink
  133. 1 - only blink, no cursor
  134. 2 - only cursor, no blink
  135. 3 - both cursor and blink
  136. */
  137.  
  138.  
  139. outportb( CONTROL, inportb(CONTROL) | 0x08 );
  140. lcd_write( 0x0c + (cursor%4));
  141.  
  142. }
  143.  
  144. --------------------------------------------------------------------------------
  145.  
Mar 16 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
using Turbo C V3.0 this code compiles and links OK

Have not tried to run it!

what is your problem?
Mar 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.