Edoardo Armeriv / Mbed 2 deprecated lab5

Dependencies:   mbed mbed-rtos tsi_sensor SLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers seven_segment.h Source File

seven_segment.h

00001 #ifndef SEVEN_SEGMENT_H
00002 #define SEVEN_SEGMENT_H
00003 
00004 #ifndef BIT
00005 #define BIT(N) (1 << (N))
00006 #endif
00007 
00008 /* This file contains routines for controlling a single seven segment   */
00009 /* display.                                                             */
00010 /* The assumption is of a common cathode display where each anode is    */
00011 /* individually controlled by an active-high signal from a port pin.    */
00012 /* The further assumption is that the control will be through an        */
00013 /* eight-bit BusOut structure where the segment control bits are        */
00014 /* defined from most significant to least significant as:               */
00015 /* DP, G, F, E, D, C, B, A                                              */
00016 /*
00017       AAA
00018      F   B
00019      F   B
00020      F   B
00021       GGG
00022      E   C
00023      E   C
00024      E   C  DP
00025       DDD   DP
00026 */
00027 
00028 /*
00029 #define SEG_A BIT(0)
00030 #define SEG_B BIT(1)
00031 #define SEG_C BIT(2)
00032 #define SEG_D BIT(3)
00033 #define SEG_E BIT(4)
00034 #define SEG_F BIT(5)
00035 #define SEG_G BIT(6)
00036 #define SEG_DP BIT(7)
00037 
00038 int seven_segment_pattern [16]= { 
00039 (SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F),
00040 (SEG_B+SEG_C),
00041 (SEG_A+SEG_B+SEG_D+SEG_E+SEG_G),
00042 (SEG_A+SEG_B+SEG_C+SEG_D+SEG_G),
00043 (SEG_B+SEG_C+SEG_F+SEG_G),
00044 (SEG_A+SEG_C+SEG_D+SEG_F+SEG_G),
00045 (SEG_A+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G),
00046 (SEG_A+SEG_B+SEG_C),
00047 (SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G),
00048 (SEG_A+SEG_B+SEG_C+SEG_D+SEG_F+SEG_G),
00049 (SEG_A+SEG_B+SEG_C+SEG_E+SEG_F+SEG_G),
00050 (SEG_C+SEG_D+SEG_E+SEG_F+SEG_G),
00051 (SEG_ASEG_D+SEG_E+SEG_F),
00052 (SEG_B+SEG_C+SEG_D+SEG_E+SEG_G),
00053 (SEG_A+SEG_D+SEG_E+SEG_F+SEG_G),
00054 (SEG_A+SEG_E+SEG_F+SEG_G)
00055 };
00056 */
00057 
00058 int seven_segment_pattern [16]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
00059 /*                               0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   A,   b,   C,   d,   E,   F  */    
00060 
00061 //BusOut seven_segment(SEVEN_SEGMENT_A,SEVEN_SEGMENT_B,SEVEN_SEGMENT_C,SEVEN_SEGMENT_D,SEVEN_SEGMENT_E,SEVEN_SEGMENT_F,SEVEN_SEGMENT_G,SEVEN_SEGMENT_DP);
00062 BusOut seven_segment(PTE20, PTE21, PTE22, PTE23, PTA6, PTA7, PTC16, PTC13);
00063 
00064 int seven_segment_find_pattern(char ss_out)
00065 {
00066 
00067     if((ss_out >= 0) && (ss_out <=15))
00068     {
00069         return(seven_segment_pattern[ss_out]);
00070     }
00071     else if((ss_out >= '0') && (ss_out <='9'))
00072     {
00073         return(seven_segment_pattern[ss_out-'0']);
00074     }
00075     else if((ss_out >= 'A') && (ss_out <='F'))
00076     {
00077         return(seven_segment_pattern[ss_out-'A'+10]);
00078     }
00079     else if((ss_out >= 'a') && (ss_out <='f'))
00080     {
00081         return(seven_segment_pattern[ss_out-'a'+10]);
00082     }
00083     else if(ss_out =='*')
00084     {
00085         return(seven_segment_pattern[0x0E]);
00086     }
00087     else if(ss_out =='#')
00088     {
00089         return(seven_segment_pattern[0x0F]);
00090     }
00091     else 
00092     {
00093        return(0);
00094     }
00095     
00096 }   /* end of seven_segment_output() */
00097     
00098 int seven_segment_output(char ss_out)
00099 {
00100     int pattern;
00101     pattern=seven_segment_find_pattern(ss_out);
00102     seven_segment=pattern;
00103     return(pattern);
00104       
00105 }   /* end of seven_segment_output() */
00106 
00107 
00108 
00109 
00110 #endif /* #ifndef SEVEN_SEGMENT_H */