Toggle command question


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Toggle command question

    The end result of what I'm trying to do is send BCD to portA so I can make a clock. I've started small with only one digit and a few LEDs and I'd like to know why something works as it does.

    The first two lines of the main program have portd.0 and portd.1 toggling LEDs outside of the for/next loop. I expected in the first go round of the program the two lights will come on and stay on until the for/next loop completes its count from 0 to 15. After the loop is completed I expected the lights to go off for the next iteration of the for/next loop count from 0 to 15.

    Actually the LEDs change state each time the for/next loop counts a digit. i.e. I've noticed the LEDs are on during the display of an odd number and off during the display of an even number.

    The digit displays I'm using are, I think, 8200-7300 and take BCD in and display a numeric/alpha character. The LEDs are something I had laying around and I don't know the part numbers.

    My question is why do the LEDs change state outside of the for/next loop?

    Other than power, the connections shown are the only things connected to the 16F877A.


    Code:
    '*  Notes   : Transfer of data in BCD format from a 16f877 to   *
    '*          : 7300 and 7340 LED assemblies                      *
    '           : has added LED on pin 19 and 20 to make sure       *
    ‘           :program is running                                 *        
    '****************************************************************
    '16f877A       7300/7340
    'port/pin          pin/BCD digit
    'A0/pin 2----------8/A
    'A1/pin 3----------1/B
    'A2/pin 4----------2/C
    'A3/pin 5----------3/D
    'E0/pin 8----------5/Latch Enable
    'D0/pin 19 +LED to GND -LED
    'D1/pin 20 +LED to GND -LED
    'OSC1/pin13 Crystal to pin 14 and 22pf cap to ground
    'OSC2/pin14 Crystal to pin 13 adn 22pf cap to ground
     
    clear 
    define osc4 ' set oscillator to 4 MHz
     
    '----------------------------------------------------------------fuses
     
    cmcon = 7 ' comparators off
    adcon0 = %11000000 ' adc off
    adcon1 = %10000111 ' sets ports to digital
    '-----------------------------------------------------------set ports
     
    trisa = %00000000 ' sets trisa as output
    trise = %11111110 ' sets bit0 of trise as output - only has 3 ports on trise
    trisd = %00000000 ' sets portd as output
    '---------------------------------------------------------------variables
     
    outputnumber var byte
    displaydigit var byte
    max_number var byte
    min_number var byte
    latch_enable var porte.0 'pin 8 on 16f877a
     
    max_number = 15
    min_number = 0
    main:
    toggle portd.1
    toggle portd.0 
    for outputnumber = min_number to max_number ' generate a number to be displayed
        displaydigit = outputnumber ' give that number to the display variable
        porta = displaydigit ' set port output to effectively BCD
        toggle latch_enable 'toggle display to make it work
        pause 500 ' wait 1/2 second
    next outputnumber
     
    if outputnumber = max_number then outputnumber = min_number
     
    goto main
     
    end

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Toggle command question

    Moved from Code Examples.

    Robert

  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Toggle command question

    Looks like it should work.... have you remembered to disable the watchdog timer and anything else that could cause an unscheduled reset?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Toggle command question

    trise = %11111110 ' sets bit0 of trise as output - only has 3 ports on trise
    Like your comment said, PORTE only has 3 pins in that PORT.
    By setting the upper bits of TRISE to all 1's, you have turned on the "Parallel Slave Port" (PSP) which affects PORTD.
    DT

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts