2440 bare metal program - timer controls LED light flashing

Publisher:Xiaohan521Latest update time:2022-02-11 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The four programs S3C2440A.s; 2440lib.c; main.c; timer.c need to be added to the project.


Main program:


/*****************************************************************************************************

* File name: main.c

* Author: ZXL 

* Description: Use the timer to make the LED light flash once every 0.5 seconds and the buzzer beep once every 0.5 seconds

* History: 2013.5.8

*************************************************************************************************/


#include "def.h"

#include "option.h"

#include "2440addr.h"     

#include "2440lib.h"

   

void dely(U32 tt)

{

   U32 i;

   for(;tt>0;tt--)

        for(i=0;i<10000;i++);

}


void init()

{

U32 i;

U8 key;

U32 mpll_val=0;

    i = 2 ; 

switch ( i ) //Set the clock frequency of 2440

{

case 0: //200

key = 12;

mpll_val = (92<<12)|(4<<4)|(1);

break;

case 1: //300

key = 13;

mpll_val = (67<<12)|(1<<4)|(1);

break;

case 2: //400

key = 14;

mpll_val = (92<<12)|(1<<4)|(1);

break;

case 3: //440!!!

key = 14;

mpll_val = (102<<12)|(1<<4)|(1);

break;

default:

key = 14;

mpll_val = (92<<12)|(1<<4)|(1);

break;

}

//MDIV=92,PDIV=1,SDIV=1 Determined by configuring MPLLCON, MPLL, that is, FCLK=400MHZ

ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);

ChangeClockDivider(key, 12); //FCLK:HCLK:PCLK = 1:1/4:1/8 =400M:100M:50M

    

Port_Init();

  

Uart_Init(0,115200);

    Uart_Select(0);   

Uart_Printf("n flashes once and beeps once every 0.5 seconds!n");

}  

   

int main(int argc, char **argv)

{

init();

led1_port_init();

beep_init();

timer0_init();

Uart_Printf("nTimer Test beginn"); 

    while(1);

      

}


Timer program:


/*****************************************************************************************************

* File name: timer.c

* Author: ZXL 

* Description: Use the timer to make the LED light flash once every 0.5 seconds and the buzzer beep once every 0.5 seconds

* History: 2013.5.8

*************************************************************************************************/



#include "def.h"

#include "option.h"

#include "2440addr.h"

#include "2440lib.h"





#define LED1_ON ~(1<<5)

#define LED2_ON ~(1<<6)

#define LED3_ON ~(1<<7)

#define LED4_ON ~(1<<8)



#define LED1_OFF (1<<5)

#define LED2_OFF (1<<6)

#define LED3_OFF (1<<7)

#define LED4_OFF (1<<8)



void led1_port_init()

{

    rGPBCON &= ~(0x3<<10); //Control register clear

    rGPBCON |= (0x1<<10); //Control register is set to output

rGPBDAT |= (LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF); //All LED lights are off

}



void led1_run()

{

    if(rGPBDAT &(1<<5)) rGPBDAT &=~(1<<5); //The LED light was originally on——> then it turns off

    else rGPBDAT |=(1<<5); //The LED light was off ——> it turns on

}



void beep_init()

{

rGPBCON &= ~(3<<0); //Control register clear

rGPBCON |= (1<<0); //Control register is set to output

}



void beep_run()

{

    if(rGPBDAT &(1<<0)) rGPBDAT &=~(1<<0); //Buzzer beeps——> then stops

    else rGPBDAT |=(1<<0); //Buzzer stops——> then it will beep

}



void __irq IRQ_Timer0_Handle(void)

{

if(rINTPND==BIT_TIMER0) //If BIT_TIMER0 triggers an interrupt, the corresponding BIT_TIMER0 bit in the INTPEND register is set to 1

     ClearPending(BIT_TIMER0); // Clear BIT_TIMER0 interrupt

    led1_run(); //LED flashes

beep_run(); //Buzzer beeps

}



void timer0_init()

{

  rTCFG0 = 49; //The first 50 division pclk/(49+1)=50M/50=1M

  rTCFG1 = 0x03; //The second 16-division frequency = 62500HZ = 1M/16

  rTCNTB0 = 62500/2; //TCNTB0[15:0]=count value  

  rTCMPB0 = 0;

  rTCON |=(1<<1); //Load the count value into TCNTB0, TCMPB0

  rTCON =0x09; //Start timer 0 and automatically reload



  rINTMOD = 0x0; // Set to IRQ mode   

  ClearPending(BIT_TIMER0); // Clear BIT_TIMER0 interrupt

  pISR_TIMER0 = (U32)IRQ_Timer0_Handle; //Correspond the timer execution function to the timer interrupt entry address

  EnableIrq(BIT_TIMER0); //Enable BIT_TIMER0 interrupt

  Uart_Printf("n interrupt type INTMSK=0x%xn",rINTMSK); //Display the internal type of interrupt that the CPU will service 1: shield 0: serviceable

}


Reference address:2440 bare metal program - timer controls LED light flashing

Previous article:2440 bare metal program - serial port sending and receiving data
Next article:2440 bare metal program - key interrupt

Recommended ReadingLatest update time:2024-11-16 14:45

Linux2.6.32 kernel porting s3c2440 - DM9000 network card driver porting
reference: http://caiming1987612.blog.163.com/blog/static/118556676200961752714307/ http://blog.chinaunix.net/u1/34474/showart_401078.html http://hi.baidu.com/%D3%F3%C4%E0%C4%EA%B8%E2/blog/item/6256fea7bfceac98d0435819.html Timing diagram and pin connection: http://blog.chinaunix.net/u1/57901/sho
[Microcontroller]
S3C2440 memory mapping (how to find 1G address with 27 address lines)
          From the data sheet of S3C2440, we know that S3C2440 can address an address range of 1G, but S3C2440 has only 27 address lines, and theoretically can only address an address range of 2 to the power of 27, which is equal to 128M.              Through detailed analysis, we know that S3C2440 solves this probl
[Microcontroller]
S3C2440 memory mapping (how to find 1G address with 27 address lines)
s3c2440 LCD screen driver (built-in kernel) linux-4.1.24
It comes with some driver configuration information. Just modify this part to support different LCD screens - /arch/arm/mach-s3c24xx/mach-smdk2440.c The other part is in /drivers/video/fbdev/s3c2410fb.c First turn on the debugging function so that the kernel can output this information when it starts, or use dmesg
[Microcontroller]
s3c2440 LCD screen driver (built-in kernel) linux-4.1.24
Knowledge of I2C (VI) -- S3C2440 uses I2C interface to access EEPROM
        After reading and understanding the official I2C protocol document, let's use s3c2440 and EEPROM to verify it.         I originally wanted to use the SDA and SCL pins of s3c2440 to multiplex as GPIO to simulate, but I couldn't figure it out after a week without an oscilloscope, so I gave up in the end. I even
[Microcontroller]
Knowledge of I2C (VI) -- S3C2440 uses I2C interface to access EEPROM
Porting U-boot_2016.09 to JZ2440 development board
1. Download source code: U-Boot source code download address http://www.linuxidc.com/Linux/2011-07/38897.htm 2. Initialize compilation: ①make smdk2410_defconfig #First use the default configuration to reduce subsequent configuration work ②make menuconfig #Further configuration according to your o
[Microcontroller]
[JZ2440 Notes] Bare metal experiment using NandFlash
I. Introduction There is no ROM inside the S3C2440 chip to store user code, so the user code needs to be saved in an external memory. If it is NorFlash, you can run the program directly in NorFlash, but NorFlash is more expensive. NandFlash is generally used as the storage medium, and SDRAM is used as the storage medi
[Microcontroller]
[JZ2440 Notes] Bare metal experiment using NandFlash
2440 Bare Metal Programming Part 1: C language calling assembly language programming
1. Inline assembly method, using the keyword __asm{assembly instruction...}. This method is simple to operate, but has many limitations, such as: PC cannot be written, label expressions are not supported, etc. Many normal assembly instructions and pseudo-instructions are not used. Here is an example: //**************
[Microcontroller]
2440 Bare Metal Programming Part 1: C language calling assembly language programming
Summary based on mini2440 timer module
1. From the document, we can know that mini2440 has a total of 5 timers. As shown in the following figure: Among them, the four registers of timer 0, 1, 2, and 3 have output pins, which are combined with the buzzer. Timer 4 has no output pin, so timer 4 is used exclusively for timing. Timers 0 and 1 share an 8-bit
[Microcontroller]
Summary based on mini2440 timer module
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号