S3C2440 Lighting

Publisher:闪耀之星Latest update time:2022-06-27 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

To light up the LED on the development board, you need to first check the schematic diagram, find the corresponding pins, and understand the schematic diagram to see how the light will light up on the circuit.


1. Look at the schematic diagram JZ2440v2_sch.pdf and find the corresponding pins  

nLED_1 corresponds to GPF4

nLED_2 corresponds to GPF5

nLED_4 corresponds to GPF6

2. Read the chip manual S3C2440A_UserManual_Rev13.pdf to set the corresponding I/O registers

CPFCON Control Register

GPFCON Data Register

Set the control register corresponding to the pin to output and the data register to 0 (indicating output low level) to light up the corresponding LED.


The assembly code to light up nLED_1 is as follows:


.global _start

_start:

LDR R0,=0x56000050 @ R0 is set to GPFCON register

@ This register is used to select the function of each pin of the port

@ is output, input or other

MOV R1,#0x00000100

STR R1,[R0] @ Set GPF4 as output port, bit [9:8] = 01

LDR R0,=0x56000054 @ R0 is set to GPFDAT register

@ Used to read/write data of port pins

MOV R1,#0x00000000 @ Change this value to 0x00000010 to turn off the LED

STR R1,[R0] @ GPF4 output 0, light up LED1

MAIN_LOOP:

B MAIN_LOOP


When writing bare metal programs in C language, you need to write the startup file yourself. (In conventional programs, the startup file is completed by the operating system, but there is no operating system in the logic.) The function of the startup file is to initialize the stack, call the main function, and do cleanup work when the main function returns after execution.


The startup file contains at least:


Software initialization:

1. Setting the stack: Setting the stack means pointing the stack pointer (sp=>) to the memory. When the memory is SRAM on the chip, it can be used directly, but when it is SDRAM, it needs to be initialized first.

2. Set the return address.

3. Call the main function.

4. Cleaning work. (Generally used to recycle resources, etc.)

Hardware initialization:

1. Turn off the watchdog. When the 2440 starts, the watchdog will count down. If it is not turned off within 3 seconds, it will restart the development board.

2. Initialize the clock. The 2440 can run at up to 400 MHz, but the clock frequency is only 12 MHz when powered on.

3. Initialize SDRAM.

Startup file content:


@******************************************************************************

@ File:crt0.S

@ Function: Startup file (through which the C program is transferred)

@******************************************************************************

 

.text

.global _start

_start:

ldr r0, =0x53000000 @ WATCHDOG register address

mov r1, #0x0

str r1, [r0] @ Write 0 to the watchdog register to disable watchdog. Otherwise the CPU will restart continuously.

ldr sp, =1024*4 @ Set the stack. Note: it cannot be larger than 4K, because only 4K of memory is available now.

@ The code in nand flash will be moved to internal ram after reset, this ram is only 4K

bl main @ Call the main function in the C program

halt_loop:

b     halt_loop 


C language lights up nLED_1 (implements the same function as assembly language) source code:


#define GPFCON (*(volatile unsigned long *)0x56000050)

#define GPFDAT (*(volatile unsigned long *)0x56000054)

 

int main(int argc,char **argv){

GPFCON |= (1 << 8); // Set GPF4 as output port, bit [9:8] = 01

GPFDAT &= (0 << 4); // GPF4 outputs 0, turns on the LED

return 0;

}


Write a running light in C language


#define GPFCON (*(volatile unsigned long *)0x56000050)

#define GPFDAT (*(volatile unsigned long *)0x56000054)

 

#define CPF4_OUT (1 << 8)

#define CPF5_OUT (1 << 10)

#define CPF6_OUT  (1 << 12)

 

void delay_time(unsigned int sec){

for(;sec > 0; sec--);

}

 

int main(int argc, char **argv){

GPFCON = CPF4_OUT | CPF5_OUT | CPF6_OUT;

unsigned int i = 0;

while(1){

delay_time(4000);

GPFDAT = (~(i << 4));

if(++i == 8)

i = 0;

}

return 0;

}


Write a button to control the light in C language

The principle is the same as lighting, but with one more part (need to determine whether the button is pressed). Then you need to check the schematic diagram to find the pins corresponding to the button, and how to determine whether the button is pressed or released. Which registers need to be set.


1. Check the schematic diagram JZ2440v2_sch and find the pins corresponding to the buttons

s2 corresponds to GPF0

s3 corresponds to GPF2

s4 corresponds to GPG3

2. Read the chip manual S3C2440A_UserManual_Rev13.pdf to set the corresponding I/O registers

GPFCON Control Register

GPFCON Data Register

GPGCON Control Register

GPGDAT Data Register

Set the control register corresponding to the pin as input, read the value of the data register, and if it is 0 (indicating a low level is connected), the corresponding button is pressed, and the LED to be controlled is turned on. If 1 is detected, it means that the button is released, and the LED to be controlled is turned off.


Source code:


#define GPFCON (*(volatile unsigned long *)0x56000050)

#define GPFDAT (*(volatile unsigned long *)0x56000054)

 

#define GPGCON (*(volatile unsigned long *)0x56000060)

#define GPGDAT (*(volatile unsigned long *)0x56000064)

 

//Set the pin corresponding to the LED to output

#define GPF4_OUT (1 << 8)

#define GPF5_OUT (1 << 10)

#define GPF6_OUT (1 << 12)

//led control register mask

#define GPF4_MASK (3 << 8) 

#define GPF5_MASK (3 << 10)

#define GPF6_MASK (3 << 12)

//Set the pin corresponding to the button to input

#define GPF0_IN (0 << 0)

#define GPF2_IN (0 << 4)

#define GPG3_IN (0 << 6)

//Key control register mask

#define GPF0_MASK (3 << 0)

#define GPF2_MASK (3 << 4)

#define GPG3_MASK (3 << 6)

 

int main(int argc, char **argv){

GPFCON &= ~(GPF0_MASK | GPF2_MASK | GPF4_MASK | GPF5_MASK | GPF6_MASK);

GPFCON |= (GPF4_OUT | GPF5_OUT | GPF6_OUT | GPF0_IN | GPF2_IN);

GPGCON &= ~GPG3_MASK;

GPGCON |= GPG3_IN;

unsigned long dwDat;

while(1){

// Take out the value of the data register and determine whether the response data bit is 1 or 0. If it is 0, the corresponding LED will be lit.

dwDat = GPFDAT;

if (dwDat & 1)

GPFDAT |= (1 << 4);

else

GPFDAT &= ~(1 << 4);

if (dwDat & (1 << 2))

GPFDAT |= (1 << 5);

else

GPFDAT &= ~(1 << 5);

dwDat = GPGDAT;

if (dwDat & (1 << 3))

GPFDAT |= (1 << 6);

else

GPFDAT &= ~(1 << 6);

}

 

return 0;

}


The above C language needs to be compiled together with the startup file when compiling. The following is a simple Makefile for the last program as an example.


key_led.bin : crt0.S key_led.c

arm-linux-gcc -g -c -o crt0.o crt0.S

arm-linux-gcc -g -c -o key_led.o key_led.c

arm-linux-ld -Ttext 0x00000000 -g crt0.o key_led.o -o key_led_elf

arm-linux-objcopy -O binary -S key_led_elf key_led.bin

clean:

rm -f key_led.bin key_led_elf *.o

Keywords:S3C2440 Reference address:S3C2440 Lighting

Previous article:S3C2440 interrupt control register
Next article:Memory Management Unit MMU

Recommended ReadingLatest update time:2024-11-16 17:44

12-S3C2440 driver learning (IX) Embedded Linux-USB driver (to be continued)
1. Learning ideas When a USB device is inserted into the system, the system will recognize it as a USB device and query the USB device information (descriptor), such as the device name, through the USB bus driver on the system according to the agreed specifications. The USB bus driver is responsible for: identifying
[Microcontroller]
12-S3C2440 driver learning (IX) Embedded Linux-USB driver (to be continued)
System clock of s3c2440
The following content is from "ARM processor bare metal development practice - mechanism rather than strategy", taking the s3c2440 development board as an example The system clock is the heart of the entire circuit. Generally speaking, there are four main clocks related to the s3c2440 processor: Fin, FCLK, HCLK an
[Microcontroller]
System clock of s3c2440
FFmpeg porting S3C2440
FFmpeg porting process: FFmpeg is an open source, free, cross-platform video and audio streaming solution. It is free software and uses the LGPL or GPL license. Its porting also follows the LGPL or GPL porting method: configure, make, make install. 1. Download the ffmpeg open source library (ffmpeg-0.5.tar
[Microcontroller]
1.8.2_S3C2440_LCD Controller_P
The LCD controller has two main functions. The first is to retrieve the data of a certain pixel from the memory. The second is to send this data to the LCD in conjunction with other signals. To know how to send data in conjunction with other signals, you need to read the LCD chip manual, know the LCD timing requiremen
[Microcontroller]
1.8.2_S3C2440_LCD Controller_P
s3c2440 lcd display picture bare metal program
Because the previous bare metal program is very simple, I won’t blog about it. Program flow: 1. Initialize C SP  2. Turn off the watchdog 3. Initialize SDRAM 4. Read the program containing pictures in NAND FLASH and put it into SDRAM. 5. Jump to SDRAM for execution Because the 2440 automatically only rea
[Microcontroller]
s3c2440 lcd display picture bare metal program
S3C2440 clock system and setting method
I have been busy studying and porting U-boot these days. There is an important step in the process of porting U-boot, which is to set the clock of s3c2440. The clock signals such as Fin, Fclk, Hclk, Pclk, Mpll, Upll, etc. make beginners confused. The various signals are confusing. I have spent some time to sort out th
[Microcontroller]
Exceptions and Interrupts in S3C2440
1. A brief introduction and implementation of exceptions and interrupts There are a total of 7 modes in S3C2440 (as shown in Figure 1), among which there are 5 exception modes: svc (management mode), abt (abort mode), und (undefined instruction mode), irq (interrupt mode) and fiq (fast interrupt mode). The abort mode
[Microcontroller]
Exceptions and Interrupts in S3C2440
ARM9 S3C2440—GPIO initialization settings
The GPIO configuration for external input and output mainly consists of the following steps:   1.Configuration of GPxCON.         The function of each IO pin is multiplexed, and GPxCON determines whether the pin is output (01), input (00), or other functions (external interrupt, serial port, etc.), represented by
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号