Anda di halaman 1dari 6

2012

Seven segment interface to LPCXpresso-LPC1769

Author: Manoj

Introduction
Seven segment:

Figure:seven segment display pinout

Seven segment displays are commonly used to display digits in many applications. Out of ten pins in the display the middle pin of each row are the power pins and the remaining eight pins to control the seven segment digits. Since the seven segments used is common anode the corresponding segments connected to ground is turned ON Shift register: These are integrated circuits which provides easy control of 7 segment LED displays using a minimum of 3 digital outputs; clock pin, data pin, latch pin to the LPC1769.

Figure:shift register-74HC595 pinout

Table:explaining about the pinouts adapted from the Philips datasheet

Demo: counter to count from 0-99 using two seven segment display The display starts at zero and counts up every second. You can easily modify the code to start at a predetermined value and count down to zero.

Figure: interface connection pinout

Code: /* ===================================================================== Name : main.c Author : Manoj/Vinayak Version : #0_01 Description : main definition ===================================================================== */ #ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; // TODO: insert other include files here(if any) // TODO: insert other definitions and declarations here // Function to provide short delay void short_delay (int n) __attribute__((noinline)); void short_delay(int n) { volatile int d; for (d=0; d<n*3000; d++) { ; } } int main(void) { // TODO: insert code here int latchPin = 9; // for shift register int dataPin = 8; int clockPin = 7; int val[] = { 129, 207, 146, 134, 204, 164, 160, 143, 128, 132 }; //defined 7 segment display digits[0-9]

int i, j; // variables used for loops // Set GPIO - P0_09, P0_08, P0_07 - to be output LPC_GPIO0->FIODIR |= (1 << 9) | (1 << 8) | (1 << 7); for ( j = 0; j < 100; j++) { // First Shift Operation // Bitwise iteration for ( i = 0; i < 8; i++) { // Clock pin high LPC_GPIO0->FIOSET |= (1 << clockPin); // "i"th data in Data pin; Here selected data from the array "val" // is right shifted by "i" value, // result is made "and" operation with 0x01 and bit status is fed to dataPin" if(((val[j/10] >> i) & 0x01) == 0x01) LPC_GPIO0->FIOSET |= ( 1 << dataPin); else LPC_GPIO0->FIOCLR |= (1 << dataPin); // Clock pin low LPC_GPIO0->FIOCLR |= (1 << clockPin); } // Second Shift Operation // Bitwise iteration for ( i = 0; i < 8; i++) { // Clock pin high LPC_GPIO0->FIOSET |= (1 << clockPin); // "i"th data in Data pin // Here selected data from the array "val" // is right shifted by "i" value, result // is "and" with 0x01 and bit status is // fed to "dataPin" if(((val[j%10] >> i) & 0x01) == 0x01) LPC_GPIO0->FIOSET |= ( 1 << dataPin); else LPC_GPIO0->FIOCLR |= (1 << dataPin); // Clock pin low LPC_GPIO0->FIOCLR |= (1 << clockPin); } // Latch pin high

LPC_GPIO0->FIOSET |= (1 << latchPin); short_delay(800); // Latch pin Low LPC_GPIO0->FIOCLR |= (1 << latchPin); if(j == 99) j = 0; } return(0); }

Anda mungkin juga menyukai