16FXlib
seg.c
Go to the documentation of this file.
1 
2 //*****************************************************************************
3 // Author : Christian Illy
4 // Created : 09.04.2009
5 // Revised : 29.06.2009
6 // Version : 0.1
7 // Target MCU : Fujitsu MB96300 series
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //*****************************************************************************
23 
24 #include "mb96348hs.h"
25 #include "seg.h"
26 #include "seg.cfg.h"
27 
28 static const uint8_t DEC7SEG[16] = { UINT8(~0x3f), UINT8(~0x06), UINT8(~0x5b), UINT8(~0x4f), UINT8(~0x66), UINT8(~0x6d), UINT8(~0x7d), UINT8(~0x07), UINT8(~0x7f), UINT8(~0x6f),
29  UINT8(~0x77), UINT8(~0x7c), UINT8(~0x58), UINT8(~0x5e), UINT8(~0x79), UINT8(~0x71) };
30 
31 void seg_init(void) {
32  SEG0_PORT_DB = 0xff;
33  SEG0_PORT_DDR = 0xff;
34  SEG1_PORT_DB = 0xff;
35  SEG1_PORT_DDR = 0xff;
36 }
37 
38 void seg_num(uint8_t num) {
39  if (num < 100) {
40  seg_numLeft(num / 10);
41  seg_numRight(num % 10);
42  }
43 }
44 
45 void seg_numLeft(uint8_t num) {
46  if (num < 10)
47  SEG1_PORT_DB = DEC7SEG[num];
48 }
49 
50 void seg_numRight(uint8_t num) {
51  if (num < 10)
52  SEG0_PORT_DB = DEC7SEG[num];
53 }
54 
55 void seg_hex(uint8_t hex) {
56  seg_hexLeft(hex / 16);
57  seg_hexRight(hex % 16);
58 }
59 
60 void seg_hexLeft(uint8_t hex) {
61  if (hex < 16)
62  SEG1_PORT_DB = DEC7SEG[hex];
63 }
64 
65 void seg_hexRight(uint8_t hex) {
66  if (hex < 16)
67  SEG0_PORT_DB = DEC7SEG[hex];
68 }
void seg_numRight(uint8_t num)
Definition: seg.c:50
#define SEG1_PORT_DDR
Data direction register for the second 7seg.
Definition: seg.cfg.h:39
void seg_num(uint8_t num)
Definition: seg.c:38
void seg_numLeft(uint8_t num)
Definition: seg.c:45
unsigned char uint8_t
Definition: inttypes.h:35
#define SEG0_PORT_DB
Port of the first 7seg.
Definition: seg.cfg.h:33
void seg_hexRight(uint8_t hex)
Definition: seg.c:65
void seg_hexLeft(uint8_t hex)
Definition: seg.c:60
void seg_hex(uint8_t hex)
Definition: seg.c:55
#define UINT8(x)
Definition: inttypes.h:40
#define SEG1_PORT_DB
Port of the second 7seg.
Definition: seg.cfg.h:37
#define SEG0_PORT_DDR
Data direction register for the first 7seg.
Definition: seg.cfg.h:35
void seg_init(void)
Definition: seg.c:31