Main program:
/*******************************************************************************
*File: Main.c
*Function: The LED digital tube displays characters 0-F, and controls 4 LEDs to display the corresponding hexadecimal
******************************************************************************/
#include "config.h"
#define HC595_CS 0x00000100 /*P0.8 port is the chip select of 74HC595*/
uint8 rcv_data;
/***********************************************************************************
*Name: DelayNS()
*Function: Long software delay
******************************************************************************/
void DelayNS(uint32 dly)
{ uint32 i;
for (;dly>0;dly--)
for(i=0;i<50000;i++);
}
/*******************************************************************************
*Name: MSpiIni()
*Function: Initialize SPI interface and set it as host
****************************************************************************/
void MSpiIni(void)
{ S0PCCR=0x52; //Set SPI clock division
S0PCR=0x30; //Set SPI interface mode, MSTR=1, CPOL=1, CPHA=0, LSBF=0
}
/***********************************************************************************
*Name: MSendData()
*Function: Send data to SPI bus
***************************************************************************/
uint8 MSendData(uint8 data)
{ IO0CLR=HC595_CS; //Chip select
S0PDR=data;
while(0==(S0PSR&0x80)); //Wait for SPIF to be set, that is, wait for data to be sent
IO0SET=HC595_CS;
return(S0PDR);
}
/*This table is the font of 0~F*/
uint8 const DISP_TAB[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E};
/*******************************************************************************
*Name: main()
*Function: Use the hardware SPI interface to output data from 0~F and control the LED display
*******************************************************************************/
int main(void)
{
uint8 i;
PINSEL0=0x00005500; //Set SPI pin connection
PINSEL1=0x00000000;
IO0DIR=HC595_CS;
MSpiIni(); //Initialize SPI interfacewhile
(1)
{ for (i=0;i<16;i++)
{rcv_data=MSendData(DISP_TAB[i]); //Send display data
DelayNS(50); //Delay
}
}
}
Previous article:ARM7 Getting Started 12, SPI Communication
Next article:ARM7 Getting Started 13, Timer Control LED Flashing
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- New version of MicroPython firmware for nRF52840
- EEWORLD University Hall ---- Introduction to Artificial Intelligence Zhejiang University of Technology
- Summary of performance indicators of integrated operational amplifiers
- EEWORLD University - Using the 75 W TAS6424-Q1 Class D Audio Amplifier for DC and AC Load Diagnostics
- EEWORLD University Hall----Live playback: High-performance i.MX RT processors help smart nodes achieve machine learning without Internet access
- Help, failed to create new IP core
- Setting the switching frequency of the switching power supply chip LTM4613
- Does the power layer of a four-layer board need to be made into a complete plane?
- [Register to enjoy gifts] element16 sincerely invites you to visit the 2019 Munich Shanghai Electronics Show
- EEWORLD University Hall----Live playback: AM57X platform features and typical applications