Sign In

7 Segment Led Should Display Required Character Without Using Delay By Passing A Parameter

tanusha tanushavasamsetti@gmail.com India

Hardware: 7 Segment Led Displaying On Kl25z Board Software: C Project Using On Kl25z

i am displaying 0 to 9 alphabetical order in 7 segment...now my problem is how should i have to display only 0 or 1 or 2 or 3 by using parameter calling function

Images

Program

#include "MKL25Z4.h"
#define LED_A (1<<0)
#define LED_B (1<<3)
#define LED_C (1<<4)
#define LED_D (1<<5)
#define LED_E (1<<6)
#define LED_F (1<<7)
#define LED_G (1<<10)
#define LED_H (1<<11)

void delay(int a)

{ 
	while(a>=0) 
	{
	    a--; 
	}

}
    void main()
    {

	SIM_SCGC5 |= (SIM_SCGC5_PORTC_MASK  );
	PORTC_PCR0 = (PORT_PCR_MUX(1));
	PORTC_PCR3 =  (PORT_PCR_MUX(1));
	PORTC_PCR4 =  (PORT_PCR_MUX(1));
	PORTC_PCR5 =  (PORT_PCR_MUX(1));
	PORTC_PCR6 =  (PORT_PCR_MUX(1));
	PORTC_PCR7 = (PORT_PCR_MUX(1));
	PORTC_PCR10 = (PORT_PCR_MUX(1));
	PORTC_PCR11 =(PORT_PCR_MUX(1));

	GPIOC_PDDR |= (1<<0);
	GPIOC_PDDR |= (1<<3);
	GPIOC_PDDR |= (1<<4);
	GPIOC_PDDR |= (1<<5);
	GPIOC_PDDR |= (1<<6);
	GPIOC_PDDR |= (1<<7);
	GPIOC_PDDR |= (1<<10);
	GPIOC_PDDR |= (1<<11);

	while(1) //
	{

		 GPIOC_PCOR |= (LED_A);
		 GPIOC_PCOR |= (LED_B);
		 GPIOC_PCOR |= (LED_C);
		 GPIOC_PCOR |= (LED_D);
		 GPIOC_PCOR |= (LED_E);
		 GPIOC_PCOR |= (LED_F);
		 GPIOC_PSOR |= (LED_G);
		 GPIOC_PSOR |= (LED_H);
		 delay(1000000); //

		 GPIOC_PSOR |=(LED_A);
		 GPIOC_PCOR |=(LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PSOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PSOR |=(LED_F);
		 GPIOC_PSOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |=(LED_A);
		 GPIOC_PCOR |=(LED_B);
		 GPIOC_PSOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PCOR |=(LED_E);
		 GPIOC_PSOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |=(LED_A);
		 GPIOC_PCOR |=(LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PSOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);


		 GPIOC_PCOR |=(LED_A);
		 GPIOC_PCOR |=(LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PSOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PCOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |=(LED_A);
		 GPIOC_PSOR |=(LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PCOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |=(LED_A);
		 GPIOC_PSOR |=(LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PCOR |=(LED_E);
		 GPIOC_PCOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |= (LED_A);
		 GPIOC_PCOR |= (LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PSOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PSOR |=(LED_F);
		 GPIOC_PSOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);


		 GPIOC_PCOR |= (LED_A);
		 GPIOC_PCOR |= (LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PCOR |=(LED_E);
		 GPIOC_PCOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 GPIOC_PCOR |= (LED_A);
		 GPIOC_PCOR |= (LED_B);
		 GPIOC_PCOR |=(LED_C);
		 GPIOC_PCOR |=(LED_D);
		 GPIOC_PSOR |=(LED_E);
		 GPIOC_PCOR |=(LED_F);
		 GPIOC_PCOR |=(LED_G);
		 GPIOC_PSOR |=(LED_H);
		 delay(1000000);

		 }
	}

Replies

R Avinash
2016-05-27 11:31:53
does the program reall works? Can you upload a video in youtube and show? Or simply few pictures uploaded here?

I don't think it will work because

All of the blocks are identical


GPIOC_PCOR |= (LED_A);
GPIOC_PCOR |= (LED_B);
GPIOC_PCOR |= (LED_C);
GPIOC_PCOR |= (LED_D);
GPIOC_PCOR |= (LED_E);
GPIOC_PCOR |= (LED_F);
GPIOC_PSOR |= (LED_G);
GPIOC_PSOR |= (LED_H);
delay(1000000); //

GPIOC_PSOR |=(LED_A);
GPIOC_PCOR |=(LED_B);
GPIOC_PCOR |=(LED_C);
GPIOC_PSOR |=(LED_D);
GPIOC_PSOR |=(LED_E);
GPIOC_PSOR |=(LED_F);
GPIOC_PSOR |=(LED_G);
GPIOC_PSOR |=(LED_H);
delay(1000000);

and does not change the general purpose io (GPIO) thus their should be no change in the LED display!

Further you have not specified which type of LED displays are they. CA or CC (CA stands for common anode, and CC for common catgode)

Anyway you can write a function like this ...
declare a function like this

void draw_digit(int d)
{
	switch(d)
	{
		case 0:
		
		//write here the GPIO configuration that show 0 on display
		
		break;
		
		
		
		case 1:
		
		//write here the GPIO configuration that show 1 on display
		
		break;
		
		
		.
		.
		.
		similar code for digit 2 to 8
		.
		.
		.
		
		case 9:
		
		//write here the GPIO configuration that show 9 on display
		
		break;
	}
}
R Avinash
2016-05-27 12:14:14
hope youn know about switch case statement of C language ...

Post a reply to tanusha

Think you can help tanusha ? Then post your thoughts that might help tanusha. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.