\r\n Moved from Code Examples.\r\n
\n
\nRobert\r\n
\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
\'* 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
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'; pd[111075] = '\r\n
\r\n Moved from Code Examples.\r\n
\n
\nRobert\r\n
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'; pd[111346] = '\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
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'; pd[111353] = '\r\n
\r\n\r\n\r\nLike your comment said, PORTE only has 3 pins in that PORT.\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
\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\nDT
\r\n
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'; // 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"; // -->
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
Bookmarks