s5pv210 裸机之LED流水灯

1:LED流水灯原理图

s5pv210 裸机之LED流水灯_第1张图片

从地板原理图看出GPJ0_3、GPJ0_4、GPJ0_5、PWMTOUT1输出为低电平则LED亮,所以首先要设置相应引脚为输出模式,在把输出值设置为0

则led亮,查核心板原理图找到相应的引脚,在搜索user_manul设置相应为即可;

2:s5pv210_LED流水灯之汇编代码,代码测试有效

/*
 *        s5pv210裸机实验
 *        
 *        LED流水灯
 *
 */
 
#define WTCON                0xE2700000
#define PS_HOLD_CONTROL      0xE010E81C
#define SVC_STACK            0xD0037D80

//LED相关寄存器
#define _GPJ0CON            0xE0200240
#define _GPJ0DAT            0xE0200244
#define _GPD0CON            0xE02000A0
#define _GPD0DAT            0xE02000A4
#define _GPJ0CON_EN         0x11111111    
#define LED_1_ON            ((0<<3) | (1<<4) | (1<<5))
#define LED_2_ON            ((1<<3) | (0<<4) | (1<<5))
#define LED_3_ON            ((1<<3) | (1<<4) | (0<<5))
#define LED_OFF             ((1<<3) | (1<<4) | (1<<5))

#define DELAY_TIME          10000000
 
    .global _start
_start:
    
    //第一步关看门狗
    ldr r0, =WTCON
    ldr r1, =0x0
    str r1, [r0]
    
    //第二步电源开关置锁,PS_HOLD_CONTROL寄存器中的0、8、9三位置1
    ldr r0, =PS_HOLD_CONTROL
    ldr r1, [r0]
    ldr r2, =0x301
    orr r1, r1, r2
    str r1, [r0]
 
    //设置svc模式下的栈
    ldr sp, =SVC_STACK
    
    //清bss
bss_clean:
    ldr r0, =bss_start            //把bss的起始地址读到r0中
    ldr r1, =bss_end            //把bss的结束地址读到r1中
    mov r2, #0x0                //把r2寄存器写入
    cmp r0, r1                    //对比r0 和r1 如果相等则跳转到led_blink
    beq led_blink
bss_clean_loop:
    str r2, [r0], #4            //不等则把r0地址写入0,r0 + 4
    cmp r0, r1                    //判断r0 r1是否相等 不相等跳转到bss_clean_loop循环
    bne bss_clean_loop
    
    
    
led_blink:    
    //_GPJ0CON设置为输出模式
    ldr r0, =_GPJ0CON            
    ldr r1, =_GPJ0CON_EN
    str r1, [r0]
    
    //_GPD0CON的GPD0_1设置为0001输出模式
    ldr r0, =_GPD0CON
    ldr r1, [r0]
    bic r1, r1, #(0xF<<4)
    orr r1, r1, #(0x1<<4)
    str r1, [r0]
    
led_flash:
    //因为LED4初始m默认是亮的所以先关闭LED4
    ldr r0, =_GPD0DAT
    ldr r1, [r0]
    orr r1, r1, #(0x1<<1)    
    str r1, [r0]

    //流水灯LED1 亮
    ldr r0, =_GPJ0DAT
    ldr r1, =LED_1_ON
    str r1, [r0]
    
    //delay
    bl delay
    
    //流水灯LED2 亮
    ldr r0, =_GPJ0DAT
    ldr r1, =LED_2_ON
    str r1, [r0]
    
    //delay
    bl delay
    
    //流水灯LED3 亮
    ldr r0, =_GPJ0DAT
    ldr r1, =LED_3_ON
    str r1, [r0]
    
    //delay
    bl delay
    
    //全部暗
    ldr r0, =_GPJ0DAT
    ldr r1, =LED_OFF
    str r1, [r0]
    
    //流水灯LED4 亮
    ldr r0, =_GPD0DAT
    ldr r1, [r0]
    bic r1, r1, #(0x1<<1)    
    str r1, [r0]
    
    //delay
    bl delay
    
    b led_flash
    
    
    
    
    
    
    //设置死循环放置跑飞
    b .
    
delay:
    ldr r0, =DELAY_TIME
    mov r1, #0x0
delay_loop:
    subne r0, r0, #1
    cmp r0, r1
    bne delay_loop
    mov pc, lr
    

 

3:s5pv210_LED流水灯之C代码,代码测试有效。

/*
 *        s5pv210裸机实验
 *        
 *        LED流水灯
 *
 */

#include "all.h"
 
#define _REG_GPJ0CON            *((unsigned int*)0xE0200240)
#define _REG_GPJ0DAT            *((unsigned int*)0xE0200244)
#define _REG_GPD0CON            *((unsigned int*)0xE02000A0)
#define _REG_GPD0DAT            *((unsigned int*)0xE02000A4)

//void delay(void);

void led_blink(void)
{
    //GPJ03、4、5设置为output模式
    
    _REG_GPJ0CON = 0x11111111;
    
    //GPD0 1设置为输出模式
    _REG_GPD0CON &= ~(0xF << 4);
    _REG_GPD0CON |= (0x1 << 4);
    
    while (1) {
        
        //led4 暗
        _REG_GPD0DAT |= (1<<1);        ////GPJ03、4、5输出低电平为亮
        //led1 亮
        _REG_GPJ0DAT = ((0<<3) | (1<<4) | (1<<5));                       
        
        //延时
        delay();
        
        //led2 亮
        _REG_GPJ0DAT = ((1<<3) | (0<<4) | (1<<5));
        
        //延时
        delay();
        
        //led3 亮
        _REG_GPJ0DAT = ((1<<3) | (1<<4) | (0<<5));
        
        //延时
        delay();
        //关 1 2 3
        _REG_GPJ0DAT = ((1<<3) | (1<<4) | (1<<5));
        //led4 亮
        _REG_GPD0DAT &= ~(1<<1);        ////延时
        delay();
        
        
        
    }    
}

 

转载于:https://www.cnblogs.com/biaohc/p/6344073.html

你可能感兴趣的:(s5pv210 裸机之LED流水灯)