ARM HOW-TO GUIDE Interfacing I2C-7SEG with LPC2148 ARM
Contents at a Glance ARM7 LPC2148 Primer Board... 3 I2C (Inter Integrated Circuit)... 3 Seven Segment Display... 4 Interfacing I2C - Seven Segment Display... 4 Interfacing I2C Seven Segment with LPC2148... 6 Pin Assignment with LPC2148... 6 Circuit Diagram to Interface I2C 7 seg with LPC2148... 7 Source Code... 7 C Program to I2C 7 Segment Display using LPC2148... 8 Testing the I2C Seven segment with LPC2148... 13 General Information... 14
ARM7 LPC2148 Primer Board The ARM7 LPC2148 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port. NXP s ARM7 (LPC2148), ARM Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers. I2C (Inter Integrated Circuit) The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link between integrated circuits (ICs).I2C is a synchronous protocol that allows a master device to initiate communication with a slave device. Data is exchanged between these devices.
Seven Segment Display A seven segment display is the most basic electronic display device that can display digits from 0-9. The most common configuration has an array of eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure 8. Every LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'h' is used to display the dot/decimal. Interfacing I2C - Seven Segment Display Fig. 1 shows how to interface the seven segments with microcontroller through I2C. I2C is a Master-Slave protocol. I2C has a clock pulse along with the data. Normally, the master device controls the clock line, SCL. This line dictates the timing of all transfers on the I2C bus. No data will be transferred unless the clock is manipulated. All slaves are controlled by the same clock, SCL.
A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to display a number. Fig. 1 Interfacing I2C - 7segment to Microcontroller
7-SEG Display Interfacing I2C Seven Segment with LPC2148 We now want to display a four digit number in LPC2148 Primer Board by using seven segment displays. The seven segment display is connected with LPC2148 controller through I2C. In LPC2148 Primer Kit, 4 nos. of common anode seven segment displays are controlled by I2C Enabled drivers. I2C Lines serial clock SCL (P0.2), serial data SDA (P0.3) connected to the I2C based 7-segment display driver. The digit select lines are (MX1, MX2) controlled by the driver chip. The 7-segmend display is powered from the 5V power supply enabled by switch SW28. Pin Assignment with LPC2148 7-SEG Driver LPC2148 LINES 7-SEG PWR Selection SCL P0.2 SDA P0.3 Make switch SW28 to 7SEG label marking position +5V OFF 1 2 3 4 SW28 8 7 6 5 PWR ON/OFF ON 7SEG LCD SM/RL GLCD
CA1 CA2 CA1 CA2 CA1 CA2 CA1 CA2 3 8 3 8 3 8 3 8 2 3 2 3 61 62 XTAL2 XTAL1 VREF VDD1 VDD2 VDD3 VDDA 63 51 43 23 7 Circuit Diagram to Interface I2C 7 seg with LPC2148 3.3V 3V3 6 18 25 42 50 59 U16 VSS1 VSS2 VSS3 VSS4 VSS5 VSSA LPC2148 P0.3 P0.2 26 22 C11 2.7nF I2C 7-SEGMENT DISPLAY U7 1 24 2 ADR SCL 23 3 CEXT SDA 22 4 P8 P16 21 5 P7 P15 20 6 P6 P14 19 7 P5 P13 18 8 P4 P12 17 9 P3 P11 16 10 P2 P10 15 11 P1 P9 14 12 MX1 MX2 13 VEE VCC R40 10k 2_SEG7 2_SEG6 2_SEG5 2_SEG4 2_SEG3 2_SEG2 2_SEG1 2_SEG0 R41 10k C12 100n 12MHz SAA1064 C36 X13 C37 22pf 22pf 1 Q3 BC847AL BC847AL Q4 1 U9 1_SEG0 7 1_SEG1 6 A 1_SEG2 4 B 1_SEG3 2 C 1_SEG4 1 D 1_SEG5 9 E 1_SEG610 F 1_SEG7 5 G DP 7 SEG DISP U8 1_SEG0 7 1_SEG1 6 A 1_SEG2 4 B 1_SEG3 2 C 1_SEG4 1 D 1_SEG5 9 E 1_SEG610 F 1_SEG7 5 G DP U10 2_SEG0 7 2_SEG1 6 A 2_SEG2 4 B 2_SEG3 2 C 2_SEG4 1 D 2_SEG5 9 E 2_SEG6 10 F 2_SEG7 5 G DP U11 2_SEG0 2_SEG1 7 6 A 2_SEG2 2_SEG3 4 2 B C 2_SEG4 2_SEG5 1 9 D E 2_SEG6 2_SEG7 10 5 F G DP 7 SEG DISP 7 SEG DISP 7 SEG DISP Source Code The Interfacing I2C seven segment displays with LPC2148 program is very simple and straight forward, that display a four digit number in seven segment display by using I2C.The C programs are developed in Keil software.
C Program to I2C 7 Segment Display using LPC2148 *************************************************************************************** Title : Program to I2C - Seven Segment display *************************************************************************************** #include <LPC214x.h> #include <stdio.h> #define MAX 6 #define AA 2 #define SI 3 #define STO 4 #define STA 5 #define I2EN 6 void I2C_ISR(void) irq; void Wait (unsigned int); void I2C_Init (void); int I2C_Start (void); int I2C_Write (unsigned char *Buff, unsigned int Count); unsigned char Buff[] = 0x00,0x27,0x3F,0x06,0x5B,0x4F; unsigned char index = 0; void I2C_ISR(void) irq if (I2C0CONSET & 0x08) switch (I2C0STAT) case (0x08): I2C0CONCLR = 1 << STA; I2C0DAT = 0x70; //Slave Addr + W break;
case (0x10): break; I2C0CONCLR = 1 << STA; //Clear START Bit I2C0DAT = 0x70; case (0x18): break; I2C0CONCLR = 0x20; //Clear START Bit I2C0DAT = Buff[index]; index++; case (0x20): break; I2C0CONCLR = 0x20; //Clear START Bit I2C0DAT = Buff[index]; index++; case (0x28): break; I2C0CONCLR = 0x20; //Clear START Bit if (index < MAX) I2C0DAT = Buff[index]; index++; else index = 0; I2C0CONSET = 0x10; //Send STOP Bit
case (0x30): I2C0CONCLR = 0x20; //Clear START Bit if (index < MAX) I2C0DAT = Buff[index]; index++; else index = 0; I2C0CONSET = 0x10; //Send STOP Bit I2C_Start(); break; case (0x38): I2C0CONSET = 0x20; break; I2C0CONCLR = 1 << SI; VICVectAddr = 0x00; void main() unsigned int i; VPBDIV = 0x02; PINSEL0 = 0x00000055; // P0.3 - SDA0 & P0.2 - SCL0 U0LCR = 0x83; U0DLL = 97; U0DLM = 0x00; U0LCR = 0x03;
VICIntSelect = 0<<9; VICVectCntl0 = 0x020 9 ; VICVectAddr0 = (unsigned long)i2c_isr; VICIntEnable = 1<<9; I2C_Init(); I2C_Start (); for (i=0;i<30;i++) Wait(10000); I2C0CONCLR = 1 << SI; while(1) for (i=0;i<20;i++) Wait(10000); void Delay(void) unsigned int i,j; for(i=0;i<20;i++) for(j=0;j<200;j++); void Wait (unsigned int Delay) while(delay--); void I2C_Init (void) I2C0SCLH = 150; //50%duty,I2C Freq ->100KHz, PCLK = 30MHz I2C0SCLL = 150; I2C0CONSET = 1 << I2EN; //Enable I2C 0
int I2C_Start (void) I2C0CONCLR = 1 << STO; I2C0CONCLR = 1 << AA; I2C0CONSET = 1 << STA; return 0; int I2C_Write (unsigned char *Buff, unsigned int Count) while(count--) I2C0DAT = *Buff++; return 0; To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project. In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Primer Board. The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.
Testing the I2C Seven segment with LPC2148 Give +3.3V power supply to LPC2148 Primer Board; the four seven segment display is connected with the LPC2148 Primer Board. First check the entire seven segments LED s are properly working or not. Here we are display just 1234 in four seven segment. The entire seven segments receive it through I2C & display it in order. If any data is not coming in seven segments, then you just check the entire seven segments LED s are working or not. Change the seven segment driver IC & Check the I2C connections. Check the four seven segments connections. Otherwise you just check the code with debugging mode in Keil. If you want to see more details about debugging just see the videos in below link. How to Create & Debug a Project in Keil.
General Information For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components. Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints. Use the exact value crystal shown in schematic. More instructions are available in following articles, Interfacing UART with LPC2148 Microcontroller. Interfacing Keys with LPC2148 Microcontroller. User Manual of LPC2148 Primer Board. Tutorial of how to create & Debug a project in Keil.
Did you enjoy the read? Pantech solutions creates information packed technical documents like this one every month. And our website is a rich and trusted resource used by a vibrant online community of more than 1,00,000 members from organization of all shapes and sizes.
What do we sell? Our products range from Various Microcontroller development boards, DSP Boards, FPGA/CPLD boards, Communication Kits, Power electronics, Basic electronics, Robotics, Sensors, Electronic components and much more. Our goal is to make finding the parts and information you need easier and affordable so you can create awesome projects and training from Basic to Cutting edge technology.