Last time I tried to use the GPIO port using the expansion interface. This time I will use the GPIO port to configure a serial digital tube display module for the development board to achieve the purpose of data display.
The serial digital tube module is shown in Figure 1. Its main control chip is MAX7219, which is a chip that converts serial signals into parallel signals.
The display module has a total of 5 pins. Except for the 2 pins occupied by the power supply, the functions and connection relationships of the remaining 3 pins are as follows:
DIN----Data pin---P5.2
CLK----Clock pin---P5.3
CS ---- chip select pin --- P5.5
Figure 1 Serial digital tube module
To achieve the output of high and low level signals, the statements are defined as:
#defineDIN_SetHigh() Cy_GPIO_Set(P5_2_PORT, P5_2_NUM)
#defineDIN_SetLow() Cy_GPIO_Clr(P5_2_PORT, P5_2_NUM)
#defineCLK_SetHigh() Cy_GPIO_Set(P5_3_PORT, P5_3_NUM)
#defineCLK_SetLow() Cy_GPIO_Clr(P5_3_PORT, P5_3_NUM)
#defineCS_SetHigh() Cy_GPIO_Set(P5_5_PORT, P5_5_NUM)
#defineCS_SetLow() Cy_GPIO_Clr(P5_5_PORT, P5_5_NUM)
To ensure the stability and reliability of the output signal, the configured delay function is:
void delay_ns(unsignedint n)
{
unsignedint i;
unsignedint count=4;
for(i=0;i<n; i++)
{
count=4;
while(count--);
}
}
The function that implements serial transmission of byte data is:
void Write_Max7219_byte(char DATA)
{
char i;
CS_SetLow();
delay_ns(100);
for(i=8;i>=1;i--)
{
CLK_SetLow();
delay_ns(100);
if(DATA&0x80)
DIN_SetHigh();
else
DIN_SetLow();
delay_ns(100);
DATA=DATA<<1;
CLK_SetHigh();
delay_ns(100);
}
}
The function to send data to the specified unit is:
void Write_Max7219(char address,char dat)
{
CS_SetLow();
delay_ns(100);
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
CS_SetHigh();
delay_ns(100);
}
The function to initialize the serial digital tube module is:
void Init_MAX7219(void)
{
Write_Max7219(0x09, 0xff);
Write_Max7219(0x0a, 0x02);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x00);
}
The main program to implement the serial digital tube drive test is:
int main(void)
{
Init_MAX7219();
Write_Max7219(1,1);
Write_Max7219(2,2);
Write_Max7219(3,3);
Write_Max7219(4,4);
Write_Max7219(5,5);
Write_Max7219(6,6);
Write_Max7219(7,7);
Write_Max7219(8,8);
}
After the program is compiled and downloaded, the display effect of its operation is shown in Figure 2.
Figure 2 Serial digital tube test results