lab 3
Dependencies: mbed mbed-rtos tsi_sensor SLCD
seven_segment.h@2:b94b72891752, 2020-02-25 (annotated)
- Committer:
- teajaypierce
- Date:
- Tue Feb 25 22:05:21 2020 +0000
- Revision:
- 2:b94b72891752
- Parent:
- 0:78b84e1ce9df
lab3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wstapleton | 0:78b84e1ce9df | 1 | #ifndef SEVEN_SEGMENT_H |
wstapleton | 0:78b84e1ce9df | 2 | #define SEVEN_SEGMENT_H |
wstapleton | 0:78b84e1ce9df | 3 | |
wstapleton | 0:78b84e1ce9df | 4 | #ifndef BIT |
wstapleton | 0:78b84e1ce9df | 5 | #define BIT(N) (1 << (N)) |
wstapleton | 0:78b84e1ce9df | 6 | #endif |
wstapleton | 0:78b84e1ce9df | 7 | |
wstapleton | 0:78b84e1ce9df | 8 | /* This file contains routines for controlling a single seven segment */ |
wstapleton | 0:78b84e1ce9df | 9 | /* display. */ |
wstapleton | 0:78b84e1ce9df | 10 | /* The assumption is of a common cathode display where each anode is */ |
wstapleton | 0:78b84e1ce9df | 11 | /* individually controlled by an active-high signal from a port pin. */ |
wstapleton | 0:78b84e1ce9df | 12 | /* The further assumption is that the control will be through an */ |
wstapleton | 0:78b84e1ce9df | 13 | /* eight-bit BusOut structure where the segment control bits are */ |
wstapleton | 0:78b84e1ce9df | 14 | /* defined from most significant to least significant as: */ |
wstapleton | 0:78b84e1ce9df | 15 | /* DP, G, F, E, D, C, B, A */ |
wstapleton | 0:78b84e1ce9df | 16 | /* |
wstapleton | 0:78b84e1ce9df | 17 | AAA |
wstapleton | 0:78b84e1ce9df | 18 | F B |
wstapleton | 0:78b84e1ce9df | 19 | F B |
wstapleton | 0:78b84e1ce9df | 20 | F B |
wstapleton | 0:78b84e1ce9df | 21 | GGG |
wstapleton | 0:78b84e1ce9df | 22 | E C |
wstapleton | 0:78b84e1ce9df | 23 | E C |
wstapleton | 0:78b84e1ce9df | 24 | E C DP |
wstapleton | 0:78b84e1ce9df | 25 | DDD DP |
wstapleton | 0:78b84e1ce9df | 26 | */ |
wstapleton | 0:78b84e1ce9df | 27 | |
wstapleton | 0:78b84e1ce9df | 28 | /* |
wstapleton | 0:78b84e1ce9df | 29 | #define SEG_A BIT(0) |
wstapleton | 0:78b84e1ce9df | 30 | #define SEG_B BIT(1) |
wstapleton | 0:78b84e1ce9df | 31 | #define SEG_C BIT(2) |
wstapleton | 0:78b84e1ce9df | 32 | #define SEG_D BIT(3) |
wstapleton | 0:78b84e1ce9df | 33 | #define SEG_E BIT(4) |
wstapleton | 0:78b84e1ce9df | 34 | #define SEG_F BIT(5) |
wstapleton | 0:78b84e1ce9df | 35 | #define SEG_G BIT(6) |
wstapleton | 0:78b84e1ce9df | 36 | #define SEG_DP BIT(7) |
wstapleton | 0:78b84e1ce9df | 37 | |
wstapleton | 0:78b84e1ce9df | 38 | int seven_segment_pattern [16]= { |
wstapleton | 0:78b84e1ce9df | 39 | (SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F), |
wstapleton | 0:78b84e1ce9df | 40 | (SEG_B+SEG_C), |
wstapleton | 0:78b84e1ce9df | 41 | (SEG_A+SEG_B+SEG_D+SEG_E+SEG_G), |
wstapleton | 0:78b84e1ce9df | 42 | (SEG_A+SEG_B+SEG_C+SEG_D+SEG_G), |
wstapleton | 0:78b84e1ce9df | 43 | (SEG_B+SEG_C+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 44 | (SEG_A+SEG_C+SEG_D+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 45 | (SEG_A+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 46 | (SEG_A+SEG_B+SEG_C), |
wstapleton | 0:78b84e1ce9df | 47 | (SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 48 | (SEG_A+SEG_B+SEG_C+SEG_D+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 49 | (SEG_A+SEG_B+SEG_C+SEG_E+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 50 | (SEG_C+SEG_D+SEG_E+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 51 | (SEG_ASEG_D+SEG_E+SEG_F), |
wstapleton | 0:78b84e1ce9df | 52 | (SEG_B+SEG_C+SEG_D+SEG_E+SEG_G), |
wstapleton | 0:78b84e1ce9df | 53 | (SEG_A+SEG_D+SEG_E+SEG_F+SEG_G), |
wstapleton | 0:78b84e1ce9df | 54 | (SEG_A+SEG_E+SEG_F+SEG_G) |
wstapleton | 0:78b84e1ce9df | 55 | }; |
wstapleton | 0:78b84e1ce9df | 56 | */ |
wstapleton | 0:78b84e1ce9df | 57 | |
wstapleton | 0:78b84e1ce9df | 58 | int seven_segment_pattern [16]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; |
wstapleton | 0:78b84e1ce9df | 59 | /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, b, C, d, E, F */ |
wstapleton | 0:78b84e1ce9df | 60 | |
wstapleton | 0:78b84e1ce9df | 61 | //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); |
wstapleton | 0:78b84e1ce9df | 62 | BusOut seven_segment(NC, NC, NC, NC, NC, NC, NC, NC); |
wstapleton | 0:78b84e1ce9df | 63 | |
wstapleton | 0:78b84e1ce9df | 64 | int seven_segment_find_pattern(char ss_out) |
wstapleton | 0:78b84e1ce9df | 65 | { |
wstapleton | 0:78b84e1ce9df | 66 | |
wstapleton | 0:78b84e1ce9df | 67 | if((ss_out >= 0) && (ss_out <=15)) |
wstapleton | 0:78b84e1ce9df | 68 | { |
wstapleton | 0:78b84e1ce9df | 69 | return(seven_segment_pattern[ss_out]); |
wstapleton | 0:78b84e1ce9df | 70 | } |
wstapleton | 0:78b84e1ce9df | 71 | else if((ss_out >= '0') && (ss_out <='9')) |
wstapleton | 0:78b84e1ce9df | 72 | { |
wstapleton | 0:78b84e1ce9df | 73 | return(seven_segment_pattern[ss_out-'0']); |
wstapleton | 0:78b84e1ce9df | 74 | } |
wstapleton | 0:78b84e1ce9df | 75 | else if((ss_out >= 'A') && (ss_out <='F')) |
wstapleton | 0:78b84e1ce9df | 76 | { |
wstapleton | 0:78b84e1ce9df | 77 | return(seven_segment_pattern[ss_out-'A'+10]); |
wstapleton | 0:78b84e1ce9df | 78 | } |
wstapleton | 0:78b84e1ce9df | 79 | else if((ss_out >= 'a') && (ss_out <='f')) |
wstapleton | 0:78b84e1ce9df | 80 | { |
wstapleton | 0:78b84e1ce9df | 81 | return(seven_segment_pattern[ss_out-'a'+10]); |
wstapleton | 0:78b84e1ce9df | 82 | } |
wstapleton | 0:78b84e1ce9df | 83 | else if(ss_out =='*') |
wstapleton | 0:78b84e1ce9df | 84 | { |
wstapleton | 0:78b84e1ce9df | 85 | return(seven_segment_pattern[0x0E]); |
wstapleton | 0:78b84e1ce9df | 86 | } |
wstapleton | 0:78b84e1ce9df | 87 | else if(ss_out =='#') |
wstapleton | 0:78b84e1ce9df | 88 | { |
wstapleton | 0:78b84e1ce9df | 89 | return(seven_segment_pattern[0x0F]); |
wstapleton | 0:78b84e1ce9df | 90 | } |
wstapleton | 0:78b84e1ce9df | 91 | else |
wstapleton | 0:78b84e1ce9df | 92 | { |
wstapleton | 0:78b84e1ce9df | 93 | return(0); |
wstapleton | 0:78b84e1ce9df | 94 | } |
wstapleton | 0:78b84e1ce9df | 95 | |
wstapleton | 0:78b84e1ce9df | 96 | } /* end of seven_segment_output() */ |
wstapleton | 0:78b84e1ce9df | 97 | |
wstapleton | 0:78b84e1ce9df | 98 | int seven_segment_output(char ss_out) |
wstapleton | 0:78b84e1ce9df | 99 | { |
wstapleton | 0:78b84e1ce9df | 100 | int pattern; |
wstapleton | 0:78b84e1ce9df | 101 | pattern=seven_segment_find_pattern(ss_out); |
wstapleton | 0:78b84e1ce9df | 102 | seven_segment=pattern; |
wstapleton | 0:78b84e1ce9df | 103 | return(pattern); |
wstapleton | 0:78b84e1ce9df | 104 | |
wstapleton | 0:78b84e1ce9df | 105 | } /* end of seven_segment_output() */ |
wstapleton | 0:78b84e1ce9df | 106 | |
wstapleton | 0:78b84e1ce9df | 107 | |
wstapleton | 0:78b84e1ce9df | 108 | |
wstapleton | 0:78b84e1ce9df | 109 | |
wstapleton | 0:78b84e1ce9df | 110 | #endif /* #ifndef SEVEN_SEGMENT_H */ |