Gpbcon controller controls LED Display

Source: Internet
Author: User

Gpbcon is used to set the input and output attributes. That is to say, do you want to control LEDs? Now you know that the LED pins are gpb0 and gpb1, and gpbcon controls the attributes of these pins, so now we need to set the attributes of these pins to output to control its flickering. So how to set it? Our pins are gpb0 and gpb1, while gpbcon controls one pin in two places, so it should be 0101 (which is clearly stated here ), the 22-bit low of the gpbcon register is used to control the attributes of the pins. Each two of them controls one pin, for example, [1:0] to control gpb0, that is, 0th pins, [] to control gpb10, that is, 11th pins. On the board, each led generally has two pins. Therefore, both pins must be set. Setting it to 00 indicates the input state, 01 indicates the output status (generally high, for example, gpb0 [1:0], that is, 1st bits are 0 and 0th bits are 1). 10 is a special function and 11 is reserved for use.

That is, gpbcon = 0x5 (0101 binary for hexadecimal is 5)

Gpbdat is used to read and write pins, which is more important. We need to control the first and second pins.
# Define led3_on () (gpbdat & = ~ (0x1) When led3 is on, the last position of gpbdat is 0 (gpb0 is the last position)
# Define led4_on () (gpbdat & = ~ (0x2) When led4 is on, the second-to-last position of gpbdat is 0 (gpb1. Second SA)
# Define led3_off () (gpbdat | = (0x1) When led3 is disabled, the last position of gpbdat is 1 (gpb0 is the last bit)
# Define led4_off () (gpbdat | = (0x2) When led4 is disabled, the second-to-last position of gpbdat is 1 (gpb1 second-to-last)

Gpbup is the port pull register controls the enabling or disabling of each port group's pull register. When the corresponding bit is 0, the pull-up register of this pin is allowed. When it is set to 1, the pull-up register is forbidden.

Here we disable gpbup = 0 xFFFF;

Speaking of this, it should be similar. Can be bright, can be destroyed, but to flash, we must also need a latency program.
Delay:
Sub r0, R0, #1
CMP r0, #0x0
BNE Delay
MoV PC, LR

Now, the necessary preparation for flashing led has been completed. The following is a complete program.
Two programs, one assembly and one C file are required.

Assembler is used for entry and the delay program, and C program is used to handle bright and extinct. The flickering effect is displayed.

The Code is as follows: LED. s
. Text
. Global _ start
LDR sp, = 1024*4
. Extern main
BL main
. Global Delay
Delay:
Sub r0, R0, #1
CMP r0, #0x0
BNE Delay
MoV PC, LR
. End

Led. c
Extern void delay (INT time );
# Define gpbcon (* (volatile unsigned *) 0x56000010)
# Define gpbdat (* (volatile unsigned *) 0x56000014)
# Define gpbup (* (volatile unsigned *) 0x56000018)
# Define led3_on () (gpbdat & = ~ (0x1 ))
# Define led4_on () (gpbdat & = ~ (0x2 ))
# Define led3_off () (gpbdat | = (0x1 ))
# Define led4_off () (gpbdat | = (0x2 ))
Void main ()
{
Gpbcon = 0x5;
[Size =-1] gpbup = 0 xFFFF;
While (1)
{
Led3_on ();
Delay (0 xfffff );
Led4_on ();
Delay (0 xfffff );
Led3_off ();
Delay (0 xfffff );
Led4_off ();
Delay (0 xfffff );
}
}

I am exhausted. I don't know if I have an error. If there is an error, please point it out. Because I use one machine when I access the Internet, and the Write Program is another machine (I cannot access the Internet, because of piracy issues), the Code cannot be copied. Sorry for any errors ..

At last, I wrote it on Linux and how to compile it. Because I still got stuck here, I think it is necessary to write it out. (I am still weak. You already know it)
Arm-Linux-gcc-g-c-o led. O led. s
Arm-Linux-gcc-g-c-o led_on.o led. c
Arm-Linux-LD-ttext 0x0000000-G led. O led_on.o-O led_on_c.o
Arm-Linux-objcopy-O Binary-s led_on_c.o led_on (note that O and S are capitalized here)

 

 

The following code is provided:

# Define gpbcon (* (volatile unsingned long *) 0x56000010)
# Define gpbdat (* (volatile unsingned long *) 0x56000014)
# Define gpb5_out (1 <(5*2 ))
Gpbcon = gpb5_out; // gpb5 pin is set to output
Gpbdat & = ~ (1 <5); // gpb5 outputs Low Level
You can see the third sentence, because gpb5 is also 5th pins, gpbcon controls it, that is, [11: 10], so you need to shift 0x1 to the left, that is, get the 11th and 10 digits as 01, in the first sentence, the low 11 bits in the gpbdat register are also used to correspond to the numerical status of 11 pins. If it is 0, it indicates that the LED is off. If it is 1, it indicates that the LED is on, therefore, you need to move the 0x1 to the left and then take the inverse, and then phase it with gpbdat. This will only set the 5th position to 0.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.