First, the input / output port GPIO programming
One—(01), one digital tube static display (implemented by 74HC595)
1, the pin connection module
First introduce the related pins of LPC2106~~
Features: Independent pin configuration
Application: The purpose of the pin connection module is to configure the pin to the required function (this chapter is mainly to introduce the GPIO function ~ ~ other will be introduced in the next chapter ~ ~)
Description: The pin connection module allows more than one function for the selected pin. The configuration register controls the multiplexer to connect the pins to the on-chip peripherals. Peripherals must be connected to the appropriate pins before activation and any associated read-only enable. Any enabled peripheral function is considered invalid if it is not mapped to the corresponding pin.
Description of the register:
The pin connection module includes two registers:
Pin Function Register 0: (PINSEL0)
The PINSEL0 register controls the function of the pins according to the settings in the table below.
The direction control bits in the IODIR register are only valid when the pin is selected as a GPIO function (also described in this chapter). For other functions, the direction is automatically controlled.
Pin Function Register 1: (PINSEL1)
The PINSEL1 register sets the function of the control pin according to the following table.
The direction control bits in the IODIR register are only valid when the GPIO function is selected for the pin. For other functions, the direction is automatically controlled.
When DBGSEL is pulled low during reset, the function control of pin P0.17-P0.31 is valid.
Pin function register value:
The PINSEL register controls the function of the device pins. As shown below.
Each pair of register bits corresponds to a specific device pin.
The direction control bit of the IODIR register is valid only when the pin is selected as the GPIO function.
The direction of other functions is automatically controlled.
Each derivative typically has a different pinout, so each pin may have a different function.
2, GPIO
characteristic:
1) Direction control of a single bit
2) Set and clear the individual control outputs
3) All I/O ports default to input after reset
application:
1) General purpose I/0 port
2) Drive LED or other indicator
3) Driving off-chip devices
4) Detect digital input
Pin description:
Register description:
The GPIO contains 4 registers, as shown in the following table:
GPIO pin value register IOPIN:
GPIO output set register IOSET:
GPIO output clear register:
GPIO direction register:
Then there is the experiment to be done today:
Static display of a digital tube
Using IAR for ARM is not good~~
Switched to Keil
Wasted me a lot of time
I knew that I used Keil early.
I have to debug IAR again.
Then the program is ~~
MDK1_1.c (first the main program ~ ~ you know)
//------------------------------------------------ ------------------------------
//LED digital tube display
/ / Through the I / O analog synchronous serial interface and 74HC595 connection, control 74HC595 drive LED digital tube display
//------------------------------------------------ ------------------------------
#include"lpc210x.h"
Typedef unsigned long uint32;
Typedef unsigned char uchar;
#define SPI_IO 0x00000150 //I/O setting word of SPI interface
Uchar const seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0.82,0xf8,
0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e};
//------------------------------------------------ ------------------------------
/ / delay function
Void delay(uint32 z)
{
Uint32 i;
For(;z》0;z--)
For(i=0;i"50000;i++);
}
//------------------------------------------------ ------------------------------
//main
Int main()
{
Uchar i;
PINSEL0=0X00000000;
PINSEL1=0X00000000; //Set the left and right pins to connect GPIO
IODIR=SPI_IO; //Set the SPI control port as output~~ Since this is analog, you need to set the direction bit yourself.
While(1)
{
For(i=0;i"16;i++)
{
HC595_send_data(seg[i]);
Delay(1);
}
}
}
74HC595.c
//------------------------------------------------ ------------------------------
//74HC595 simulates SPI communication, easy to call
#include"lpc210x.h"
Typedef unsigned long uint32;
Typedef unsigned char uchar;
#define SPI_CS 0x00000100 //P0.8 analog chip selection
#define SPI_DA 0x00000040 //P0.6 analog data transmission port
#define SPI_CLK 0x00000010 //P0.4 analog CLK
//------------------------------------------------ ------------------------------
//Send a byte function to the 74HC595 (when sending data, the high order is first)
// Still about to introduce 74HC595:
The //74HC595 is an 8-bit shift register and a memory, tri-state output function.
//The shift register and memory are separate clocks.
//Data is input to the shift register on the rising edge of SH_CP and input to the storage register on the rising edge of ST_CP.
/ / If the two clocks are connected together, the shift register is always one pulse earlier than the storage register (it is generally not used ~~).
// The shift register has a serial shift input (DS), a serial output (Q7'), and an asynchronous low reset.
/ / The storage register has a parallel 8-bit, with a three-state bus output, when OE is enabled (low), the data of the storage register is output to the bus.
Void HC595_send_data(uchar dat)
{
Uchar i;
IOCLR=SPI_CS; //SPI_CS=0
For(i=0;i"8;i++) //simulate SPI~~
{
IOCLR=SPI_CLK; //SPI_CLK=0
If((dat&0x80)!=0) //Set the output value of SPI_DA
IOSET=SPI_DA; //To send from the highest bit, when the highest bit is 1, set SPI_DA
Else
IOCLR=SPI_DA; //When the highest bit is 0, clear SPI_DA
Dat ""; //dat loop left one bit
IOSET=SPI_CLK; //SPI_CLK is 1, a rising edge of the pulse, shifting the data into the shift register
}
IOSET=SPI_CS; //SPI_CS=1, input to the storage register, since the chip select is always low, the displayed data is directly output.
}
This is a special TOVAPO TP010-600 Vape Pen product series. We sell TP010-600 vape pen disposable,TP010-600 vape pen kit,
TP010-600 vape starter kit, and other Tovapo vapes.
We are specialized electronic cigarette manufacturers from China, Vapes For Smoking, Vape Pen Kits suppliers/factory, wholesale high-quality
products of Modern E-Cigarette R & D and manufacturing, we have the perfect after-sales service and technical support. Look forward to
your cooperation!
TP010-600 vape pen disposable,TP010-600 vape pen kit,TP010-600 vape starter kit,400mah battery vape,400 mah vape disposable
Ningbo Autrends International Trade Co.,Ltd. , https://www.ecigarettevapepods.com