Results 1 to 4 of 4

Thread: Toggle command question


\n
\nMy question is why do the LEDs change state outside of the for/next loop?
\n
\nOther than power, the connections shown are the only things connected to the 16F877A.
\n
\n
\n
\r\n
Code:
\r\n
\'*  Notes   : Transfer of data in BCD format from a 16f877 to   *\n\'*          : 7300 and 7340 LED assemblies                      *\n\'           : has added LED on pin 19 and 20 to make sure       *\n‘           :program is running                                 *        \n\'****************************************************************\n\'16f877A       7300/7340\n\'port/pin          pin/BCD digit\n\'A0/pin 2-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-8/A\n\'A1/pin 3-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-1/B\n\'A2/pin 4-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-2/C\n\'A3/pin 5-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-3/D\n\'E0/pin 8-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-5/Latch Enable\n\'D0/pin 19 +LED to GND -LED\n\'D1/pin 20 +LED to GND -LED\n\'OSC1/pin13 Crystal to pin 14 and 22pf cap to ground\n\'OSC2/pin14 Crystal to pin 13 adn 22pf cap to ground\n \nclear \ndefine osc4 \' set oscillator to 4 MHz\n \n\'-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-fuses\n \ncmcon = 7 \' comparators off\nadcon0 = %11000000 \' adc off\nadcon1 = %10000111 \' sets ports to digital\n\'-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-set ports\n \ntrisa = %00000000 \' sets trisa as output\ntrise = %11111110 \' sets bit0 of trise as output - only has 3 ports on trise\ntrisd = %00000000 \' sets portd as output\n\'-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-variables\n \noutputnumber var byte\ndisplaydigit var byte\nmax_number var byte\nmin_number var byte\nlatch_enable var porte.0 \'pin 8 on 16f877a\n \nmax_number = 15\nmin_number = 0\nmain:\ntoggle portd.1\ntoggle portd.0 \nfor outputnumber = min_number to max_number \' generate a number to be displayed\n    displaydigit = outputnumber \' give that number to the display variable\n    porta = displaydigit \' set port output to effectively BCD\n    toggle latch_enable \'toggle display to make it work\n    pause 500 \' wait 1/2 second\nnext outputnumber\n \nif outputnumber = max_number then outputnumber = min_number\n \ngoto main\n \nend
\r\n
\r\n \r\n
\r\n\r\n \r\n\r\n\r\n
\r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n Reply With Quote Reply With Quote \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n\r\n'; pd[111075] = '\r\n
  • \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n #2\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n\r\n
    \r\n
    \r\n \r\n \r\n \r\n Demon\'s Avatar\r\n \r\n \r\n \r\n
    \r\n \r\n
    \r\n Demon\r\n \r\n
    \r\n\r\n Demon is offline\r\n\r\n \r\n \r\n Moderator\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n \r\n
    \r\n
    \r\n
    Join Date
    Jan 2005
    \r\n
    Location
    Montreal, Quebec, Canada
    \r\n \r\n
    Posts
    1,184
    \r\n \r\n
    \r\n \r\n \r\n
    \r\n \r\n
    \r\n
    \r\n\r\n
    \r\n \r\n
    \r\n \r\n

    \r\n Default Re: Toggle command question\r\n

    \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n Moved from Code Examples.
    \n
    \nRobert\r\n
    \r\n
    \r\n\r\n \r\n\r\n\r\n
    \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n \r\n Reply With Quote Reply With Quote \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n
  • \r\n'; pd[111346] = '\r\n
  • \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n #3\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n\r\n
    \r\n
    \r\n \r\n \r\n \r\n Charlie\'s Avatar\r\n \r\n \r\n \r\n
    \r\n \r\n
    \r\n Charlie\r\n \r\n
    \r\n\r\n Charlie is offline\r\n\r\n \r\n \r\n Registered User\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n \r\n
    \r\n
    \r\n
    Join Date
    Dec 2010
    \r\n \r\n \r\n
    Posts
    164
    \r\n \r\n
    \r\n \r\n \r\n
    \r\n \r\n
    \r\n
    \r\n\r\n
    \r\n \r\n
    \r\n \r\n

    \r\n Default Re: Toggle command question\r\n

    \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n Looks like it should work.... have you remembered to disable the watchdog timer and anything else that could cause an unscheduled reset?\r\n
    \r\n
    \r\n\r\n \r\n\r\n\r\n
    \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n \r\n Reply With Quote Reply With Quote \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n
  • \r\n'; pd[111353] = '\r\n
  • \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n #4\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n\r\n
    \r\n
    \r\n \r\n \r\n \r\n Darrel Taylor\'s Avatar\r\n \r\n \r\n \r\n
    \r\n \r\n
    \r\n Darrel Taylor\r\n \r\n
    \r\n\r\n Darrel Taylor is offline\r\n\r\n \r\n \r\n Moderator / meLabs Support\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n \r\n
    \r\n
    \r\n
    Join Date
    Jul 2003
    \r\n
    Location
    Colorado Springs
    \r\n \r\n
    Posts
    4,759
    \r\n \r\n
    \r\n \r\n \r\n
    \r\n \r\n
    \r\n
    \r\n\r\n
    \r\n \r\n
    \r\n \r\n

    \r\n Default Re: Toggle command question\r\n

    \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n \r\n trise = %11111110 \' sets bit0 of trise as output - only has 3 ports on trise\r\n \r\n
    \r\n
    \r\n
    Like your comment said, PORTE only has 3 pins in that PORT.
    \nBy setting the upper bits of TRISE to all 1\'s, you have turned on the "Parallel Slave Port" (PSP) which affects PORTD.\r\n
    \r\n
    \r\n\r\n \r\n\r\n\r\n
    \r\n \r\n\r\n \r\n \r\n \r\n
    DT
    \r\n
    \r\n \r\n\r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n \r\n \r\n \r\n \r\n \r\n Reply With Quote Reply With Quote \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n
    \r\n
    \r\n
    \r\n
  • \r\n'; // next/previous post info pn[110799] = "111353,111075"; pn[0] = ",110799"; pn[111075] = "110799,111346"; pn[111346] = "111075,111353"; pn[111353] = "111346,110799"; // cached usernames pu[0] = guestphrase; pu[14248] = "AvionicsMaster1"; pu[785] = "Demon"; pu[15260] = "Charlie"; pu[109] = "Darrel Taylor"; // -->

    Threaded View

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

      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.


      Hi, we are pleased to see that you are using our forum.

      We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

      Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.






      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

    Members who have read this thread : 3

    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