I am new to arm, so I wrote a few small practice programs, recorded here.
Includes: running water lamp, single button, pwm driven buzzer, serial port and PC communication
Development board s3c2410, development environment realview + h-jtag
Without further ado, let’s start the first program. The study of bare board program development by Liu Shui Deng is like hello world, the first lesson for novices in any high-level language, haha. The contents of several files are as follows:
led.c
1 #include "s3c2410.h"
2 #include "delay.h"
3
4
5
6 void myblink(void)
7 {
8 delay(0);
9 GPFCON = (GPFCON & ~(0xff<<8))|0x5500;
10
11 while(1){
12 GPFDAT = 0x7f;
13 delay(1000);
14 GPFDAT = 0xbf;
15 delay(1000);
16 GPFDAT = 0xdf;
17 delay(1000);
18 GPFDAT = 0xef;
19 delay(1000);
20}
twenty one }
Configure GPF4, 5, 6, and 7 pins as output states through GPFCON, and write data to the corresponding ports through GPFDAT. Pay attention to this bit operation method. In addition, the pin pull-up can also be configured through the GPFUP register, which is not used in this example.
delay.c
1 #include "delay.h"
2 #include "s3c2410.h"
3
4
5 static int delayLoopCount = 400;
6
7 /************************************************ *********************************************
8 * name: delay
9 * func: delay time
10 * para: nTime -- input, nTime=0: nAdjust the delay function by WatchDog timer.
11 * nTime>0: the number of loop time, 100us resolution.
12 * ret: none
13 * modify:
14* comment:
15 ************************************************* *********************************************/
16 void delay(int nTime)
17 {
18 // time=0: adjust the Delay function by WatchDog timer.
19 // time>0: the number of loop time
20 // resolution of time is 100us.
21 int i,adjust=0;
22 if(nTime==0)
twenty three {
24 nTime = 200;
25 adjust = 1;
26 delayLoopCount = 400;
27 //PCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable
28 WTCON = ((PCLK/1000000-1)<<8)|(2<<3);
29 WTDAT = 0xffff; //for first update
30 WTCNT = 0xffff; //resolution=64us @any PCLK
31 WTCON = ((PCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
32}
33 for(;nTime>0;nTime--)
34 for(i=0;i 36 { 37 WTCON = ((PCLK/1000000-1)<<8)|(2<<3); //Watch-dog timer stop 38 i = 0xffff - WTCNT; //1count->64us, 200*400 cycle runtime = 64*i us 39 delayLoopCount = 8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i) 40} 41 } This is the delay code in the development board routine. I used it directly and the comments are more detailed. Note that the watchdog timer is only used once, when delay(0) is used to calculate the initial value of delayLoopCount. I still don't like this kind of delay method. It's too wasteful to just let the CPU run idle. fs2410_ram.sct 1 ; ************************************************ ************* 2 ; *** Scatter-Loading Description File generated by uVision *** 3;************************************************ ************* 4 5 LR_ROM1 0x30000000 0x00200000 { ; load region size_region 6 ER_ROM1 0x30000000 0x00200000 { ; load address = execution address 7 *.o (RESET, +First) 8 ;*(InRoot$$Sections) 9.ANY (+RO) 10} 11 RW_RAM1 +0 { ; RW data 12.ANY (+RW +ZI) 13} 14} 15 fs2410_flash.sct 1 ; ************************************************ ************* 2 ; *** Scatter-Loading Description File generated by uVision *** 3;************************************************ ************* 4 5 LR_ROM1 0x00000000 0x00200000 { ; load region size_region 6 ER_ROM1 0x00000000 0x00200000 { ; load address = execution address 7 *.o (RESET, +First) 8 ;*(InRoot$$Sections) 9.ANY (+RO) 10} 11 RW_RAM1 0x30000000 0x04000000 { ; RW data 12.ANY (+RW +ZI) 13} 14} DebugInRam.ini 1 FUNC void Init_Board(void) 2 { 3 _WWORD (0x53000000,0x00000000); 4 5 _WWORD (0x4A000008,0xFFFFFFFF); 6 _WWORD (0x4A00001C,0x000007FF); 7 8 _WWORD (0x4C000014,0x3); 9 _WWORD (0x4C000004,0x0005c042); 10 11 _WWORD (0x56000070,0x00280000); 12 _WWORD (0x56000078,0x00000000); 13 14 _WWORD (0x48000000,0x22111110); 15 _WWORD (0x48000004,0x00000700); 16 _WWORD (0x48000008,0x00000700); 17 _WWORD (0x4800000C,0x00000700); 18 _WWORD (0x48000010,0x00000700); 19 _WWORD (0x48000014,0x00000700); 20 _WWORD (0x48000018,0x00000700); 21 _WWORD (0x4800001c,0x00018005); 22 _WWORD (0x48000020,0x00000700); 23 _WWORD (0x48000024,0x008e0459); 24 _WWORD (0x48000028,0x000000B2); 25 _WWORD (0x4800002c,0x00000030); 26 _WWORD (0x48000030,0x00000030); 27 28 _WWORD (0x56000014,0x1); 29 30 _WWORD (0x56000020,0xaaaa55aa); 31 _WWORD (0x56000028,0xffff); 32 _WWORD (0x56000024,0x0); 33 pc = 0x30000000; 34} 35 //map 0x48000000, 0x60000000 read write 36 Init_Board(); 37 In fact, the key to this first project is to be familiar with the processor, board, and development environment. Therefore, the configuration of the project is the key point. fs2410_ram.sct and fs2410_flash.sct are link scripts whose target files are run on ram and flash respectively. They are mainly used to configure the addresses of the program code segment and data segment. ;*(InRoot$$Sections) is commented out because a development board is not needed. For the libraries provided, it is very important to understand the address allocation of the board before writing the program. These two files are generated by realview. You cannot compile the project at the beginning and they will be generated automatically. DebugInRam.ini is the debugging script when the target is running on ram. It was not written by me. It is included in the development board routine, but this is very important. Otherwise, the memory has not been initialized, and there will be problems with the debugger. It cannot be Always run programs on flash. The above three scripts, unless otherwise specified, will be used in subsequent programs and will not be posted again. main.c is very simple. It just contains the header file and then calls myblink. I won’t post it here. This project does not require the startup code provided by the project You can also use S3C2410A.C, but the configuration is more complicated, which is the content of other articles.
Previous article:PLL,FCLK、HCLK、PCLK,AHB/APB (S3C2410)
Next article:Introduction to 3c2410 bare board program---single button (2)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- This week's highlights
- MicroPython version 1.13 released
- How to create a compilation environment for the SINA33 development board
- What are the main parameters of electronic components? What are their respective characteristics?
- Regarding the issue of analog quantity acquisition, please ask the seniors
- [RVB2601 Creative Application Development] MP3 Player
- HuaDa HC32A460 Series Introduction (Part 2)
- 【IoT Development Notes】Gizwits Cloud Device Transplantation RT-Thread
- Semiconductor Industry Online Member System Questionnaire Survey Come and participate to win a 50 yuan Jingdong card! It can be done in 3 minutes~
- DC charging efficiency issues