-
Notifications
You must be signed in to change notification settings - Fork 1
/
led7seg.c
140 lines (110 loc) · 4.04 KB
/
led7seg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*****************************************************************************
* led7seg.c: Driver for the 7 segment display
*
* Copyright(C) 2009, Embedded Artists AB
* All rights reserved.
*
******************************************************************************/
/*
* NOTE: SPI must have been initialized before calling any functions in
* this file.
*
*/
/******************************************************************************
* Includes
*****************************************************************************/
#include "lpc17xx_gpio.h"
#include "lpc17xx_ssp.h"
#include "led7seg.h"
/******************************************************************************
* Defines and typedefs
*****************************************************************************/
#define LED7_CS_OFF() GPIO_SetValue( 2, (1<<2) )
#define LED7_CS_ON() GPIO_ClearValue( 2, (1<<2) )
/******************************************************************************
* External global variables
*****************************************************************************/
/******************************************************************************
* Local variables
*****************************************************************************/
/* character mapping */
static uint8_t chars[] = {
/* '-', '.' */
0xFB, 0xDF, 0xFF,
/* digits 0 - 9 */
0x24, 0xAF, 0xE0, 0xA2, 0x2B, 0x32, 0x30, 0xA7, 0x20, 0x22,
/* ':' to '@' are invalid */
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
/* A to J */
0x21, 0x38, 0x74, 0xA8, 0x70, 0x71, 0x10, 0x29, 0x8F, 0xAC,
/* K to T */
0xFF, 0x7C, 0xFF, 0xB9, 0x04, 0x61, 0x03, 0xF9, 0x12, 0x78,
/* U to Z */
0x2C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
/* '[' to '`' */
0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF,
/* a to j */
0x21, 0x38, 0xF8, 0xA8, 0x70, 0x71, 0x02, 0x39, 0x8F, 0xAC,
/* k to t */
0xFF, 0x7C, 0xFF, 0xB9, 0xB8, 0x61, 0x03, 0xF9, 0x12, 0x78,
/* u to z */
0xBC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
/* { to '|' */
0xFF, 0x7D,
};
static uint8_t invertedChars[] = {
/* '-', '.' */
0xFB, 0xDF, 0xFF,
/* digits 0 - 9 */
0x24, 0x7D, 0xE0, 0x70, 0x39, 0x32, 0x23,0x7C, 0x20, 0x38
};
/******************************************************************************
* Local Functions
*****************************************************************************/
/******************************************************************************
* Public Functions
*****************************************************************************/
/******************************************************************************
*
* Description:
* Initialize the 7 segment Display
*
*****************************************************************************/
void led7seg_init (void)
{
//GPIO_SetDir( 2, 2, 1 );
GPIO_SetDir( 2, (1<<2), 1 );
LED7_CS_OFF();
}
/******************************************************************************
*
* Description:
* Draw a character on the 7 segment display
*
* Params:
* [in] ch - character interpreted as an ascii character. Not all ascii
* characters can be realized on the display. If a character
* can't be realized all segments are off.
* [in] invertedMode - set to TRUE to use inverted mode. In this case the ch data
* if they are digits 0 - 9 will be inverted on the 7 segment display.
*
*****************************************************************************/
void led7seg_setChar(uint8_t ch, uint32_t invertedMode)
{
uint8_t val = 0xff;
SSP_DATA_SETUP_Type xferConfig;
// LED7_CS_ON();
if (ch >= '-' && ch <= '|') {
val = chars[ch - '-'];
}
if (invertedMode) {
val = invertedChars[ch - '-'];
}
xferConfig.tx_data = &val;
xferConfig.rx_data = NULL;
xferConfig.length = 1;
LED7_CS_ON();
//SSP_SendData(LPC_SSP1, val);
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
LED7_CS_OFF();
}