from this section, start using the ClassA20 class library to complete the operation of the peripheral functions, please firstHttps://github.com/tjCFeng/ClassA20Download the ClassA20 class library.
The purpose of encapsulation is to simplify operations, just imagine what you need to do to set up Gpio registers directly in Linux? Basically compute the physical address, get the map address, understand the role of each register, set the corresponding bit ... It's very tedious. After using the Encapsulated class library, you only need to do this:
As long as the corresponding IO port is found from the schematic, the other can not be considered, this development efficiency I will not say more (said this period of time IO port has been operating, hehe).
The function of fun is to select the function of the IO port and open the Gpio.pas file to see the definition. The function of each IO port is different, so it needs to be specified according to the manual instructions. But generally Fun0 is the input, FUN1 is the output, the other is not regular.
Pull is the function of whether to open the internal tensile resistance. The banana pie PH24 already has a pull-up resistor, so you don't have to set it up. It is best to set the circuit if it is built by itself without pulling the resistor.
A single IO port operates quickly, if I want to output a 8-bit, 16-bit data for a device, do I have to create many of these objects and then work on them? Absolutely not, even if you are not afraid of trouble, timing may not allow, so this time, tgpiogroup this class should appear.
Tgpiogroup only specify the port at the time of creation, rather than specifying a pin, so it can be assigned to the port at the time of the output. For example:
do not attempt to execute this code on your device, as this code, for example, may cause the system to crash, change to the correct port, and then run.
Since it is called IO, then the output must have input. However, because there is no kernel interrupt to go to the user program, so now temporarily can not respond to the input and other interrupts, can only use the polling method, this strongly not recommended, or wait for the implementation of interrupt forwarding to consider it (I do not know why in the banana pie REQUEST_IRQ always return errorcode:- 22, the same program on Pcduino no problem. And the driver of the compilation also depends on the kernel version, very troublesome, there is no good way to find.
With this in mind, it's easy to create a program that controls LEDs such as the following:
It is too simple and boring, do not waste time, do something practical, control the Nokia 5110 LCD display something.
First build the hardware environment, find the spare pin, connect the LCD. For example, I am connected in this way:
rst-pi14
Sce-pi10
D/C-PI16
Din-ph21
Clk-ph20
I'll find the rest of VCC and GND.
Then write the software based on the hardware connection. For the clarity of the program structure, I created a 5110 class, a single file. The definition of a class is this:
Only the functions in the public are visible in the class, and the others are private functions and variables.
Download this unit file from here Lcd5110.pas, Link: http://pan.baidu.com/s/1gdxinGB Password: CNLL. If the PIN definition is not the same, find this section in the file and change it to your own pin:
function is implemented, the following to build the display interface. That's what I did.
put on two buttons and a memo input box.
After selecting the form, create and close two events in the event, then double-click the two buttons to create the Click event and enter the code:
Finish writing and start running. Enter the text in the input box, then click on the "Showtext button" and the small screen shows:
Please download this unit file here Lcd5110.pas, Link: http://pan.baidu.com/s/1gdxinGB password: CNLL.
please download the ClassA20 class library at https://github.com/tjCFeng/ClassA20.
Please download this unit file here Lcd5110.pas, Link: http://pan.baidu.com/s/1gdxinGB password: CNLL.
please download the ClassA20 class library at https://github.com/tjCFeng/ClassA20.
Use of the 4.GPIO class "Allwinner ClassA20 class Library Analysis"