Basic fading in and out of leds with light sensor.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:24:58 2016 +0000
Revision:
0:cf7af2656659
Basic v1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mturner5 0:cf7af2656659 1 #include "FRDM-s401.h" // 4x7 segdisplay
mturner5 0:cf7af2656659 2
mturner5 0:cf7af2656659 3
mturner5 0:cf7af2656659 4 #if 1 // VREF to VLL1
mturner5 0:cf7af2656659 5 /* Following configuration is used for LCD default initialization */
mturner5 0:cf7af2656659 6 #define _LCDRVEN (1) //
mturner5 0:cf7af2656659 7 #define _LCDRVTRIM (8) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 8 #define _LCDCPSEL (1) // charge pump select 0 or 1
mturner5 0:cf7af2656659 9 #define _LCDLOADADJUST (3) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 10 #define _LCDALTDIV (0) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 11 #define _LCDALRCLKSOURCE (0) // 0 -- External clock 1 -- Alternate clock
mturner5 0:cf7af2656659 12
mturner5 0:cf7af2656659 13 #define _LCDCLKPSL (0) // Clock divider to generate the LCD Waveforms
mturner5 0:cf7af2656659 14 #define _LCDSUPPLY (1)
mturner5 0:cf7af2656659 15 #define _LCDHREF (0) // 0 or 1
mturner5 0:cf7af2656659 16 #define _LCDCLKSOURCE (1) // 0 -- External clock 1 -- Alternate clock
mturner5 0:cf7af2656659 17 #define _LCDLCK (1) //Any number between 0 and 7
mturner5 0:cf7af2656659 18 #define _LCDBLINKRATE (3) //Any number between 0 and 7
mturner5 0:cf7af2656659 19
mturner5 0:cf7af2656659 20
mturner5 0:cf7af2656659 21 #else //VLL3 to VDD internally
mturner5 0:cf7af2656659 22 /* Following configuration is used for LCD default initialization */
mturner5 0:cf7af2656659 23 #define _LCDCLKSOURCE (1) // 0 -- External clock 1 -- Alternate clock
mturner5 0:cf7af2656659 24 #define _LCDALRCLKSOURCE (0) // 0 -- External clock 1 -- Alternate clock
mturner5 0:cf7af2656659 25 #define _LCDCLKPSL (0) // Clock divider to generate the LCD Waveforms
mturner5 0:cf7af2656659 26 #define _LCDSUPPLY (0)
mturner5 0:cf7af2656659 27 #define _LCDLOADADJUST (3) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 28 #define _LCDALTDIV (0) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 29 #define _LCDRVTRIM (0) // CPSEL = 1 0 -- 8000 pf 1 -- 6000 pf 2 -- 4000 pf 3 -- 2000 pf
mturner5 0:cf7af2656659 30 #define _LCDHREF (0) // 0 or 1
mturner5 0:cf7af2656659 31 #define _LCDCPSEL (1) // 0 or 1
mturner5 0:cf7af2656659 32 #define _LCDRVEN (0) //
mturner5 0:cf7af2656659 33 #define _LCDBLINKRATE (3) // Any number between 0 and 7
mturner5 0:cf7af2656659 34 #define _LCDLCK (0) // Any number between 0 and 7
mturner5 0:cf7af2656659 35
mturner5 0:cf7af2656659 36 #endif
mturner5 0:cf7af2656659 37
mturner5 0:cf7af2656659 38
mturner5 0:cf7af2656659 39
mturner5 0:cf7af2656659 40
mturner5 0:cf7af2656659 41 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~ LCD Control Register 0 ~|~|~|~|~|~|~|~|~|~|~|~|~*/
mturner5 0:cf7af2656659 42 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 43 #define _LCDINTENABLE (1)
mturner5 0:cf7af2656659 44
mturner5 0:cf7af2656659 45 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~ LCD Control Register 1 ~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 46 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 47 #define _LCDFRAMEINTERRUPT (0) //0 Disable Frame Frequency Interrupt
mturner5 0:cf7af2656659 48 //1 Enable an LCD interrupt that coincides with the LCD frame frequency
mturner5 0:cf7af2656659 49 #define _LCDFULLCPLDIRIVE (0) // 0 GPIO shared with the LCD. Inputs levels and internal pullup reference to VDD
mturner5 0:cf7af2656659 50 // 1 If VSUPPLY=11and RVEN=0. Inputs levels and internal pullup reference to VLL3
mturner5 0:cf7af2656659 51 #define _LCDWAITMODE (0) // 0 Allows the LCD driver and charge pump to continue running during wait mode
mturner5 0:cf7af2656659 52 // 1 Disable the LCD when the MCU goes into wait mode
mturner5 0:cf7af2656659 53 #define _LCDSTOPMODE (0) // 0 Allows the LCD driver and charge pump to continue running during stop2 or stop3
mturner5 0:cf7af2656659 54 // 1 Disable the LCD when and charge pump when the MCU goes into stop2 or stop3
mturner5 0:cf7af2656659 55
mturner5 0:cf7af2656659 56 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~ LCD Voltage Supply Register ~|~|~|~|~|~|~|~|~|~|~|~*/
mturner5 0:cf7af2656659 57 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 58 #define _LCDHIGHREF (0) //0 Divide input VIREG=1.0v
mturner5 0:cf7af2656659 59 //1 Do not divide the input VIREG=1.67v
mturner5 0:cf7af2656659 60 #define _LCDBBYPASS (0) //Determines whether the internal LCD op amp buffer is bypassed
mturner5 0:cf7af2656659 61 //0 Buffered mode
mturner5 0:cf7af2656659 62 //1 Unbuffered mode
mturner5 0:cf7af2656659 63
mturner5 0:cf7af2656659 64 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~ LCD Regulated Voltage Control |~|~|~|~|~|~|~|~|~|~*/
mturner5 0:cf7af2656659 65 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 66 #define _LCDCONTRAST (1) //Contrast by software 0 -- Disable 1-- Enable
mturner5 0:cf7af2656659 67 #define _LVLCONTRAST (0) //Any number between 0 and 15, if the number is bigger the glass gets darker
mturner5 0:cf7af2656659 68
mturner5 0:cf7af2656659 69 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~ LCD Blink Control Register ~|~|~|~|~|~|~|~|~|~|~|~*/
mturner5 0:cf7af2656659 70 /*~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|~|*/
mturner5 0:cf7af2656659 71 #define _LCDBLINKCONTROL (1) //0 Disable blink mode
mturner5 0:cf7af2656659 72 //1 Enable blink mode
mturner5 0:cf7af2656659 73 #define _LCDALTMODE (0) //0 Normal display
mturner5 0:cf7af2656659 74 //1 Alternate display for 4 backplanes or less the LCD backplane sequencer changes to otuput an alternate display
mturner5 0:cf7af2656659 75 #define _LCDBLANKDISP (0) //0 Do not blank display
mturner5 0:cf7af2656659 76 //1 Blank display if you put it in 0 the text before blank is manteined
mturner5 0:cf7af2656659 77 #define _LCDBLINKMODE (0) //0 Display blank during the blink period
mturner5 0:cf7af2656659 78 //1 Display alternate displat during blink period (Ignored if duty is 5 or greater)
mturner5 0:cf7af2656659 79
mturner5 0:cf7af2656659 80
mturner5 0:cf7af2656659 81 //Calculated values
mturner5 0:cf7af2656659 82 #define _LCDUSEDPINS (_LCDFRONTPLANES + _LCDBACKPLANES)
mturner5 0:cf7af2656659 83 #define _LCDDUTY (_LCDBACKPLANES-1) //Any number between 0 and 7
mturner5 0:cf7af2656659 84 #define LCD_WF_BASE LCD->WF8B[0]
mturner5 0:cf7af2656659 85
mturner5 0:cf7af2656659 86 // General definitions used by the LCD library
mturner5 0:cf7af2656659 87 #define LCD_WF(x) *((uint8 *)&LCD_WF_BASE + x)
mturner5 0:cf7af2656659 88
mturner5 0:cf7af2656659 89 /*LCD Fault Detections Consts*/
mturner5 0:cf7af2656659 90 #define FP_TYPE 0x00 // pin is a Front Plane
mturner5 0:cf7af2656659 91 #define BP_TYPE 0x80 // pin is Back Plane
mturner5 0:cf7af2656659 92
mturner5 0:cf7af2656659 93 // Fault Detect Preescaler Options
mturner5 0:cf7af2656659 94 #define FDPRS_1 0
mturner5 0:cf7af2656659 95 #define FDPRS_2 1
mturner5 0:cf7af2656659 96 #define FDPRS_4 2
mturner5 0:cf7af2656659 97 #define FDPRS_8 3
mturner5 0:cf7af2656659 98 #define FDPRS_16 4
mturner5 0:cf7af2656659 99 #define FDPRS_32 5
mturner5 0:cf7af2656659 100 #define FDPRS_64 6
mturner5 0:cf7af2656659 101 #define FDPRS_128 7
mturner5 0:cf7af2656659 102
mturner5 0:cf7af2656659 103 // Fault Detect Sample Window Width Values
mturner5 0:cf7af2656659 104 #define FDSWW_4 0
mturner5 0:cf7af2656659 105 #define FDSWW_8 1
mturner5 0:cf7af2656659 106 #define FDSWW_16 2
mturner5 0:cf7af2656659 107 #define FDSWW_32 3
mturner5 0:cf7af2656659 108 #define FDSWW_64 4
mturner5 0:cf7af2656659 109 #define FDSWW_128 5
mturner5 0:cf7af2656659 110 #define FDSWW_256 6
mturner5 0:cf7af2656659 111 #define FDSWW_512 7
mturner5 0:cf7af2656659 112
mturner5 0:cf7af2656659 113 /*
mturner5 0:cf7af2656659 114 Mask Bit definitions used f
mturner5 0:cf7af2656659 115 */
mturner5 0:cf7af2656659 116 #define mBIT0 1
mturner5 0:cf7af2656659 117 #define mBIT1 2
mturner5 0:cf7af2656659 118 #define mBIT2 4
mturner5 0:cf7af2656659 119 #define mBIT3 8
mturner5 0:cf7af2656659 120 #define mBIT4 16
mturner5 0:cf7af2656659 121 #define mBIT5 32
mturner5 0:cf7af2656659 122 #define mBIT6 64
mturner5 0:cf7af2656659 123 #define mBIT7 128
mturner5 0:cf7af2656659 124 #define mBIT8 256
mturner5 0:cf7af2656659 125 #define mBIT9 512
mturner5 0:cf7af2656659 126 #define mBIT10 1024
mturner5 0:cf7af2656659 127 #define mBIT11 2048
mturner5 0:cf7af2656659 128 #define mBIT12 4096
mturner5 0:cf7af2656659 129 #define mBIT13 8192
mturner5 0:cf7af2656659 130 #define mBIT14 16384
mturner5 0:cf7af2656659 131 #define mBIT15 32768
mturner5 0:cf7af2656659 132 #define mBIT16 65536
mturner5 0:cf7af2656659 133 #define mBIT17 131072
mturner5 0:cf7af2656659 134 #define mBIT18 262144
mturner5 0:cf7af2656659 135 #define mBIT19 524288
mturner5 0:cf7af2656659 136 #define mBIT20 1048576
mturner5 0:cf7af2656659 137 #define mBIT21 2097152
mturner5 0:cf7af2656659 138 #define mBIT22 4194304
mturner5 0:cf7af2656659 139 #define mBIT23 8388608
mturner5 0:cf7af2656659 140 #define mBIT24 16777216
mturner5 0:cf7af2656659 141 #define mBIT25 33554432
mturner5 0:cf7af2656659 142 #define mBIT26 67108864
mturner5 0:cf7af2656659 143 #define mBIT27 134217728
mturner5 0:cf7af2656659 144 #define mBIT28 268435456
mturner5 0:cf7af2656659 145 #define mBIT29 536870912
mturner5 0:cf7af2656659 146 #define mBIT30 1073741824
mturner5 0:cf7af2656659 147 #define mBIT31 2147483648
mturner5 0:cf7af2656659 148
mturner5 0:cf7af2656659 149 #define mBIT32 1
mturner5 0:cf7af2656659 150 #define mBIT33 2
mturner5 0:cf7af2656659 151 #define mBIT34 4
mturner5 0:cf7af2656659 152 #define mBIT35 8
mturner5 0:cf7af2656659 153 #define mBIT36 16
mturner5 0:cf7af2656659 154 #define mBIT37 32
mturner5 0:cf7af2656659 155 #define mBIT38 64
mturner5 0:cf7af2656659 156 #define mBIT39 128
mturner5 0:cf7af2656659 157 #define mBIT40 256
mturner5 0:cf7af2656659 158 #define mBIT41 512
mturner5 0:cf7af2656659 159 #define mBIT42 1024
mturner5 0:cf7af2656659 160 #define mBIT43 2048
mturner5 0:cf7af2656659 161 #define mBIT44 4096
mturner5 0:cf7af2656659 162 #define mBIT45 8192
mturner5 0:cf7af2656659 163 #define mBIT46 16384
mturner5 0:cf7af2656659 164 #define mBIT47 32768
mturner5 0:cf7af2656659 165 #define mBIT48 65536
mturner5 0:cf7af2656659 166 #define mBIT49 131072
mturner5 0:cf7af2656659 167 #define mBIT50 262144
mturner5 0:cf7af2656659 168 #define mBIT51 524288
mturner5 0:cf7af2656659 169 #define mBIT52 1048576
mturner5 0:cf7af2656659 170 #define mBIT53 2097152
mturner5 0:cf7af2656659 171 #define mBIT54 4194304
mturner5 0:cf7af2656659 172 #define mBIT55 8388608
mturner5 0:cf7af2656659 173 #define mBIT56 16777216
mturner5 0:cf7af2656659 174 #define mBIT57 33554432
mturner5 0:cf7af2656659 175 #define mBIT58 67108864
mturner5 0:cf7af2656659 176 #define mBIT59 134217728
mturner5 0:cf7af2656659 177 #define mBIT60 268435456
mturner5 0:cf7af2656659 178 #define mBIT61 536870912
mturner5 0:cf7af2656659 179 #define mBIT62 1073741824
mturner5 0:cf7af2656659 180 #define mBIT63 2147483648
mturner5 0:cf7af2656659 181
mturner5 0:cf7af2656659 182
mturner5 0:cf7af2656659 183