"Tiny6410 Bare-Metal Program" Chapter One: Discussion on the commissioning of LED Happy lights RVDS _ hardware-related

Source: Internet
Author: User

=============================================================================================================== =====================

First, the hardware pin description

The tiny6410 Development Board has 4 user programmable LEDs located on the core board directly connected to the CPU's gpio.

Led detailed resources occupy the following table:

LED4 LED3 LED2 LED1 GPIO GPK7 GPK6 GPK5 GPK4

Second, bare-metal program Description

The Tiny6410 uses the following 4 pins to connect led light-emitting diodes, respectively, gpk4--led1 gpk5--led2 gpk6--led3 gpk7--led4. This program will control the output level of these four pins to achieve the effect of the horse-lamp.

The following program sets two registers rGPIOKCON0 is the Gpk0~gpk7 control register (each 4 bit control one, GPK0~GPK7 working mode setting), is used to set up the GPK the work mode (mainly is the input or the output), the Rgpiokdat registers (each 1 bit controls one, GPK0~GPK31 level value set \ Read) is the GPK data register, is to GPK input \ Output what level.

Description: RGPIOKCON0 control the working mode of Gpkcon7~gpkcon0, Rgpiokcon control the working mode of Gpkcon15~gpkcon8, Rgpiokdat control the output level value of Gpkdat31~gpkdat0. All of these are 32-bit registers. Arm is a 32-bit register.

Each 4-bit determines the operating mode of a gpio, and each 1-bit determines the output level value.

1.main.c

#include "def.h" #include "gpio.h"//As the hardware Introduction section above, for the corresponding Gpio pin position. Set to 0, low level, is lit.  Set the value of the Rgpiokdat register, each of which determines the value of a Gpio port, gpiok0~gpiok31 #define LED1_ON ~ (1<<4)//1111 1111 1111 1111 1111 1111 1110 1111   GPKDAT4 0, namely output low level #define LED2_ON ~ (1<<5)//1111 1111 1111 1111 1111 the 1111 1101 1111 GPKDAT5 Place 0 #define Led3_on  ~ (1<<6)//1111 1111 1111 1111 1111 1111 1011 1111 GPKDAT6 Place 0 #define LED4_ON ~ (1<<7)//1111 1111 1111 1111 1111 1111 0111 1111 GPKDAT7 Place 0//As the hardware Introduction section above, for the corresponding Gpio pin. Set to 1, low level, is off. Sets the value of the Rgpiokdat register #define LED1_OFF (1<<4)//0000 0000 0000 0000 the 0000 0000 0001 0000 GPKDAT4 Set 1, which is the output high level #define LED2 _off (1<<5)//0000 0000 0000 0000 0000 0000 0010 0000 GPKDAT5 Place 1 #define LED3_OFF (1<<6)//0100 0000 000 0 0000 0000 0000 0100 0000 GPKDAT6 Reset 1 #define LED4_OFF (1<<7)//1000 0000 0000 0000 0000 0000 1000 0000 GPKDAT7 1 #define LEDALL_OFF (0xf<<4)//0000 0000 0000 0000 0000 0000 1111 0000 The gpkdat4~7 set 1//corresponding GPIO pin start address #define Gpio_bas E (0x7F008000)//ogpio_regs type is defined in Gpio.h #define GPIO (volatile Ogpio_regs *) gpio_base) void delay (int times);
void Ledportinit (void);

void Ledrun (void);
  int main (void) {ledportinit ();
Ledrun ();
  } void delay (int times) {int i;
for (; times>0;times--) for (i=0;i<3000;i++);
  } void Ledportinit (void) {u32 uconvalue;
  Uconvalue = gpio->rgpiokcon0;    Uconvalue &= ~ (0xffff<<16);       0000 0000 0000 0000 1111 1111 1111 + 1111 Sets rGPIOKCON0 registers, each 4 bit determines a GPIO pin working mode Uconvalue |= 0x1111<<16;	 0001 0001 0001 0001 0000 0000 0000 0000 working Mode gpkcon7~0 = Gpio->rgpiokcon0;
  Set Gpkcon7~4 to 0001, that is, output mode} void Ledrun (void) {Gpio->rgpiokdat |= ledall_off; while (1) {gpio->rgpiokdat &= led1_on; delay (1000);
    Gpio->rgpiokdat |= Ledall_off;  Gpio->rgpiokdat &= led2_on; Delay (1000);
    Gpio->rgpiokdat |= Ledall_off; Gpio->rgpiokdat &= led3_on; Delay (1000);
    Gpio->rgpiokdat |= Ledall_off; Gpio->Rgpiokdat &= led4_on; Delay (1000);
  Gpio->rgpiokdat |= Ledall_off; }
}
The 2.OGPIO_REGS definition is as follows: Gpio.h, which defines the gpio of a to N-port structure, is intended to be easily set later, and we use only the Gpiok associated with it.

#include "def.h"
typedef struct tag_gpio_regs{
u32 rgpioacon//0x7f00
...
U32 rGPIOKCON0;  0X7F00 8800 Description: ARM is addressed by Byte, that is, each byte size has an address
u32 rGPIOKCON1;//0x7f00 8804 u32
;  0x7f00 8808
u32 rgpiokpud; 0x7f00 880C ...
} Ogpio_regs;

3.3.U32 is defined as follows: Def.h

......
typedef unsigned long		u32;    The u32 size is 32bit, 4Byte, or 4 bytes ...


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.