473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

pc based digital clock via parallel port using c language

How are you every one?

I have this project and I already have a code and the circuit, but I studied assembly language it's supposed to display the hours and minutes.

Does any one know assembly and c language?

Here's the code:


Expand|Select|Wrap|Line Numbers
  1. TITLE CLOCK.ASM
  2.     DOSSEG
  3.     .MODEL SMALL
  4.     .STACK 0100H
  5.     .DATA
  6.     PRINTERPORTBASEADDRESS equ 378h
  7.  
  8.     .CODE
  9.     MAIN PROC
  10.     MOV AX, @DATA
  11.     MOV DS, AX
  12.  
  13.     CALL RTIME ; READ TIME
  14.     CALL DisplayTime ;DISPLAY TIME
  15.  
  16.     MOV AX, 4C00H
  17.     INT 21H
  18.     MAIN ENDP
  19.  
  20.     RTIME PROC
  21.     MOV AH, 02H
  22.     INT 1AH
  23.     RET
  24.  
  25.     ; CH - HOUR
  26.     ; CL - MINUTES
  27.     ; DH - SECONDS
  28.     RTIME ENDP
  29.  
  30.     DisplayTime PROC
  31.     push DX ; was DH
  32.     push CX ; was CL
  33.     ;
  34.     mov AL,CH
  35.     mov DX,PRINTERPORTBASEADDRESS
  36.     out DX,AL
  37.     mov AL,01h
  38.     mov DX,PRINTERPORTBASEADDRESS+2
  39.     out DX,AL ; enable display
  40.     call Delay
  41.     ;
  42.     mov AL,00h
  43.     mov DX,PRINTERPORTBASEADDRESS+2
  44.     out DX,AL
  45.     pop AX ; pop CL (minutes)
  46.     mov DX,PRINTERPORTBASEADDRESS
  47.     out DX,AL
  48.     mov AL,02h
  49.     mov DX,PRINTERPORTBASEADDRESS+2
  50.     out DX,AL ; enable display
  51.     call Delay
  52.     ;
  53.     mov AL,00h
  54.     mov DX,PRINTERPORTBASEADDRESS+2
  55.     out DX,AL
  56.     pop AX ; pop DH (seconds)
  57.     mov AL,AH
  58.     mov DX,PRINTERPORTBASEADDRESS
  59.     out DX,AL
  60.     mov AL,08h
  61.     mov DX,PRINTERPORTBASEADDRESS+2
  62.     out DX,AL ; enable display
  63.     call Delay
  64.     ;
  65.     mov DX,PRINTERPORTBASEADDRESS+2
  66.     mov AL,00h
  67.     out DX,AL
  68.     ret
  69.  
  70.     DisplayTime ENDP
  71.  
  72.     Delay Proc
  73.     MOV CX, 00100h
  74.     X: PUSH CX
  75.     MOV CX, 0FFFFh
  76.     Y: LOOP Y
  77.     POP CX
  78.     LOOP X
  79.     RET
  80.  
  81.     Delay ENDP
  82.     END
Thank you for your time.

This is the circuit diagram

http://www.electvillage.com/upload//...adbd174136.png
Dec 11 '12 #1
7 3450
donbock
2,426 Expert 2GB
Is there a problem with this assembly language program?
Dec 11 '12 #2
But there's small problem with minutes don't work probably
Thank you for time and writing comment
Dec 13 '12 #3
Expand|Select|Wrap|Line Numbers
  1.  
  2. #define A 0
  3. #define B 1
  4. #define C 2
  5. #define D 3
  6. #define E 4
  7. #define F 5
  8. #define G 6
  9.  
  10. typedef struct {int seg[7];} digit_t;
  11.  
  12. digit_t disp[4];
  13. /*
  14.  *  AAAA
  15.  * F    B
  16.  * F       B
  17.  *  GGGG
  18.  * E    C
  19.  * E       C
  20.  *  DDDD
  21.  */
  22.  
  23. digit_t int2segs[10] = {
  24. /* A  B  C   D  E  F   G */  
  25.   {1, 1, 1,  1, 1, 1,  0},  /* 0 */
  26.   {0, 1, 1,  0, 0, 0,  0},  /* 1 */
  27.   {1, 1, 0,  1, 1, 0,  1},  /* 2 */
  28.   {1, 1, 1,  1, 0, 0,  1},  /* 3 */
  29.   {0, 1, 1,  0, 0, 1,  1},  /* 4 */
  30.   {1, 0, 1,  1, 0, 1,  1},  /* 5 */
  31.   {1, 0, 1,  1, 1, 1,  1},  /* 6 */
  32.   {1, 1, 1,  0, 0, 0,  0},  /* 7 */
  33.   {1, 1, 1,  1, 1, 1,  1},  /* 8 */
  34.   {1, 1, 1,  1, 0, 1,  1}   /* 9 */
  35. };
  36.  
  37. void print_dig (digit_t d, char *name)
  38. {
  39.     int i;
  40.  
  41.     printf("%s\n", name);
  42.     for (i=0; i < 7; i++) {
  43.     printf("   Segment %c : %6d\n", 'A'+ i, d.seg[i]);
  44.     }
  45. }
  46.  
  47. void display_dig (digit_t *d, int n)
  48. {
  49.     digit_t symbol;
  50.     int i;
  51.  
  52.     if (n > 9) {
  53.     printf("\n error digit too large \n");
  54.         exit(1);
  55.     }
  56.     symbol = int2segs[n];
  57.  
  58.     for (i=0; i < 7; i++) {
  59.     d->seg[i] += symbol.seg[i];    /* Add value for this tick */
  60.     }
  61. }
  62.  
  63. void display(int h, int m, int s)
  64. {
  65.     int m1, m10, h1, h10;
  66.  
  67.     m1 = m%10;                /* get individual digits */
  68.     m10 = m/10;
  69.     h1 = h%10;
  70.     h10 = h/10;
  71.  
  72.     if (h10 > 0)            /* leading zero supression */
  73.     display_dig(&disp[0], h10);
  74.     display_dig(&disp[1], h1);
  75.     display_dig(&disp[2], m10);
  76.     display_dig(&disp[3], m1);
  77. }
  78.  
  79. main()
  80. {
  81.     int hour, min;
  82.  
  83.     for (hour = 1; hour <= 12; hour++) {
  84.     for (min = 0; min < 60; min++) {
  85.         display(hour, min, 0);
  86.     }
  87.     }
  88.     print_dig(disp[0], "Hours Tens");
  89.     print_dig(disp[1], "Hours Ones");
  90.     print_dig(disp[2], "Minutes Tens");
  91.     print_dig(disp[3], "Minutes Ones");
  92. }

Is there any problem if I use it for my project ??
Dec 15 '12 #4
zmbd
5,501 Expert Mod 4TB
loloysh
Just what is it that you're asking?
Are you having errors with this?
Dec 16 '12 #5
donbock
2,426 Expert 2GB
I assume the assembly language in your initial post is for an x86-style microprocessor. The x86 architecture allows for both memory-mapped I/O and port I/O. The OUT command used in lines 36,39,44,47,50,55,59,62,67 of the assembly-language program performs port output. Unfortunately for you, port I/O is incompatible with Standard C -- no combination of C instructions will induce the compiler to emit an OUT command. You either need a nonstandard compiler extension or your C program needs a way to invoke explicit assembly language instructions. There are two ways for C code to invoke explicit assembly language instructions: inline via the asm keyword or through a C-callable assembly language subroutine.

These are advanced topics. It would help me to know your familiarity with x86 assembly and C before I go into more detail.

@loloysh: did you write these two programs or are you trying to understand code that somebody else wrote?
Dec 16 '12 #6
donbock
2,426 Expert 2GB
It isn't such an advanced topic if your compiler provides a nonstandard library function that does the hard part for you. The following functions are part of the MSDN run-time library (assuming your program executes in a Microsoft environment).
Expand|Select|Wrap|Line Numbers
  1. #include <conio.h>
  2. int _outp(
  3.    unsigned short port,
  4.    int databyte 
  5. );
  6. unsigned short _outpw(
  7.    unsigned short port,
  8.    unsigned short dataword 
  9. );
  10. unsigned long _outpd(
  11.    unsigned short port,
  12.    unsigned long dataword 
  13. );
The original assembly language program does a few more tricky things that you need to handle properly in C:
  • Line 17: INT 21H
  • Line 22: INT 1AH
  • Lines 72-81: Delay Proc
Dec 16 '12 #7
donbock
2,426 Expert 2GB
The link to the circuit diagram wants to install a driver before it will show me the diagram ... I'm not willing to do that. Please describe the important parts of the circuit:
  1. Does each data bit drive a segment of the display or does your circuit include a binary/BCD-to-segment converter?
  2. If each data bit drives a segment, then are the data bits active high or active low?
  3. For each digit of the display, what control signal strobes that digit; and is the strobe active high or active low?
  4. What is the minimum width of the strobe pulses?
Dec 16 '12 #8

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

Similar topics

4
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
0
by: Loui Mercieca | last post by:
Hi I have read and tried the tutorial from the msdn at http://support.microsoft.com/default.aspx?scid=kb;en-us;823179&Product=vb6 which i really suggest regarding the serial and parallel port. ...
1
by: charles8000 | last post by:
Hi, I have trouble writing on parallel port using C++. It's been years I have worked with C++, I would need files to use as examples. Thank you for helping... ...
2
by: Wouter van Teijlingen | last post by:
Dear Readers, I was reading about how to control the COM and LPT port using VB .NET. I've found a lot of information, and it was very useful to me. I found an example program on the site of...
1
by: stephanier | last post by:
hello!!! i`m working in a proyect and i need to read the parallel port using assembly... i have searched in the internet, but did not find any usefull information... can someone help me??......
6
by: abhi | last post by:
Hello, I want to create a small project which will display scrolling text on LED that will be attached to Parallel port. I want to create this project in C language(possibly in Mingw) on Windows...
1
by: mravichandran82 | last post by:
Hi Friends, I need a detailed discusion and a good example about, how to read parallel port input and output to parallel port through java source code. If u send as mail then I thank u so...
3
by: jasmeetqwertyqwertyqwerty | last post by:
how to interfere with parallel port using c++ and how to program a robot using c++ code .can any1 also send me a program in c++....m new here i hope u will help. Thnx in advance. cya
1
by: abhinav7777 | last post by:
Hi!! I'm Final Year Student(CS).. I'm developing a project which is a prototype of a SPY Vehicle.. I want to know how to access parallel port using C/C++ , VB.Net or Java. Anybody having...
1
by: ssndk123 | last post by:
Hi, Using the UserPort program that changes permissions in XP so that I am able to write directly to the parallel port using assembler.. I'm trying to send out square wave pulses for x number...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.