Question

Software The segment LEDs are driven through different GPIO Ports that are defined as digital outputs. The predefined hexadecimal encoding values need to be shifted to the corresponding bit in order to light up the correct segment LED on different Ports. The program counts from 0 through 15 with 1 sec interval, then rolls over to 0 again. The count values are shown on the seven segment display as 0, 1, 2, 3 4, 5, 6,7, 8, 9, A, b, C, d, E, and F

need a C Code to show the 7 segment from 0-9 and A-F. thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code below is working fine . it may help you

CODE

#define Data7219 RB0_bit
#define Load7219 RB1_bit
#define Clk7219 RB2_bit

const unsigned char Font_B[16]=
{
        0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,
        0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47
};

unsigned long value;
unsigned char dpset = 0;

void Send7219 (char,char);
void Send7219byte(char);
void MAX7219init();
void Display(float);

void main (void){
        TRISA = 0xFF;
        TRISB = 0x00;
        PORTB = 0x00;
        ANSEL = 0x00;
        ANSELH = 0x00;
        ADCON1 = 0x00;
        CM1CON0 = 0x00;
        CM2CON0 = 0x00;

        MAX7219init();
        Display(230.14592);                  //my_weird_number
        //Display(123.45678);                    //much easier to work with

        while(1){;}//Display(47110815);} //my_weird_number}
}

void MAX7219init()
{
        Data7219 =0;
        Load7219 =0;
        Clk7219 = 0;
        Send7219(0x09,0x00);//Decode Mode
        Send7219(0x0A,0x05);//Brightness
        Send7219(0x0B,0x07);//Scan limit
        Send7219(0x0C,0x01);
        Send7219(0x0F,0x00);
}

void Send7219 (char Digit,char Data)
{
        Send7219byte(Digit);
        Send7219byte(Data);
        Data7219=0;
        Load7219=1;
        Load7219=0;
}

void Send7219byte (char byte)
{
unsigned char I;
        for(I=0;I<8;I++)
        {
        if (byte & 0x80)
                Data7219=1;
        else
                Data7219=0;

        Clk7219=1;
        byte<<=1;
        Clk7219=0;
        }
}

void Display (float My_number)
{
        unsigned char dispskip;         // add 1 if "." found within string
        unsigned char i, string[23];

        FloatToStr(My_number, string);
        string[9] = 0;                // null terminate
        string[8] = 0x20;             // FloatToString returns 7 characters + ".", so blank the 9th

        dispskip = 8;                 // initialise
        for (i=0;i<8;i++)
        {
                if (string[dispskip-i] == 0x20)//0x20 is ASCII " "
                Send7219(i+1,0);
                          //send MAX7219 " " to MAX7219

                else if ((string[dispskip-i] <= 0x39))
                      Send7219(i+1,(Font_B[string[dispskip-i] - 0x30]));//0-9
                else
                      Send7219(i+1,(Font_B[string[dispskip-i] - 0x57]));//A-F
                      
                if (string[dispskip-i] == '.'){//0x20 is ASCII " "
                        dispskip = 7;                                                 //
                        if (string[dispskip-i] <= 0x39)
                       Send7219(i+1,(Font_B[string[dispskip-i] - 0x30]) | (0b10000000));//0-9
                        else
                  Send7219(i+1,(Font_B[string[dispskip-i] - 0x57]) | (0b10000000));//A-F
                }
        }
}  

THANK YOU

Add a comment
Know the answer?
Add Answer to:
need a C Code to show the 7 segment from 0-9 and A-F. thank you Software...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Figure 1 a conceptual diagram of a seven-segment screen is presented, called a, b, c, d, e, f ...

    In Figure 1 a conceptual diagram of a seven-segment screen is presented, called a, b, c, d, e, f and g, as well as a decimal point dp. In this work, it is not considered the decimal point. Figure 1: Seven-Segment Screen Each of the segments is a light-emitting diode (LED). The screen is used for representing numbers or other symbols. If the screen is a common cathode, then when a high voltage appears (logical value 1) the respective LED...

  • A seven segment decoder is a digital circuit that displays an input value 0 through 9 as a digital output in the 7-segment display. The behavior of this design can be modeled with the schematic diagra...

    A seven segment decoder is a digital circuit that displays an input value 0 through 9 as a digital output in the 7-segment display. The behavior of this design can be modeled with the schematic diagram below, where DCBA is the 4-bit input (D is the most significant bit and A is the least significant bit) and abcdefg is the 7-segment output. 2. (20 POINTS) A seven segment decoder is a digital circuit that displays an input value 0 through...

  • 6. Pre-Lab steps Step1: Designing Refer to Chapter 4, section 4.4 in your textbook to help...

    6. Pre-Lab steps Step1: Designing Refer to Chapter 4, section 4.4 in your textbook to help you design your application and the reference is found below A seven segment display consists of seven LEDs (hence its name) arranged in a rectangular fashion as shown in Figure 1. Each of the seven LEDs is called a segment because when illuminated the segment forms part of a numerical digit (both Decimal and Hex)to be displayed. Comm on Figure 1. Seven Segment Display...

  • In this lab, you will design a finite state machine to control the tail lights of...

    In this lab, you will design a finite state machine to control the tail lights of an unsual car. There are three lights on each side that operate in sequence to indicate thedirection of a turn. Figure ! shows the tail lights and Figure 2 shows the flashing sequence for (a) left turns and (b) right rums. ZOTTAS Figure 28:8: BCECECece BCECECECes BCECECECB BCECECBCB 8888 Figure 2 Part 1 - FSM Design Start with designing the state transition diagram for...

  • Need answers. thank you VOCABULARY BUILDER Misspelled Words Find the words below that are misspelled; circle...

    Need answers. thank you VOCABULARY BUILDER Misspelled Words Find the words below that are misspelled; circle them, and then correctly spell them in the spaces provided. Then fill in the blanks below with the correct vocabulary terms from the following list. amino acids digestion clectrolytes nutrients antioxident nutrition basal metabolic rate extracellulare oxydation calories fat-soluble presearvatives catalist glycogen processed foods cellulose homeostasis saturated fats major mineral coenzyeme trace minerals diaretics metabolism water-soluable 1. Artificial flavors, colors, and commonly added to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT