Functions: The four digital tubes are divided into two groups, and the four buttons are also divided into two groups. Each group controls the addition and subtraction of the corresponding digital tube display data. The data is displayed cyclically between 0--99, and has a power-off protection function. The data before power-off is saved through 24LC01B. The program is simple and easy to read, which is a blessing for beginners (because I am also a novice)!
2. Device Introduction
1. Overview
SAA1064 is a 4-bit LED driver produced by Philips. It is a bipolar circuit with an I2C interface. This circuit is specially designed to drive a 4-bit seven-segment display with a decimal point. Two 2-bit displays can be switched through a multi-way switch. The device has an I2C bus slave transmitter and receiver inside, which can be programmed to 4 different slave device addresses through the input level of the address pin ADR. The internal mode controller can control each bit of the LED to enable it to work in static mode, dynamic mode, off mode and segment test mode.
2. Pin function and package form
SAA1064 uses two package forms: 24-pin DIP and SOT. Figure 1 shows the pin arrangement of the 24-pin DIP package. The functions of the main pins are as follows:
ADR (1): address input line;
CEXT (2): internal oscillator capacitor input terminal, typical value is 2.7nF;
P8~P1 (3~10): segment data output port 1;
P9~P16 (15~22): segment data output port 2;
MX1 (11): multiplexer output 1;
MX2 (14): multiplexer output 2:
VEE (12): ground;
VCC (13): power supply;
SDA (23): I2C bus serial data line;
SCL (24): I2C bus serial clock line;
3. Functional Description
3.1 Communication Protocol
The master device CPU reads or writes SAA1064 through the I2C bus. The information transmission format on the I2C bus in the read/write mode is shown in Figure 2. In the figure: S is the start signal; P is the end signal; A is the response bit; X is an arbitrary value; A1A0 is determined by the ADR input potential to determine the 2-bit address bit; SC SB SA is the unit address bit; C6~C0 is the control bit; PR is the power-on reset flag.
3.2 SAA1064 Slave Address
The slave address of SAA1064 is determined by the input level on the pin ADR. The ADR pin corresponds to 4 different slave addresses (A1A0=00, 01, 10, 11) when connected to VEE, 3/8VCC, 5/8VCC and VCC respectively. In the write mode, the corresponding slave address byte values are 70H, 72H, 74H, 76H, and in the read mode, the corresponding slave address byte values are 71H, 73H, 75H, 77H. Other addresses are not responded to by the device.
3.3 Status Byte
Only one bit is used in the status byte of SAA1064: the power-on reset flag bit PR. When it is logic "1", it indicates that power has been turned off and on since the last read status. After the read status byte operation is completed, the flag is cleared to 0.
3.4 Unit address
bits SC, SB, and SA form a pointer to determine which register the data byte after the instruction byte is written to, and the other data is written to the subsequent unit in sequence. This feature is called unit address increment. The unit address pointer range is 0 to 7. The unit address allocation is listed in Table 1.
3.5 Control Byte
The meaning of each bit of the control byte (C0~C6) is as follows:
C0=0 static display, digits 1 and 2 can be displayed continuously;
C0=1 dynamic display, digits 1, 3 and 2, 4 are displayed alternately;
C1=0/1 digits 1, 3 dark/light selection bit;
C2=0/1 digits 2, 4 dark/light selection bit;
C3=1 all segments are turned on for segment testing, and their current is determined by C4, C5, C6;
C4=1 segment output current increases by 3mA;
C5=1 segment output current increases by 6mA;
C6=1 segment output current increases by 12mA;
3.6 Data Byte
When the data in the data byte is 1, the corresponding segment is turned on (lit). Data bytes D17~D10, D27~D20, D37~D30, D47~D40 correspond to the displays of bits 1, 2, 3 and 4 respectively. The high bit corresponds to the output terminal P8 or P16, and the low bit corresponds to the output terminal P1 or P9. The data displayed by displays 1~4 corresponds to the content of unit addresses 1~4.
3.7 SDA, SCL
SDA and SCL are the data line and clock line of the bus respectively. To prevent overvoltage pulses on these pins, a voltage regulator (5.5V) should be connected to them, that is, the normal line voltage should not exceed 5.5V. Under normal circumstances, the data jumps and latches on the clock of the corresponding bit.
3.8 Power-on reset
The power-on reset signal is generated inside the SAA1064 chip. This signal can clear each bit inside to 0 and display all dark. At this time, only the power-off flag is set.
3.9 External timing control capacitor
Connecting a timing capacitor to the ground on the pin (pin 2) of SAA1064 can make the internal multiplexed oscillator work. In static working mode, because the oscillator is not required to work, this pin can be connected or floating.
3.10 Segment data output terminals
P1~P16 are segment data output terminals with controllable absorption current. Their conduction can be controlled by the corresponding digital bits, and the magnitude of their current is controlled by the control bits of C4, C5, and C6.
3.11 Multiple output terminals
The multiple output terminals MX1 and MX2 of SAA1064 are alternately turned on in dynamic display mode. They are all driven by the frequency-divided signal of the internal clock.
In static mode, MX1 is always turned on, and its output is composed of an internal emitter follower, which can directly drive the common pole of the 2-digit display. If it exceeds the total power consumption of the circuit, pins 11 and 14 should be connected together with a transistor.
III. Program (PICC adjustment)
//Use for DN-100 Cotroller
//Date:from 2007.12.7 to
//Author:wujie
//Company:Wuxi Zhouxiang complete set of welding equipment CO.LTD
//Introduce:
//MCU:p16f73
//display IC:SAA1064 addr:0x70
//START
#include
__CONFIG(XT&WDTDIS&BORDIS);
//Program declaration
void initial(void);
void display(char cur_hex,char time_hex);
void button_test(void);
void start_iic();
void stop_iic(void);
void ack_iic();
void nack_iic();
void send_iic(char c);
char receive_iic(void);
//Predefined
#define nop() asm("nop")
#define SDA RC4
#define SCL RC3
unsigned int i,rxbuf;
char cur,time;
//Initialization
void initial(void)
{
TRISA=0X3F; //ALL PORTS ARE INPUT
PORTA=0X00;
TRISB=0X03; //RB0,RB1 ARE INPUTS
PORTB=0X00;
TRISC =0XE7; // RC3,RC4, ARE outPUTS
PORTC=0X18; //RC3,RC4 ARE IN HIGH
cur=0;
time=0;
}
//Display subroutine
void display(char cur_hex,char time_hex)
{
char d1buf, d2buf,d3buf,d4buf;
//Array storage display 7-segment code
char bit_dis[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0x00};
d2buf=bit_dis[cur_hex%10];//unit digit of CUR
d1buf=bit_dis[cur_hex%100/10];//tens digit of CUR
d4buf=bit_dis[time_hex%10];//unit digit of TIME
d3buf=bit_dis[time_hex%100/10];//tens digit of TIME
nop();
start_iic();
nop();
send_iic(0x70);//SAA1064 address
send_iic(0x00);
send_iic(0x37);//check the above information
send_iic(d1buf);
send_iic(d2buf);
send_iic(d3buf);
send_iic(d4buf);
nop();
stop_iic();
}
//write 24cl01b subroutine
void w_24cl01b(unsigned char cur_tmp,unsigned char time_tmp)
{
start_iic();
send_iic(0xa0);
send_iic(0x10);
send_iic(cur_tmp);
send_iic(time_tmp);
stop_iic();
for(i=0 ;i<500;i++);
}
//read 24cl01b subroutine
char r_24cl01b()
{
start_iic();
send_iic(0xa0);
send_iic(0x10);
start_iic();
send_iic(0xa1);
cur=receive_iic();
ack_iic( );
time=receive_iic();
nack_iic();
stop_iic();
display(cur,time);
for(i=0;i<10000;i++);
}
//Button detection
void button_test(void)
{
if(RC1==1)
{
for(i=0;i<=2000;i++);//Delay 20mS
if(RC1==1)
{
cur++;
cur=cur %100; //Let CUR < 100, because only 2 digits can be displayed
w_24cl01b(cur,time);
}
}
if(RC2==1)
{
for(i=0;i<=2000;i++);
if(RC2==1)
{
cur--;
if(cur<=0)
w_24cl01b(cur,time);//Write to 24LC01B and save
{
cur=cur+100;//Let CUR>0, because only 2 digits can be displayed
}
}
}
if(RC5==1)
{
for(i=0;i<=2000;i++);
if(RC5==1)
{
time++;
time=time%100;//Let TIME<100, because only 2 digits can be displayed
w_24cl01b(cur,time);
}
}
if(RC6==1)
{
for(i=0;i<=2000;i++);
if(RC6==1)
{
time--;
if(time<=0)
{
time=time+100; //Let TIME>0, because only 2 digits can be displayed
}
w_24cl01b(cur,time);
}
}
display(cur,time);
for(i=0;i<10000;i++);
}
//I2C protocol
//Start signal
void start_iic()
{
SDA=1;
SCL=1; nop
(
); nop()
;
nop(); nop();
SDA=0;
nop();
nop();
SCL=0;//it is ready to send data
nop();
}
//Stop signal
void stop_iic(void)
{
SDA=0;
SCL=1;
nop();
nop();
nop();
nop();
SDA=1;
nop();
}
//Send response
void ack_iic()
{
SDA=0;
nop();
nop();
SCL=1;
nop();
nop();
nop();
nop();
SCL=0;
nop();
nop();
}
//Send a byte
void send_iic(char c)
{
for(i=0;i<8;i++)
{
SCL=0;
if((c<
{
SDA=1;
}
else
{
SDA=0;
}
SCL=1;
nop();
nop();
nop();
nop();
SCL=0;
nop();
}
SDA=1;
TRISC4=1;//Set to input state, wait for response
SCL=1;//Assume that the response has always been
nop();
nop();
nop();
nop();
SCL=0;
nop();
TRISC4=0;//Restore to output
}
//Accept a byte
char receive_iic(void)
{
SDA=1;
rxbuf=0;
TRISC4=1;//Note: must set input
for(i=0;i<8;i++)
{
SCL=0;
nop();
nop();
nop();
nop();
SCL=1;
nop();
rxbuf=rxbuf<<1;
if(SDA==1)
{
rxbuf=rxbuf+1;
}
}
nop();
nop();
SCL=0;
nop();
TRISC4=0;//Restore to output
return (rxbuf);
}
//Main program
void main(void)
{
initial();
r_24cl01b(); //Read the data stored in 24LC01B before power failure
while(1)
{
button_test();
}
}
IV. Conclusion
Pay attention to the purple areas in the above program. I have suffered losses from this before. The so-called tuned programs on the Internet do not pay attention to these areas, which results in the program not running normally as expected.
Previous article:PIC microcontroller example 3: dual-machine asynchronous communication based on PROTEUS simulation
Next article:PIC microcontroller application topic three: I2C reading and writing 24C02
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- "Playing with the board" + Zhou Hangci's book Chapter 7, Example 4
- A brief summary of the use of MAX9611/9612 current detection chips
- If you have a third child, the government will give you a house. Would you give birth to a third child?
- Ginkgo USB-SPI nRF24L01 host computer debugging software source code download
- New Technology for Air Quality Monitors and Smoke Detectors
- 【ESP32-C3-DevKitM-1】ESP32-C3 development environment construction
- Layoffs, employment difficulties…what do you think of this winter?
- DSP28 fir low-pass filter design source code
- [Analysis of the topic of the college electronic competition] - 2019 National Competition G "Wireless transceiver system for dual-channel voice simultaneous interpretation"
- USB Type-c charging and music listening two-in-one adapter solution