Traditional Culture Encyclopedia - Photography and portraiture - Urgent for C5 1 MCU 12 lamp to run the 4-digit digital tube control program, which requires both the digital tube and the lamp to be on, and it is better to have comments.

Urgent for C5 1 MCU 12 lamp to run the 4-digit digital tube control program, which requires both the digital tube and the lamp to be on, and it is better to have comments.

I don't know if your digital tube is negative. If it is * * * positive, I will change it for you.

The program code is as follows, you can download it to your single-chip computer to test it.

# include & ltreg 5 1 . h & gt;

sbit shmag _ 0 1 = p0^0;

sbit shmag _ 02 = p0^ 1;

sbit shmag _ 03 = p0^2;

sbit shmag _ 04 = p0^3;

# definedata _ outp2//macrodefine LED lamp data port P2, port 0-7 # definedate _ outp1/macrodefine digital tube data port p 1, port 0-7.

Unsigned character code Volat_table[]={ 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };; //Put the LED bit code in the code.

Unsigned charcode valat _ shmag [] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,//Digital tube 0-F display segment codes 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x765438+.

/*

* Delay subfunction with parameter 1 ms

**/

Void Delay_ 1ms (unsigned integer time)

{

Unsigned integers x, y;

For(x = time; x & gt0; x -)

for(y = 120; y & gt0; y-);

}

/*

* light the LED running water lamp function

**/

Void light _ water Cmd (void)

{

Unsigned character I; //Define variables

for(I = 0; I<8; i++)//I = 0; Gaga I = 8; end

{

DATA _ Out = Volat _ table[I]; //P2' s LED lights are on from the first to the eighth.

delay _ 1 ms(500); //Delay 500ms LED 1+0 to turn on 500, LED 1 turn off 500. .............

}

}

/*

* Digital tube scanning display subfunction

**/

void Shmag_waterCmd(void)

{

Unsigned character temperature;

for(Temp = 0; Temp & lt 16; Temp++)

{

DATE _ Out = Valat _ Shmag[Temp];

delay _ 1 ms(500);

}

}

/*

* The main function of the program.

**/

int main(void)

{

shmag _ 0 1 = 0; //Digital tube position 1 Display on.

shmag _ 02 = 0; //Digital tube position 2 display is turned on.

shmag _ 03 = 0; //Digital tube position 3 display is turned on.

shmag _ 04 = 0; //Digit tube position 4 display is on.

While( 1) // macrocycle

{

light _ water cmd(); //Always light LED1-LED 7 circularly;

shmag _ water cmd(); //Always cycle the digital tube to display 0-f;

}

}