> Van: G345CDE > Aan: PICLIST@MITVMA.MIT.EDU > Onderwerp: Re: Reasonably simple schematics for PIC > Datum: woensdag 6 mei 1998 22:18 > > Hi: > I am trying to learn to program the 16C84..I have a programmer but need source > code for a few relatively simple circuits to practice on......a counter and 7 > seg. display counting to 9....anything that will help me visualize the > relationship of the code to circuit action. Open to all suggestions. Thanks > . Regards, George. Hello George, You can do two things : Use the PIC as a counter only (and decode your counter-value external with a 7447 or alike) or do both in the PIC (count and Binary-to-7Seg converson). Thinking you will do the latter (why use extra chips if you dont _have_ to :-) the hardware is shockingly simple : just connect segments 'a' thru 'g' and the 'dp' thru some resistors of 470 Ohm (1K Ohm if you got a High-brightness display) to the I/O lines 0 thru 7 of port B. This way you can turn every segment On-and-Off to your likings. I suggest to use a common Kathode display (the common pin connected to Ground). this way a '1' in the Output-data will turn a segement On. If you use a common Annode display (the common pin connected to VCC) a '0' will turn the segment on. Now the software : Put Port B int an Output by writing all zero's to the TRISB-register. (don't forget to set & clear STATUS,RPO to do this !). Now send any data to PORTB and your display will show the code (Try b'01101101' to get the number 5 on the display). To convert the values '0' thru '9' to the codes that will represent the numbers 0 thru 9 on your display you will have to do something like : clrf PCLATH ;Set the page your Bin7Seg-table is on movf COUNT,W ;Copy Counter-value to W call Bin7Seg ;Convert to 7-segment-code movwf PORTB ;Send it to your Hardware Bin7Seg: addwf PCL retlw b'????????' ;Code for a 7-segment '0' retlw b'????????' ;Code for a 7-segment '1' etc retlw b'01101101' ;Code for a 7-segment '5' etc retlw b'????????' ;Code for a 7-segment '9' Warning : The table has only got items 0 thru 9, so the value in W should _NOT_ exeed this max value. otherwise unexpected results will occur ! To see the next number : Advance COUNTER, call the Conversion-routine and send the result again to PORTB Don't forget to tell you program where you COUNTER variable is located (preferrably at the first free RAM-location, 0x0C) Greetz, Rudy Wieser P.s. Extend your Bin7Seg-table to 16 elements (and have a Hexa-Decimal display) and you could 'and' the upper nibble out so you can't get out of the table. Bin7Seg: andlw 0x0f addwf PCL retlw b'????????' ;Code for a 7-segment '0' etc retlw b'????????' ;Code for a 7-segment '15' (mostly the letter 'F')