-1

7 セグメント LCD で 9 より上の数字を表示できるように、16 進出力を 1 つ左にシフトしようとしています。

C でプログラミングしています。私が使用しているソフトウェアは NIOS II であるため、DE0 ボードに直接再プログラミングできます。

このプロジェクトの目的は、'button1' が押されるたびに LCD の値を 1 ずつインクリメントすることです。私はこれを成功させましたが、もちろん9の後、左にシフトして1から再起動し、元の位置を0に置き換える必要があります。かなりの調査を行いましたが、運がなかったのでどんな助けでも大歓迎です。ありがとう。

コードは以下のとおりです。

#include "sys/alt_stdio.h"   //for the alt_putstr function below.  Outputs to Eclipse console
#include "altera_avalon_pio_regs.h"  //for the I/O functions in the while loop below
#include "sys/alt_timestamp.h"  //see Nios II Software Developer’s Handbook, Timestamp Driver
#include "system.h"

#define setHeaderOuts HEADEROUTPUTS_BASE+0x10   //HEADEROUTPUTS_BASE is defined in system.h of the _bsp file.  It refers to the base address in the Qsys design
                                                //the hex offset (in this case 0x10, which is 16 in decimal) gives the number of bytes of offset
                                                //each register is 32 bits, or 4 bytes
                                                //so to shift to register 4, which is the outset register, we need 4 * (4 bytes) = 16 bytes
#define clearHeaderOuts HEADEROUTPUTS_BASE+0x14 //to shift to register 5 (the 'outclear' register) we need to shift by 5 * (4 bytes) = 20 bytes, (=0x14 bytes)
                                                // offset of 5 corresponds to the 'outclear' register of the PIO.


int  main(void)
{
    alt_putstr("This is the ELEE1062 version of the NIOS processor");
    int buttons = 0; //the buttons on the DE0
    //int switches = 0;  //the switches on the DE0
    int count = 0; //general purpose counter
    int hexd = 0;

    while(1)
    {
        buttons=IORD_ALTERA_AVALON_PIO_DATA(PUSHBUTTONS1_2_BASE); //read the value of the pushbuttons

        while((buttons & 0x01) == 1) // i.e. while pushbutton 1 is not pressed
        {
            buttons=IORD_ALTERA_AVALON_PIO_DATA(PUSHBUTTONS1_2_BASE); //read the value of the pushbuttons
        }

        count=count+1;

        IOWR_ALTERA_AVALON_PIO_DATA(DE0_LEDS_BASE,count); //display the value of count in binary, using the green LEDs

        while((buttons & 0x01) == 0) //i.e. while pushbutton 1 is pressed
        {
            buttons=IORD_ALTERA_AVALON_PIO_DATA(PUSHBUTTONS1_2_BASE); //read the value of the pushbuttons

        }

        if (count==0)
        {
            hexd=0x000000c0;
        }

        else if (count==1)
        {
            hexd=0xf9;
        }

        else if ( count==2)
        {
            hexd=0xa4;
        }

        else if ( count==3)
        {
            hexd=0xb0;
        }

        else if ( count==4)
        {
            hexd=0x99;
        }

        else if ( count==5)
        {
            hexd=0x92;
        }

        else if ( count==6)
        {
            hexd=0x82;
        }

        else if ( count==7)
        {
            hexd=0xd8;
        }

        else if ( count==8)
        {
            hexd=0x80;
        }

        else if ( count==9)
        {
            hexd=0x90;
        }

        else if ( count>9)
        {
            hexd= hexd & ~(1<<count);
        }


        //count=alt_timestamp_start(); //start the timer. Timer increments each clock cycle.  Clock for ELEE1062_NIOS is 50MHz
        //buttons=IORD_ALTERA_AVALON_PIO_DATA(PUSHBUTTONS1_2_BASE); //read the value of the pushbuttons
        //switches=IORD_ALTERA_AVALON_PIO_DATA(DE0SWITCHES_BASE); //read the value of the switches
        IOWR_ALTERA_AVALON_PIO_DATA(SSEG_BASE,hexd);  //DE0 7 segment displays all off --notice that a logic '1' turns the segment off
        IOWR_ALTERA_AVALON_PIO_DATA(SSEG_BASE,hexd);  //DE0 7 segment displays all on
        IOWR_ALTERA_AVALON_PIO_DATA(DE0_LEDS_BASE,0x000);  //all off --for the green LEDs, a logic '0' turns the LED off
        IOWR_ALTERA_AVALON_PIO_DATA(DE0_LEDS_BASE,0xfff);  //all on
        IOWR_ALTERA_AVALON_PIO_DATA(clearHeaderOuts,0x01); //turn off the first pin of the output port
        IOWR_ALTERA_AVALON_PIO_DATA(setHeaderOuts,0x01);    //turn on the first pin of the output port
        //IOWR_ALTERA_AVALON_PIO_DATA(SSEG_BASE,switches);  //light up the 7 segment display segments corresponding to how the DE0 switches are set
        IOWR_ALTERA_AVALON_PIO_DATA(DE0_LEDS_BASE,buttons); //light up the green LEDs corresponding to which DE0 buttons are pushed
        //count=alt_timestamp(); //record the value of the timer, and store in the 'count' variable


    }
}
4

2 に答える 2

1

ずらすだけではうまくいきません。9 -> 10(これをシフトと呼ぶことができます)しかし、どう19 -> 20ですか?これは明らかに宿題またはその他の形式の学習であるため、コードを記述しません。最終的な目標は、7 セグメント LED ディスプレイで数字を表すことです。そこから考えてください。したがって、入力として2進数(count)があり、出力はLEDピン信号である必要があります。あなたの仕事は、あるものを別のものに変換することです。Led は基本的に 10 進数で動作するため、最初に 2 進数を一連の 10 進数に変換し、次にそれらをピン信号に変換する必要があります (このコードは既に持っています)。4 桁すべてを使用するには、数値を 0x11223344 の形式に変換する必要があります。数値は LED の位置を示します。0xF9A4B099 は 1234 です (私が間違っていなければ)。

于 2013-12-16T17:19:21.313 に答える