Daryl Hurst

Driving a digital display using HCS08 MC9S08GB60

Discussion created by Daryl Hurst on Mar 28, 2008
Latest reply on Apr 1, 2008 by Daryl Hurst
 
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.
 
 
 
#include <hidef.h> /* 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 (;:smileywink:  //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<n; i++)
   for (j=0; j<100; j++)
     {}
}

void Output_Seven_Segments (unsigned char segments, unsigned char digit)//this doesnt work!
{
 
 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<6:0>
 
  PTFD == Mask_Digits;//Mask digit bits <7:2> off, so we only end with bits <1:0>
  //(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&0x01)<<6;   //Bit 0 becomes 6
  newval=newval|(value&0x02)>>1;   //Bit 1 becomes 0
  newval=newval|(value&0x04)<<5;  //Bit 2 becomes 7
  newval=newval|(value&0x40)>>4;  //Bit 6 becomes 2
  newval=newval|(value&0x80)>>6;  //Bit 7 becomes 1
  newval=newval|(value&0x38);    //And bits 543 are copied undisturbed
 
  return (newval);
}
 
 
  for(;:smileywink: {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
}


Message Edited by karmabobby on 2008-03-28 02:25 PM

Message Edited by karmabobby on 2008-03-28 02:26 PM

Message Edited by karmabobby on 2008-03-28 02:26 PM

Message Edited by karmabobby on 2008-03-28 02:30 PM

Message Edited by karmabobby on 2008-03-28 02:31 PM

Message Edited by karmabobby on 2008-03-28 02:32 PM

Message Edited by karmabobby on 2008-03-28 02:33 PM

Outcomes