Skip to content

Commit 864883e

Browse files
committed
Library for controlling an SAA1064
1 parent eb7b78d commit 864883e

File tree

5 files changed

+245
-0
lines changed

5 files changed

+245
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Write to 7-segment LEDs using the SAA1064
3+
*/
4+
#include "Wire.h" // enable I2C bus
5+
#include <saa1064.h>
6+
byte addr = 0x70; // Chip select address (pin 1 to GND)
7+
int brightness = 2; // 0 = off, 6 = bright (21ma)
8+
9+
SAA1064 saa1064;
10+
11+
void setup() {
12+
saa1064.begin(addr, brightness);
13+
}
14+
15+
void loop() {
16+
saa1064.clear();
17+
for (int i=0; i<10000; i++) {
18+
saa1064.displayInt(i, 0);
19+
delay(125);
20+
}
21+
}
22+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Write to 7-segment LEDs using the SAA1064
3+
*/
4+
#include "Wire.h" // enable I2C bus
5+
#include <saa1064.h>
6+
byte addr = 0x70; // Chip select address (pin 1 to GND)
7+
int brightness = 2; // 0 = off, 6 = bright (21ma)
8+
#define INPUT A0
9+
10+
SAA1064 saa1064;
11+
12+
void setup() {
13+
saa1064.begin(addr, brightness);
14+
pinMode(INPUT, input);
15+
}
16+
17+
void loop() {
18+
saa1064.clear();
19+
for (int i=0; i<10000; i++) {
20+
saa1064.displayInt(i, 0);
21+
delay(125);
22+
}
23+
}
24+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#######################################
2+
# Syntax Coloring Map for SAA1064
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
SAA1064 KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
clear KEYWORD2
16+
displayInt KEYWORD2
17+
18+
#######################################
19+
# Constants (LITERAL1)
20+
#######################################
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* saa1064.cpp
3+
*
4+
* Copyright 2012 Warren Gill <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*
21+
* Thanks to John Boxall at tronixstuff
22+
* Example 39.3 - NXP SAA1064 I2C LED Driver IC Demo III
23+
* Displaying numbers on command
24+
* http://tronixstuff.wordpress.com/tutorials > chapter 39
25+
* John Boxall July 2011 | CC by-sa-nc
26+
*/
27+
28+
#include <Wire.h>
29+
#include <avr/pgmspace.h>
30+
#include "Arduino.h"
31+
#include "saa1064.h"
32+
33+
// Byte representations of pins required to display each digit 0~9
34+
// then A~F, and blank digit
35+
int SAA1064::_digits[]={ 63, 6, 91, 79, 102, 109, 125,7, 127, 111, 119, 124, 57, 94, 121, 113, 0};
36+
uint8_t SAA1064::_brightness[]={
37+
(byte)B00000111, // 0ma
38+
(byte)B00010111, // 3ma
39+
(byte)B00100111, // 6ma
40+
(byte)B00110111, // 9ma
41+
(byte)B01000111, // 12ma
42+
(byte)B01100111, // 18ma
43+
(byte)B01110111 // 21ma
44+
};
45+
46+
void SAA1064::begin(uint8_t ioaddr, int brightness) {
47+
// define the I2C address for the SAA1064
48+
_addr = ioaddr >> 1;
49+
50+
if (brightness > 6) brightness = 6;
51+
52+
Wire.begin(); // Start the I2C bus
53+
Wire.beginTransmission(_addr);
54+
Wire.write((byte)B00000000); // this is the instruction byte.
55+
// Zero means the next byte is the control byte
56+
57+
// control byte (dynamic mode on, digits 1+3 on, digits 2+4 on,
58+
// 9mA segment current
59+
// Wire.write((byte)B00110111); // 9ma
60+
Wire.write(_brightness[brightness]);
61+
Wire.endTransmission();
62+
}
63+
64+
void SAA1064::begin(uint8_t ioaddr) {
65+
begin(ioaddr, 2);
66+
}
67+
68+
void SAA1064::begin() {
69+
begin(0x70, 2);
70+
}
71+
72+
void SAA1064::clear() {
73+
Wire.beginTransmission(_addr);
74+
Wire.write(0x01); // start with digit 1 (right-hand side)
75+
Wire.write((byte)0); // blank digit 1
76+
Wire.write((byte)0); // blank digit 2
77+
Wire.write((byte)0); // blank digit 3
78+
Wire.write((byte)0); // blank digit 4
79+
Wire.endTransmission();
80+
}
81+
82+
void SAA1064::setBrightness(int brightness) {
83+
if (brightness > 6) brightness = 6;
84+
Wire.beginTransmission(_addr);
85+
Wire.write((byte)B00000000); // this is the instruction byte.
86+
Wire.write(_brightness[brightness]);
87+
Wire.endTransmission();
88+
}
89+
90+
/*
91+
displayInt
92+
displays the number 'num'
93+
zero = 0 - no leading zero
94+
zero = 1 - leading zero
95+
*/
96+
void SAA1064::displayInt(int num, int zero) {
97+
int thousand, hundred, ten, one;
98+
// breakdown number into columns
99+
thousand = num/1000;
100+
hundred = (num-(thousand*1000))/100;
101+
ten = (num-((thousand*1000)+(hundred*100)))/10;
102+
one = num-((thousand*1000)+(hundred*100)+(ten*10));
103+
if (zero==1) { // yes to leading zero
104+
Wire.beginTransmission(_addr);
105+
Wire.write(0x01);
106+
Wire.write(_digits[one]);
107+
Wire.write(_digits[ten]);
108+
Wire.write(_digits[hundred]);
109+
Wire.write(_digits[thousand]);
110+
Wire.endTransmission();
111+
delay(10);
112+
} else
113+
if (zero==0) { // no to leading zero
114+
if (thousand==0) {
115+
thousand=16;
116+
}
117+
if (hundred==0 && num<100) {
118+
hundred=16;
119+
}
120+
if (ten==0 && num<10) {
121+
ten=16;
122+
}
123+
Wire.beginTransmission(_addr);
124+
Wire.write(1);
125+
Wire.write(_digits[one]);
126+
Wire.write(_digits[ten]);
127+
Wire.write(_digits[hundred]);
128+
Wire.write(_digits[thousand]);
129+
Wire.endTransmission();
130+
delay(10);
131+
}
132+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* saa1064.h
3+
*
4+
* Copyright 2012 Warren Gill <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*
21+
* Thanks to John Boxall at tronixstuff
22+
* NXP SAA1064 I2C LED Driver IC Demo
23+
* http://tronixstuff.wordpress.com/tutorials
24+
* John Boxall July 2011 | CC by-sa-nc
25+
*/
26+
27+
#ifndef _SAA1064_H__
28+
#define _SAA1064_H__
29+
#define byte uint8_t
30+
31+
class SAA1064 {
32+
public:
33+
void begin(uint8_t ioaddr, int brightness);
34+
void begin(uint8_t ioaddr);
35+
void begin(void);
36+
37+
void setBrightness(int brightness);
38+
void clear();
39+
void displayInt(int num, int zero);
40+
41+
private:
42+
static int _digits[];
43+
static uint8_t _brightness[];
44+
uint8_t _addr;
45+
};
46+
47+
#endif

0 commit comments

Comments
 (0)