#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 (;;) //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){ 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(;;) { __RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */}}#include <hidef.h> /* 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 { ; }}#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include <stdio.h>#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<n; i++) for (j=0; j<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<6:0> //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//called to remangle the broken bits. Otherwise just look at how the routine
//shuffles bit around! int FixDigit2(int 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);}switch ( digits ) {case 0:Code to execute if digits == 0break;case 1:Code to execute if digits == 1break;case 2:
Code to execute if digits == 2break;
case 3:
Code to execute if digits == 3
}
#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include <stdio.h>/* Function Prototypes */void delay(long int);void Output_Seven_Segments(unsigned char, unsigned char);void main(void);int FixDigit2(int);...