To generate an output on Breadboard using parallel port.

This is a discussion on To generate an output on Breadboard using parallel port. within the C Programming forums, part of the General Programming Boards category; Hello guys. I am a low programmer I gont know too much about programming so I need your help. I ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    To generate an output on Breadboard using parallel port.

    Hello guys.
    I am a low programmer I gont know too much about programming so I need your help.
    I have to generate a program which turn on and turn off 10 LEDS in ascending order on bread board using PARALLEL PORT. The problem is parallel port only give 8 bits and I have to get result on 10 bits. I have used DEMULTIPLEXER (74HC138N) to get 10 bits. I have joine D0-D8 from LEDS D9 from demultiplexer and then 3 LEDS from DEMULTIPLEXER's leg.
    I hope someone will come up with a working program.
    Thankyou in advance.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,639
    That someone needs to be you -- you aren't going to learn otherwise. Read the site's homework policy. Then, make an attempt, post your code (read this first) and ask specific questions. You will find us much more willing to help.

    Also, it often helps if you give us the uC you're using and any relevant circuit schematics for problems like this.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,747
    You are going to have to break this problem into hardware and software parts.

    The software needs to output values ?,?,? in order to the output port.

    What is the hardware? Note, we are NOT assuming PCs if PC state that.

    Tim S.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Quote Originally Posted by chip manual page
    74HC138; 74HCT138
    3-to-8 line decoder/demultiplexer; inverting

    1. The 74HC138; 74HCT138 decoder accepts three binary weighted address inputs (A0, A1
    and A3) and when enabled, provides 8 mutually exclusive active LOW outputs (Y0 to Y7).

    2. The 74HC138; 74HCT138 features three enable inputs: two active LOW (E1 and E2) and
    one active HIGH (E3). Every output will be HIGH unless E1 and E2 are LOW and E3 is
    HIGH.
    Para 1 takes up 3 bits from your parallel port.
    Para 2 takes up 1 bit from your parallel port.
    For that, you can drive 8 LEDs.

    You have 4 bits left to drive 2 more LEDs.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Salem I am going for the first step that is I will take 3 inputs and generate 8 outputs and 2 more outputs from the parallel port.
    I created this program for 8 leds directly connected from parallel port and giving me 8 bits result. I'll be thankful to you guys if you guys can help me out to generate 10 bits result.
    Here is my program for 8 bit.

    # include <stdio.h>
    void main ()
    {
    int leds[9] = {0,1,2,4,8,16,32,64,128};
    int i=1;
    for (i=0;i<9;i++)
    {
    printf("\n%d",leds[i]);
    outportb(0x378,leds[i]);
    sleep(1);
    }
    }

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    You seem to have mastered [b][/b] tags for code, how about actually using [code][/code] tags instead?

    Also, you need to SHOW us your hardware circuit diagram, showing how you wired up your 74HC138 to your parallel port pins.

    I'm not going to guess you put it on pins 4 to 7 (and write a program for it), only for you to come back saying it still doesn't work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by hamxakhan View Post
    Salem I am going for the first step that is I will take 3 inputs and generate 8 outputs and 2 more outputs from the parallel port.
    I created this program for 8 leds directly connected from parallel port and giving me 8 bits result. I'll be thankful to you guys if you guys can help me out to generate 10 bits result.
    Here is my program for 8 bit.

    Code:
    #include <stdio.h>
    void main ()
    {
    int leds[9] = {0,1,2,4,8,16,32,64,128};
    int i=1;
    for (i=0;i<9;i++)
    {
    printf("\n%d",leds[i]);
    outportb(0x378,leds[i]);
    sleep(1);
    }
    }
    At this point it would likely be easier to redo your breadboard with a 74HC154 which is 4 lines in and 16 mutually exclusive outputs. You would be using only 4 bits of your port and it would be much easier to drive software wise... If you only need 10 leds, just leave a few open outputs and test your output values in software to be less than or simply use %10 to have the output value wrap around from 0 to 9...

    Code:
    outportb(0x378, leds[i] % 10);
    I believe the 74HC154 can be had for less than $2.00cdn. so that shouldn't be a problem.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,639
    You didn't read the link I posted that discusses code tags, did you...please put your code in code tags and indent it properly.

    Your code doesn't allow multiple bits on your parallel port to be active at the same time, which means you can't actually address your demuxer in a meaningful way. You wan't to use only 3 bits to generate numbers 0-7. The 3 bits represent A0-A2, and the output numbers Y0-7. If you're familiar with binary numbers, then you realize that binary to decimal gives something like:
    000 = 0 <-- LED 0 on Y0
    001 = 1 <-- LED 1 on Y1
    010 = 2
    011 = 3
    ...
    111 = 7 <-- LED 7 on Y7

    Those 3 output bits will allow you to address the 8 outputs of your demuxer. You can use the 3 low-order bits (call them b0 - b2) of your parallel port data for this. You can then use b3 and b4 for the other two LEDs, and b5 for your enable. You could use an array like you are currently doing to map LED numbers to parallel port outputs. For example, to turn on LED 3, you would give the following output (where x means "don't care"):
    x x 1 0 0 0 1 1

    Convert that to hex, and you get 0x23 (I'm using 0's for x). Thus, your array would look something like:
    int led[10] = {..., 0x23, ...};

    Then, to turn on LED 3, you would call:
    outportb(0x378, led[3]);

    Note that because of the active low outputs of the demuxer, and the fact that I don't have a schematic, you may need to invert b0-b2 to get the desired output.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parallel Port: Sending the signals as binary
    By h3ro in forum Tech Board
    Replies: 7
    Last Post: 08-25-2007, 01:22 PM
  2. troubleshooting on parallel port
    By year2038bug in forum Tech Board
    Replies: 4
    Last Post: 11-04-2005, 11:46 AM
  3. Output to parallel port
    By samuraijack in forum C Programming
    Replies: 3
    Last Post: 01-27-2003, 04:55 AM
  4. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  5. Help needed: Output to Parallel port.
    By Ingsy in forum C Programming
    Replies: 4
    Last Post: 10-10-2001, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21