<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>8-bit MicrocontrollersのトピックRe: Driving a digital display using HCS08 MC9S08GB60</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207763#M17607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;It is an exact copy of my code. Ok well I will go back and edit my code and see what happens, I will also post it back up properly. Cheers&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Mar 2008 21:57:56 GMT</pubDate>
    <dc:creator>karmabobby</dc:creator>
    <dc:date>2008-03-28T21:57:56Z</dc:date>
    <item>
      <title>Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207761#M17605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fimg37.picoodle.com%2Fimg%2Fimg37%2F4%2F3%2F28%2Ff_7segmentdism_4b5dfa5.png" rel="nofollow" target="_blank"&gt;http://img37.picoodle.com/img/img37/4/3/28/f_7segmentdism_4b5dfa5.png&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am trying to drive a Digital display using the above schematic. I know how the circuit works, I am just having some trouble with C syntax...and well some of my code may well be wrong but I think I have given it a good attempt. It is meant to display 'EP2'. If anyone could help me just get the code working I would be very grateful. If anyone spots any glaring errors could someone please give me help with this. I am new to C and this course has thrown me in the deep end when it comes to programming.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */&lt;BR /&gt;#include "derivative.h" /* include peripheral declarations */&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;#define&amp;nbsp; E_Display 0x79&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Digital display for 'E'&lt;BR /&gt;#define&amp;nbsp; P_Display 0x73&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Digital display for 'P'&lt;BR /&gt;#define&amp;nbsp; Two_Display 0x57&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Digital display for '2'&lt;BR /&gt;#define&amp;nbsp; DP_Off 0x80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Used to turn Decimal Point off&lt;BR /&gt;#define&amp;nbsp; All_Off 0x00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Used to turn all bits off&lt;BR /&gt;#define&amp;nbsp; All_On&amp;nbsp; 0xFF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Used toturn all bits on&lt;BR /&gt;#define&amp;nbsp; Drive_Segment_Bus 0x3F&amp;nbsp;&amp;nbsp; //Used to drive the output&lt;BR /&gt;#define&amp;nbsp; Mask_Digits 0x03&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Masking bits 7-2 off '00000011'&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void main (void) {&lt;BR /&gt;//&amp;nbsp;SET DDRs for output ports&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;for (;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt;&amp;nbsp; //Repeat forever&lt;BR /&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Output_Seven_Segments(E_Display,1) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;delay(1);&amp;nbsp;//Call a delay subroutine&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Output_Seven_Segments(P_Display,2) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;delay(1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Output_Seven_Segments(Two_Display,3) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;delay(1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;}&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;void delay(long int n)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;long int i;&lt;BR /&gt;&amp;nbsp;unsigned int j;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;for (i=0; i&amp;lt;n; i++)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; for (j=0; j&amp;lt;100; j++)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {}&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;void Output_Seven_Segments (unsigned char segments, unsigned char digit)//this doesnt work!&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;segments == 0;&lt;BR /&gt;&amp;nbsp;digit == 0;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;//Remember: segments variable is formed as:&lt;BR /&gt;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DP g f e d c b a&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;if (digit==Two_Display)&amp;nbsp;&amp;nbsp; //This is the broken display&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;segments=FixDigit2(segments);&amp;nbsp;//Call a subroutine to mangle all bits&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PTFD == All_Off;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;TURN ALL DIGITS OFF&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; PTBD == Drive_Segment_Bus;//DRIVE SEGMENTS BUS with segments&amp;lt;6:0&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PTFD == Mask_Digits;//Mask digit bits &amp;lt;7:2&amp;gt; off, so we only end with bits &amp;lt;1:0&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;//(i.e. there are only 4 displays)&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;switch (PTFD) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;case 0:&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mask_Digits == 1;//Drive Most significant digit ON&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTFD == Mask_Digits;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;break;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;case 1:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mask_Digits == 2;//Drive Next digit ON&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTFD == Mask_Digits;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;break;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;case 2:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mask_Digits == 3;//Drive Least significan digit ON&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTFD == Mask_Digits;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;break;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;case 3:&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTAD == 0xFF; //Drive LED bar graph ON&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;break;&lt;BR /&gt;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;//Note: if your display is broken also include the following subroutine which is called to remangle the broken bits. Otherwise just look at how the routine shuffles bit around!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;unsigned char FixDigit2(unsigned char value) {&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; unsigned char newval;&lt;BR /&gt;&amp;nbsp; newval=0;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x01)&amp;lt;&amp;lt;6;&amp;nbsp;&amp;nbsp; //Bit 0 becomes 6&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x02)&amp;gt;&amp;gt;1;&amp;nbsp;&amp;nbsp; //Bit 1 becomes 0&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x04)&amp;lt;&amp;lt;5;&amp;nbsp; //Bit 2 becomes 7&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x40)&amp;gt;&amp;gt;4;&amp;nbsp; //Bit 6 becomes 2&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x80)&amp;gt;&amp;gt;6;&amp;nbsp; //Bit 7 becomes 1&lt;BR /&gt;&amp;nbsp; newval=newval|(value&amp;amp;0x38);&amp;nbsp; &amp;nbsp; //And bits 543 are copied undisturbed&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; return (newval);&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; for(;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __RESET_WATCHDOG(); /* feeds the dog */&lt;BR /&gt;&amp;nbsp; } /* loop forever */&lt;BR /&gt;&amp;nbsp; /* please make sure that you never leave main */&lt;BR /&gt;}&lt;BR /&gt;}&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:25 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:26 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:26 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:30 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:31 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:32 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by karmabobby on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-03-28&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:33 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 21:23:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207761#M17605</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-03-28T21:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207762#M17606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I haven't looked through all the code but taking a very quick glance you need to fix some problems.&amp;nbsp; Mainly you are mixing up "==" and '='.&amp;nbsp; The double equal sign "==" is a boolean operation, it returns true or false based on the evaulation of the left since equaling the value on the right side.&amp;nbsp; This is normally only when testing conditions in things like if statements, while loops, do while loops etc.&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Is this an exact copy of your code?&amp;nbsp; If not, copy and paste it using the source code function of the forums.&amp;nbsp; When you post, there is a button to the right of the bold, italics, underline and strike through buttons above the area where you type your text labeled "SRC".&amp;nbsp; Press this and a new window should open to let you post source code.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 21:50:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207762#M17606</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-03-28T21:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207763#M17607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;It is an exact copy of my code. Ok well I will go back and edit my code and see what happens, I will also post it back up properly. Cheers&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 21:57:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207763#M17607</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-03-28T21:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207764#M17608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#define  E_Display 0x79       //Digital display for 'E'#define  P_Display 0x73       //Digital display for 'P'#define  Two_Display 0x57       //Digital display for '2'#define  DP_Off 0x80          //Used to turn Decimal Point off#define  All_Off 0x00         //Used to turn all bits off#define  All_On  0xFF         //Used toturn all bits on#define  Drive_Segment_Bus 0x3F   //Used to drive the output#define  Mask_Digits 0x03         //Masking bits 7-2 off '00000011'    void main (void) { // SET DDRs for output ports     for (;;)  //Repeat forever {  Output_Seven_Segments(E_Display,1) ;  Delay(1); //Call a delay subroutine  Output_Seven_Segments(P_Display,2) ;  Delay(1);  Output_Seven_Segments(Two_Display,3) ;  Delay(1);                           }} void delay(long int n){ long int i; unsigned int j; for (i=0; i&amp;lt;n; i++)   for (j=0; j&amp;lt;100; j++)     {}}void Output_Seven_Segments (unsigned char segments, unsigned char digit){  segments = 0; digit = 0;   //Remember: segments variable is formed as: //        DP g f e d c b a if (digit==Two_Display)   //This is the broken display    segments=FixDigit2(segments); //Call a subroutine to mangle all bits  PTFD = All_Off;            // TURN ALL DIGITS OFF   PTBD = Drive_Segment_Bus;//DRIVE SEGMENTS BUS with segments&amp;lt;6:0&amp;gt;  PTFD = Mask_Digits;//Mask digit bits &amp;lt;7:2&amp;gt; off, so we only end with bits &amp;lt;1:0&amp;gt;   //(i.e. there are only 4 displays) switch (PTFD) {  case 0:            Mask_Digits == 1;//Drive Most significant digit ON        PTFD = Mask_Digits;    break;  case 1:           Mask_Digits == 2;//Drive Next digit ON        PTFD = Mask_Digits;    break;  case 2:           Mask_Digits == 3;//Drive Least significan digit ON        PTFD = Mask_Digits;    break;  case 3:         PTAD = 0xFF; //Drive LED bar graph ON    break; }   }//Note: if your display is broken also include the following subroutine which is called to remangle the broken bits. Otherwise just look at how the routine shuffles bit around! unsigned char FixDigit2(unsigned char value) {    unsigned char newval;  newval=0;    newval=newval|(value&amp;amp;0x01)&amp;lt;&amp;lt;6;   //Bit 0 becomes 6  newval=newval|(value&amp;amp;0x02)&amp;gt;&amp;gt;1;   //Bit 1 becomes 0  newval=newval|(value&amp;amp;0x04)&amp;lt;&amp;lt;5;  //Bit 2 becomes 7  newval=newval|(value&amp;amp;0x40)&amp;gt;&amp;gt;4;  //Bit 6 becomes 2  newval=newval|(value&amp;amp;0x80)&amp;gt;&amp;gt;6;  //Bit 7 becomes 1  newval=newval|(value&amp;amp;0x38);    //And bits 543 are copied undisturbed    return (newval);}  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */  /* please make sure that you never leave main */}}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Ok heres the source code. I am still having errors when it compiles.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 22:19:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207764#M17608</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-03-28T22:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207765#M17609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;You still have a for loop at the bottom that is not in any function.&amp;nbsp; This needs to be removed as well as the 2 end brackets after it.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am sure many people here could post code that does exactly what you want but I think it would be beneficial if you started with something&lt;/DIV&gt;&lt;DIV&gt;a bit more simple then worked yourself up to displaying EP2.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The code as it currently is can't turn on any of the segments, it can't turn anything on as you haven't configured any of the port pins as outputs.&lt;/DIV&gt;&lt;DIV&gt;To set these as inputs or outputs you have to write to PTXDD where X is the Port you want to set the data direction on.&amp;nbsp; Each bit of PTXDD&lt;/DIV&gt;&lt;DIV&gt;corresponds to one of the 8 pins on the port, but not all ports have all 8 pins.&amp;nbsp;All the pins&amp;nbsp;shown in the schematic should be setup as outputs.&lt;/DIV&gt;&lt;DIV&gt;Once oyu have set these as outputs, you then control if they are high or low by setting the according bit in PTXD where X is the port you&lt;/DIV&gt;&lt;DIV&gt;are accessing. From the schematic it isn't completely clear what port pins are going where.&amp;nbsp; For example, does PB1 refer to Port B pin&amp;nbsp;1 or&lt;/DIV&gt;&lt;DIV&gt;Port B pin 0?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Try getting back to basics and just turning on certain segments on one display first.&amp;nbsp; The code to do this should look something&amp;nbsp;like this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void main (void) {    // Set DDRs for output ports   PTADD = 0x01; // Replace XX with the hex value to set the PA2 and PA1 as outputs      PTFDD = 0x01; // Same here, setting the inputs/outputs for port F   PTBDD = 0x01; // Setting the input/outputs for Port B      PTFD = 0x01;  // Replace XX with the hex value to select the display you want to use   PTBD = 0x01;  // Replace XX with the hex value to turn on the segments you want   /* Port A shouldn't need to have anything done to it, it only controls the decimal     point and enables some other LED's according to the schematic*/   for (;;)  //Repeat forever   {   ;                         }}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2008 23:33:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207765#M17609</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-03-28T23:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207766#M17610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Ok I will have a look, thanks for pointing that out.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Mar 2008 17:49:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207766#M17610</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-03-29T17:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207767#M17611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Your code still has numerous problems, even after you fix the things that &lt;STRONG&gt;allawtterb&lt;/STRONG&gt; pointed out.&amp;nbsp; I&lt;BR /&gt;assume that your code has never compiled without warnings&amp;nbsp;and errors.&amp;nbsp; I will list a few of the issues&lt;BR /&gt;that I&amp;nbsp;observed.&amp;nbsp; However, I will leave it to you to find where the problem is located, and provide&amp;nbsp;the&lt;BR /&gt;correction.&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;You do not seem to have provided any function prototypes,&amp;nbsp;resulting in&amp;nbsp;some compile errors&lt;/LI&gt;&lt;LI&gt;In some instances, the name by which a function is called does not match the name by which the&lt;BR /&gt;function is defined, resulting in further compile warnings.&amp;nbsp; (Hint: C is case sensitive.)&lt;/LI&gt;&lt;LI&gt;In one instance, you have passed parameters to a function, and then immediately zeroed them&lt;BR /&gt;before the passed value has been used by the function.&lt;/LI&gt;&lt;LI&gt;Some of the macros that define constants do not match the port output allocations you have used&lt;BR /&gt;This would result in an incorrect display.&lt;/LI&gt;&lt;LI&gt;There does appear to be a lack of understanding of the purpose of using a switch/case statement&lt;BR /&gt;The manner in which you have used it does not make sense to me.&lt;/LI&gt;&lt;/OL&gt;&lt;DIV&gt;You will notiice that, with the present structure of your code, you will not be able to do anything else&lt;BR /&gt;except scan the display, unless you first blank the display.&amp;nbsp; This is because any disruption to the digit&lt;BR /&gt;timing will cause one digit to appear brighter than the other digits.&amp;nbsp; Ultimately you will most likely need to&lt;BR /&gt;use a periodic timer interrupt to display the next digit in the multiplexing sequence.&amp;nbsp; To minimize flicker,&lt;BR /&gt;for a 4-digit display, the period between interrupts should be less than 4 ms.&amp;nbsp; ( I have also categorized&lt;BR /&gt;the LED array as digit.)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Another suggestion is to set up a table (a constant array variable) containing the 7-segment configuration&lt;BR /&gt;for the numerals 0 to 9, and for each alphabetic you wiish to display.&amp;nbsp; This would provide more flexibility in&lt;BR /&gt;dynamically changing the contents of the display.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-03-30&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:33 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Mar 2008 21:29:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207767#M17611</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-29T21:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207768#M17612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I have looked at my code and have eliminated all of the errors. However I still am having big problems with switch statements.&amp;nbsp; Here is my code mixed with some psuedo code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include &amp;lt;stdio.h&amp;gt;#define  E_Display 0x79       //Digital display for 'E'#define  P_Display 0x73       //Digital display for 'P'#define  Two_Display 0x57       //Digital display for '2'#define  DP_Off 0x80          //Used to turn Decimal Point off#define  All_Off 0x00         //Used to turn all bits off#define  All_On  0xFF         //Used toturn all bits on#define  Drive_Segment_Bus 0x3F   //Used to drive the output#define  Mask_Digits 0x03         //Masking bits 7-2 off '00000011'    void delay(long int n){ long int i; unsigned int j; for (i=0; i&amp;lt;n; i++)   for (j=0; j&amp;lt;100; j++)     {}} void Output_Seven_Segments (unsigned char segments, unsigned char digit){   //Remember: segments variable is formed as: //        DP g f e d c b a if (digit==2)   //This is the broken display    segments=FixDigit2(segments); //Call a subroutine to mangle all bits  PTFD = All_Off;            // TURN ALL DIGITS OFF   PTBD = Drive_Segment_Bus;//DRIVE SEGMENTS BUS with segments&amp;lt;6:0&amp;gt;                          //mask variable digits with Mask_Digits variable switch (digits)  {  case 0:           //Drive most significant digit on   break;  case 1:            //Drive second digit on    break;  case 2:           //Drive least significant digit on          break;   case 3:           //Drive LED display on      break; }   }    void main (void) {    // Set DDRs for output ports   SOPT_COPE = 0;//Disable watchdog timer   PTADD = 0x02; // Replace XX with the hex value to set the PA2 and PA1 as outputs      PTFDD = 0xE0; // Same here, setting the inputs/outputs for port F   PTBDD = 0x7F; // Setting the input/outputs for Port B      /* Port A shouldn't need to have anything done to it, it only controls the decimal     point and enables some other LED's according to the schematic*/     for (;;)  //Repeat forever {     Output_Seven_Segments(E_Display,1) ;  delay(1); //Call a delay subroutine  Output_Seven_Segments(P_Display,2) ;  delay(1);  Output_Seven_Segments(Two_Display,3) ;  delay(1);                           }}//Note: if your display is broken also include the following subroutine which is&lt;/PRE&gt;&lt;PRE&gt;//called to remangle the broken bits. Otherwise just look at how the routine&lt;/PRE&gt;&lt;PRE&gt;//shuffles bit around! int FixDigit2(int value) {    unsigned char newval;  newval=0;    newval=newval|(value&amp;amp;0x01)&amp;lt;&amp;lt;6;   //Bit 0 becomes 6  newval=newval|(value&amp;amp;0x02)&amp;gt;&amp;gt;1;   //Bit 1 becomes 0  newval=newval|(value&amp;amp;0x04)&amp;lt;&amp;lt;5;  //Bit 2 becomes 7  newval=newval|(value&amp;amp;0x40)&amp;gt;&amp;gt;4;  //Bit 6 becomes 2  newval=newval|(value&amp;amp;0x80)&amp;gt;&amp;gt;6;  //Bit 7 becomes 1  newval=newval|(value&amp;amp;0x38);    //And bits 543 are copied undisturbed    return (newval);}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;I have a few questions as to my best approach to this. I know the FixDigit2 subroutine is correct as it was given to me.&lt;/DIV&gt;&lt;DIV&gt;The delay subroutine and main are also correct, I am just having trouble with Output_Seven_Segments&lt;/DIV&gt;&lt;DIV&gt;sub routine which happens to be the most important one.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have checked the settings for the DDR's and they are also correct. I think my bit masking is correct also.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Here is where I get confused. I need to use a 4 case switch statement for displaying the appropriate outputs.&lt;/DIV&gt;&lt;DIV&gt;1 case will be the most significant bit, 1 will be the second digit, 1 will be the least significant bit and the last one will be to drive the LED display.&lt;/DIV&gt;&lt;DIV&gt;I have been asked to mask digit bits &amp;lt;7:2&amp;gt; off so there is only 2 bits for the 4 outputs (00,01,10,11).&lt;/DIV&gt;&lt;DIV&gt;But to what do I apply this? Should I apply this to the variable digit? This seems to me to be the best approach.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Could someone give me the general form of the switch I need. Is this psuedo code correct?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;switch ( digits ) {case 0:Code to execute if digits == 0break;case 1:Code to execute if digits == 1break;&lt;/PRE&gt;&lt;PRE&gt;case 2:&lt;/PRE&gt;&lt;PRE&gt;Code to execute if digits == 2break;&lt;/PRE&gt;&lt;PRE&gt;case 3:&lt;/PRE&gt;&lt;PRE&gt;Code to execute if digits == 3&lt;/PRE&gt;&lt;PRE&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;Now would it be wise to manipulate variable digits at any point or just leave it alone?&lt;/DIV&gt;&lt;DIV&gt;I am required to use a timer for my next program.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by karmabobby on &lt;SPAN class="date_text"&gt;2008-04-01&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:34 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2008 20:30:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207768#M17612</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-04-01T20:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207769#M17613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;The switch statement seems fine except you are switching on digits instead of digit.&amp;nbsp; The compiler would have generated an error for this.&amp;nbsp; You should not have to do anything&amp;nbsp;else to digit, it is just used to select which display you want to&amp;nbsp;drive.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You still have a problem that bigmac pointed out,&amp;nbsp;you should have function prototypes.&amp;nbsp; You are calling one function before it is declared (FixDigit2) which should generated a warning from your compiler.&amp;nbsp; All warnings should be inspected and understood before they are dismissed.&amp;nbsp; If you don't understand what it is doing then go to the help see if you can find any&amp;nbsp;information on it.&amp;nbsp; The above problem should produce the following warning:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;C1801: Implicit parameter-declaration for&amp;nbsp;'FixDigit2'&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The C in C1801 indicates this is a compiler warning, if you go to Help -&amp;gt; Search then put C1801 in, it correctly describes what the problem&amp;nbsp;is, a lack of a function prototype.&amp;nbsp; Without function prototypes you&amp;nbsp;would have to declare a function before it is called, meaning&amp;nbsp;this error would not&amp;nbsp;appear if FixDigit2 appeared&amp;nbsp;above Output_Seven_Segments in your .c file.&amp;nbsp; The way to get around having to re-order functions in this&amp;nbsp;manner is provide a function prototype for every function you use at the top of your .c file or in an included header(.h) file.&amp;nbsp; The top of your .c file should like something like this:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include &amp;lt;stdio.h&amp;gt;/* Function Prototypes */void delay(long int);void Output_Seven_Segments(unsigned char, unsigned char);void main(void);int FixDigit2(int);&lt;/PRE&gt;...&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;You can put the names of the variables after the variable types, but it is not required.&amp;nbsp; Either way, stay consistent and always put the variable names or never put them.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Some other notes:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1. I don't know why you included stdio.h, it is not needed.&lt;/DIV&gt;&lt;DIV&gt;2. If you are required to use FixDigit2 and this way of display letters/numbers it is ok, but it is not a good way to do so in general.&amp;nbsp; The best way to do this would normally be a look-up table.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2008 21:37:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207769#M17613</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-04-01T21:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207770#M17614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Within your code, you have assumed the following bit sequence -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;DP g f e d c b a&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This means that segment&amp;nbsp;A should be allocated to PTB0, through to segment G allocated to PTB6.&amp;nbsp; This&lt;BR /&gt;differs from your original bit assignments, where segment A starts with PTB1.&amp;nbsp; I would suggest that you&lt;BR /&gt;alter your hardware connections to what you have assumed within the code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I can't see any need for the use of a switch statement in your code - it just complicates things.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define&amp;nbsp; DIGIT_PORT&amp;nbsp; PTFD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Port F used for digits */&lt;BR /&gt;#define&amp;nbsp; DIGIT_MASK&amp;nbsp; 0xF0&lt;BR /&gt;#define&amp;nbsp; SEG_PORT&amp;nbsp;&amp;nbsp;&amp;nbsp; PTBD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Port B used for segments */&lt;BR /&gt;#define&amp;nbsp; SEG_MASK&amp;nbsp;&amp;nbsp;&amp;nbsp; 0x7F&lt;BR /&gt;#define&amp;nbsp; DP_BIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTAD_PTAD0 /* Port A used for DP */&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;void Seven_Seg_out( byte segments, byte digit)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; // Remember: segments variable formed as: DP g f e d c b a&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; DIGIT_PORT &amp;amp;= ~DIGIT_MASK;&amp;nbsp; /* Set all digits OFF */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SEG_PORT &amp;amp;= ~SEG_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Set all segments OFF */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; DP_BIT = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Set DP to OFF */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;//&amp;nbsp;&amp;nbsp; if (digit == Two_Display)&amp;nbsp;&amp;nbsp; // This is the broken display&lt;BR /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; segments = FixDigit2( segments); // Mangle segment bits&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; if (segments &amp;amp; 0x80)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Test DP state */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DP_BIT = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Set DP to ON */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SEG_PORT |= segments &amp;amp; SEG_MASK;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; DIGIT_PORT |= (0x10 &amp;lt;&amp;lt; digit);&lt;BR /&gt;}&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The parameter &lt;FONT face="Courier New"&gt;digit&lt;/FONT&gt; would require a value 0-3.&amp;nbsp; The attached header file might also be of some use.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-04-02&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:25 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2008 23:22:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207770#M17614</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-01T23:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Driving a digital display using HCS08 MC9S08GB60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207771#M17615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Ok I will take another look. The FixDigit subroutine was provided by my lecturer, I think it was meant to show us clearly how bit manipulation works. Thanks for showing me function prototypes the examples I found on the net were pretty vague. I'm going to get the bit manipulations in this program sorted and to do this I thought it would be best to write another simple program using the LED's on Port F on this board. Anyway thanks for the help guys my knowledge of the language is expanding and I am getting better slowly! &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2008 23:27:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Driving-a-digital-display-using-HCS08-MC9S08GB60/m-p/207771#M17615</guid>
      <dc:creator>karmabobby</dc:creator>
      <dc:date>2008-04-01T23:27:13Z</dc:date>
    </item>
  </channel>
</rss>

