74HC595 control LED lamp
You should simulate SPI, because 595 is a serial input and parallel output chip.

You mainly simulate SPI, control it, and your hardware wiring diagram should not be wrong.

Now my computer can't hold the simulation. If you like, just me.

I will write one for you according to your hardware diagram.

QQ 2475 19442

You can do it in one byte, you know, your problem now is to send it.

I have a program with an analog display digital tube.

You extract what you want from the code.

# include & ltc 805 1f 3 10 . h & gt;

# include & ltstdio.h & gt

# include & ltmath.h & gt

# include & ltIntrins.h & gt

# include & ltabsacc.h & gt

/* * * * * * * * * * * * * * Analog SPI controls the digital tube * * * * * * * * * * * * * * *

sbit SPI 1 _ sh _ clk = p 1^4; //Analog SPI shift clock

sbit SPI 1 _ ST _ clk = p 1^5; //Analog SPI Latch Clock

sbit SPI 1 _ out _ OE = p 1^6; //Analog SPI output control

sbit SPI 1 _ data = p 1^7; //Analog SPI data output

/*************************************************************/

* * * * * * * * * * * * * Data definition of system operation * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Unsigned character ADC _ date [4] = {0}; //Save the AD conversion values of the four potentiometers.

unsigned char dis PAM[8]= { 10, 10, 10, 10, 10, 10, 10 }; //Digital tube display cache

sbit down _ button = p3^3; //Down button

sbit up _ button = p3^4; //Raised key

Bit flash memory;

Sbit beef = p0^7;;

Bit control _ coordinate = 0;

Unsigned char kkk

Unsigned characters Hbeef, Lbeef

Unsigned int m = 0;; //m is mainly used as a control variable for additional counting.

Unsigned character code letter [] =

{

0x32,0x48,0x7a,0x 17,0x37,0x48,0x 12,0x32,0x7e,0x7a,0x37,0x6b,0x7e,0x7a

};

Unsigned character code seg[]={0x7e, 0x48, 0x3d, 0x6d, 0x4b, 0x67, 0x77, 0x4c, 0x7f, 0x6f, 0x00, 0x37, 0x1f};

//Digital pipe segment code 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, e, p.

Unsigned char code seg_only[]={0x04, 0x08, 0x40, 0x20, 0x 10, 0x02, 0x0 1, 0x80, 0x00}; //a b c d e f g DP

Unsigned int code table [15]={64260, 64400, 64524, 64580,

64684,64777,64820,64898,

64968,65030,65058,65 1 10,

65 157,65 178,652 17};

/************************************************************/

Unsigned character code SONG 1[]=

{

0x35,0x3 1,0x34,0x34,0x24,0x35,0x32,0x32,0x24,0x38,

0x44,0x58,0x48,0x34,0x3 1,0x34,0x34,0x24,0x38,0x34,

0x7F,0x32,0x34,0x32,0x34,0x24,0x38,0x34,0x24,0x38,

0x43,0x58,0x48,0x34,0x32,0x34,0x38,0x24,0x38,0x34,

0x7F,0x 16,0x4C,0x74,0x78,0x64,0x54,0x48,0x54,0x64,

0x58,0x44,0x34,0x24,0x38,0x24,0x 14,0x 12,0x2 1,0x 14,

0x78,0x68,0x3F,0x4C,0x74,0x78,0x64,0x52,0x42,0x48,

0x53,0x64,0x58,0x44,0x34,0x24,0x38,0x24,0x24,0x38,

0x44,0x58,0x48,0x3C,0x00

};

Unsigned character code SONG0[]={ // Happy birthday.

0X82,0X0 1,0X8 1,0X94,0X84,0XB4,0XA4,0X04,0X82,0X0 1,

0X8 1,0X94,0X84,0XC4,0XB4,0X04,0X82,0X0 1,0X8 1,0XF4,

0XD4,0XB4,0XA4,0X94,0XE2,0X0 1,0XE 1,0XD4,0XB4,0XC4,

0XB4,0X04,0X00

};

/*****************************************************

* * Function declaration section * *

*****************************************************/

/* * * * * * * * * * * * * * * * * * System Configuration Function Statement * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

void sysclk(void); //System clock initialization

void PIO _ Init(void); //I/O port initialization

void SPI _ Init(void); //SPI initialization

//void PWM(void); //PWM initialization

void t 0 1 _ init(void); //Timer0, 1 Initialization

Void interrupt _ init (void); //Interrupt initialization

void ADC _ INIT(void); //AD conversion initialization

Invalid delay (unsigned integer time); //Delay program

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

void Spel _ Count(unsigned int Putin _ Count,unsigned char LR); /////Putin_Count is plastic data within 10000.

//LR is the control of left and right digital tubes, and LR=0 left.

Voiled _ flash1(unsigned character speed);

Void led_flash2 (unsigned char speed); //Digital tube operation display

Void SPI_Write_Byte (unsigned character write _ byte);

//Analog SPI sends a byte to 595 for display.

Void coordinates (unsigned char X_radiation, unsigned char y _ radiation);

//Display coordinates

Void Sing_Song (unsigned char * p _ song);

//Music performance function

/****************************************************/

/****************************************************/

/****************************************************/

/*****************************************************

* * Main functions * *

*****************************************************/

Void main(void) // main program

{

PCA0MD & amp= ~ 0x40// Turn off the watchdog.

PIO _ initialization (); //I/O port initialization configuration

sysclk(); //System clock initialization configuration

t 0 1 _ init(); //Timer initialization configuration

//PWM();

SPI _ Init(); //SPI0DAT is the data register of SPI.

Interrupt _ Initialize (); //Interrupt initialization configuration

ADC _ INIT(); //AD conversion initialization

SPI 1 _ OUT _ OE = 0; //Allow 595 output

ad 0 busy = 1; //After initialization, start an AD conversion first.

Delay (1);

EA = 1; //Then turn on the interrupt.

Delay (1);

Beef = 0;

//Spel_count(20 10,0);

//Spel_count( 12 1, 1); //Both left and right digital tubes display 0 after starting.

/*

ADC_date[0] indicates that the AD conversion value in the left and right direction of the handle corresponds to the middle value of the input of P2.0, that is, 0x80c0.

ADC_date[ 1] indicates that the AD conversion value in the left and right direction of the handle corresponds to P2. 1, and the median input value is 0x8040.

ADC_date[2] indicates that the AD conversion value in the front-back direction on the right side of the handle corresponds to P2.2, and the median input value is 0x8340.

ADC_date[3] indicates that the AD conversion value in the front-back direction on the left side of the handle corresponds to P2.3, and the median input value is 0x7f04.

*/

//Sing _ Song(Song 0);

while( 1)

{

for(Hbeef = 0; Hbeef & lt8; Hbeef++)

dis PAM[Hbeef]= 10;

while( 1)

{

led _ flash 1( 120);

led _ flash 2( 120);

led _ flash 1(60);

led _ flash 1(60);

led _ flash 1(60);

led _ flash 1(60);

led _ flash 1(40);

Delay (200);

led _ flash 2(60);

led _ flash 2(60);

led _ flash 2(60);

led _ flash 2(60);

led _ flash 2(40);

Break;

}

kkk = 0; m = 0;

while( 1)

{

If(kkk==50) is broken;

Coordinate (0, kkk% 6);

}

kkk = 0; m = 7000

while( 1)

{

Spel_count(m,0);

If (m== 13000)

{ m = 0; kkk++; Break; }

//Spel_count(kkk,0);

Spel_count( 13000-m, 1);

}

while( 1)

{ Sing _ Song(Song 0);

Break;

}

}

}

/****************************************************/

/****************************************************/

/****************************************************/

/*****************************************************

* * System initialization function * *

*****************************************************/

Void sysclk(void) // internal crystal oscillator

{

OSCICL = 0xa3// 0x83

OSCICN = 0xc3// divided by 2

CLKSEL = 0x00

}

Void PIO_Init(void) // port configuration

{

P0MDIN = 0xff// analog input is prohibited, 0 is analog, and 1 is digital.

P0MDOUT = 0xff//0 is open drain, and 1 is push-pull (ff).

P0SKIP = 0xf0

p 1 mdin = 0x ff;

p 1m dout = 0xf 0; //The lower four bits are used for 138.

p 1 skip = 0x ff;

P2MDIN = 0xff// analog input is prohibited, 0 is analog, and 1 is a number.

P2MDOUT = 0xff//0 is open drain, and 1 is push-pull (ff).

P2SKIP = 0xff

P3MDIN = 0xff

P3MDOUT = 0xff// The lower four bits are used for 138.

XBR0 = 0x02

xbr 1 = 0x 40;

}

Void SPI_Init(void) //SPI initialization

{

SPI0CFG = 0x40

SPI 0 cn = 0x 0 1; //0000 00 1 The last bit is SPI enable bit, which works in three-wire host mode.

Spi0ckr = 0x2f//The SPI clock frequency is set to 150kHz 0x6f 0x2f.

}

void t0 1_init(void)

{

TCON = 0x 10; //0 10 1 0000 Timer0/1allowed to work.

TMOD = 0x 1 1; //Timer 0/ 1 works in 16-bit counting mode.

CKCON = 0x00// system clock 12 frequency division

TH0 = 0xf8//PCA 50Hz clock

TL0 = 0x00

th 1 = 0x 00;

TL 1 = 0x 00;

}

Void Interrupt_Init(void) // interrupt setting

{

IE = 0; //Allow Timer 0/ 1 Interrupt Request

IP = 0x08//SPI is a low priority.

}

void ADC_INIT(void)

{

AMX0P = 0x08//P2.0

AMX0N = 0x 1f; //Single-ended mode GND is a negative input.

Adc0cf = 0xfc/11111100 data is left aligned.

ADC0CN = 0x80// Enable AD conversion.

REF0CN = 0

}

/****************************************************/

/****************************************************/

/****************************************************/

/*****************************************************

* * User defined functions * *

*****************************************************/

//Separate data

void Spel _ Count(unsigned int Putin _ Count,unsigned char LR)

{

Control coordinate = 0; //Display in normal form

if(Putin _ Count & gt; = 10000)

{ tr 1 = 0;

If (! Flash)

{

dis PAM[0+4 * LR]= 1 1; //letter e

dis PAM[ 1+4 * LR]= 12; //letter p

dis PAM[2+4 * LR]= 12;

dis PAM[3+4 * LR]= 12;

Beef =1;

}

other

{

dis PAM[0+4 * LR]= 10; //letter e

dis PAM[ 1+4 * LR]= 10; //letter p

dis PAM[2+4 * LR]= 10;

dis PAM[3+4 * LR]= 10;

Beef = 0;

}

}

other

{

dis param[3+4 * LR]= Putin _ Count % 10;

if(Putin _ Count & gt; = 10)

{ dis PAM[2+4 * LR]=(Putin _ Count/ 10)% 10; }

else dis param[2+4 * LR]= 10;

if(Putin _ Count & gt; = 100)

{ dis PAM[ 1+4 * LR]=(Putin _ Count/ 100)% 10; }

else disp ram[ 1+4 * LR]= 10;

if(Putin _ Count & gt; = 1000)

{ dis PAM[0+4 * LR]=(Putin _ Count/ 1000)% 10; }

else dis param[0+4 * LR]= 10;

}

}

Voiled _ flash1(unsigned character speed)

{

Unsigned characters led_i, led _ j;;

Control coordinate = 0;

for(led _ I = 0; led _ i & lt20; led_i++)

{

for(led _ j = 0; led _ j & lt7; led_j++)

dis PAM[led _ j]= dis PAM[led _ j+ 1];

if(led _ I & lt; 10)

de param[7]= led _ I;

other

dis PAM[7]= 10;

Delay (speed);

}

}

Void led_flash2 (unsigned character speed)

{

Unsigned characters led_i, led _ j;;

Control coordinate = 0;

for(led _ I = 0; led _ i & lt20; led_i++)

{

for(led _ j = 7; led _ j & gt0; led_j -)

dis PAM[led _ j]= dis PAM[led _ j- 1];

if(led _ I & lt; 10)

de param[0]= led _ I;

other

dis PAM[0]= 10;

Delay (speed);

}

}

Void SPI_Write_Byte (unsigned character write byte)

{

Unsigned character k;

for(k = 0; k & lt8; k++)

{

SPI 1 _ DATA =(write _ byte & gt; & gt(7-k))& amp; 0x 0 1;

SPI 1 _ SH _ CLK = 1;

SPI 1 _ SH _ CLK = 0;

}

}

Empty coordinates (unsigned character X _ radiation, unsigned character Y _ radiation)

{unsigned charged radiation;

Control _ coordinate =1; //Display in the form of coordinates

For (radiation = 0; Radiation & lt8; Radiation++)

if(X_radiation==0)

Dis PAM[ radiation ]= Y _ radiation;

other

{

If (radiation! = X _ radiation-1)

Dis PAM[ radiation] = 8;

dis PAM[X _ radiation- 1]= Y _ radiation;

}

}

Voidsing _ song (unsigned char * p _ song)//Play music.

{

Unsigned character I = 0;;

Unsigned characters yfm, jpm

while(*(P_song+i))

{

jpm =(*(P _ song+I))& amp; 0x0f// beat value

yfm =((*(P _ song+I))& gt; & gt0x 04)& amp; 0x0f// Simple spectrum value

If(yfm) // Simple spectrum is 1, take the count value.

{

yfm-;

hbeef = TABLE[yfm]/256; //Take the high byte of the count value

th 1 = Hbeef;

lbeef = TABLE[yfm]% 256; //Take the low byte of the count value

TL 1 = Lbeef;

tr 1 = 1; //Start Timer 0

}

else { tr 1 = 0; Beef = 0; }//notation is 0, no pronunciation.

Spel_count(yfm,0);

Spel_count(jpm, 1);

Delay (jpm *100); //Beat delay

i++;

}

}

Void delay//Delay program

{unsigned int i, j;

for(I = 0; I & lt2000; i++)

{

for(j = 0; J< time; j++){ _ nop _(); _ nop _(); }

}

}

/****************************************************/

/****************************************************/

/****************************************************/

/*****************************************************

* * Interrupt service function * *

*****************************************************/

Void Timer 0 (void) interrupt1/Timer 0 interrupt service.

{

Unsigned character n;

TH0 = 0xe8

TL0 = 0x00

* * * * * * * * * * * * * * Display control part * * * * * * * * * * * * *

n = p 1; //Get the currently scanned column

n =(++ n)amp; 0x07

If(Control_Coordinate) // The display mode control bit is valid, that is, it is displayed in the form of coordinates.

SPI _ Write _ Byte(seg _ only[dis pram[n]]);

Otherwise, the//display mode control bit is invalid, that is, it is displayed in normal form.

SPI _ Write _ Byte(seg[dis pram[n]]);

P 1。 = 0xf8// After scanning, add 1 to the current column.

SPI 1 _ ST _ CLK = 1;

p 1 | = n; //Send a new bit.

SPI 1 _ ST _ CLK = 0; //Analog SPI is a latched output.

/**************************************************/

if(m % 200 = = 0){ flash = ~ flash; }//When the data exceeds the displayed digits, it flashes.

if(m % 25 = = 0)kkk++;

Switch (m%4)

{

Case 0: ADC _ date [0] = adc0h; //The array stores the AD conversion values in a staggered way, with the left and right 0x80c0.

AMX0P = 0x09//2. 1 is the actual input of AD.

ad 0 busy = 1;

Break;

Case1:ADC _ date [1] = adc0h; //Right Up and Down 0x8040

AMX0P = 0; //2.2 is the positive input of AD.

ad 0 busy = 1;

Break;

Case 2: ADC _ date [2] = adc0h; //Left Up and Down 0x8340

AMX0P = 0x0b//2.3 is the positive input of AD.

ad 0 busy = 1;

Break;

Case 3: ADC _ date [3] = adc0h; //Right, Left and Right 0x7f04

AMX0P = 0x08//2.0 is the positive input of AD.

ad 0 busy = 1;

Break;

Default value:;

}

m++; //Collect the next data

}

Voidtimer 1 (void) interrupt 3//Timer 1 interrupt service.

{

th 1 = Hbeef;

TL 1 = Lbeef;

Beef = ~ beef;

}

/****************************************************/

/****************************************************/

/****************************************************/

This program is used when I debug the robot. There is a lot of code in it that you don't need. There is a built-in SPI for communicating with the wireless module, so you don't need to know about analog-to-digital conversion.

I hope you can find what you want.