ok6410 -- uart & led

;/*************************************************************************************
;
; Project Name : OK6410 Uart & Led
;*************************************************************************************/
.globl main
.globl _start

_start:
    ldr r0,=0x70000000
    orr r0, r0, #0x13
    mcr p15, 0, r0, c15, c2, 4
   
    ldr r0, =0x7E004000
    mov r1, #0
    str r1, [r0]
   
    ldr r0, =0x7F008820
    ldr r1, =0x00221111
    str r1, [r0]
   
    ldr r1, =0x7F008828
    mov r0, #0
    str r0, [r1]
    bl delay
   
    ldr r1, =0x7F008824
    mov r0, #0
    str r0, [r1]
    bl delay

loop:
    mov r0, #0xE
    str r0, [r1]
    bl delay
   
    mov r0, #0xD
    str r0, [r1]
    bl delay
   
    mov r0, #0xB
    str r0, [r1]
    bl delay
   
    mov r0, #0x7
    str r0, [r1]
    bl delay
   
 bl sys_clk_init
    bl        main
   
delay:
    ldr r2, =0x500000
 
delay_loop:
    sub r2, r2, #1
    cmp r2, #0
    bne delay_loop
    mov pc, lr
 
 ;-------------------------- clock init
sys_clk_init:
 ldr r0, =0x7E00F000
 ldr r1, [r0, #0x900]
 mov r2, #0x40
 orr r1, r1, r2
 str r1, [r0, #0x900]
 nop
 nop
 nop
 nop
 
 ldr r2, =0x80
 orr r1, r1, r2
 str r1, [r0, #0x900]
 
 
check_sync_ack:
 ldr r1, [r0, #0x900]
 ldr r2, =0xF00
 and r1, r1, r2
 cmp r1, #0xF00
 bne check_sync_ack
 
 
set_lock_time:
 mov r1, #0xFF00
 orr r1, r1, #0xFF
 str r1, [r0, #0x0]
 str r1, [r0, #0x4]
 str r1, [r0, #0x8]

set_div_clock:
 ldr r1, [r0, #0x20]
 bic r1, r1, #0xFF00
 bic r1, r1, #0xFF
 ldr r2, =0x3300
 orr r1, r1, r2
 str r1, [r0, #0x20]

set_uart_clock:
 ldr r1, [r0, #0x28]
 bic r1, r1, #0x70000
 orr r1, r1, #0x30000
 str r1, [r0, #0x28]

enable_apll_epll:
 ldr r1, =0x810A0301
 str r1, [r0, #0x0c]
 ldr r1, =0x810A0302
 str r1, [r0, #0x10]
 
selete_clk_src:
 ldr r1, [r0, #0x1c]
 ldr r2, =0x2005
 orr r1, r1, r2
 str r1, [r0, #0x1c]
 
    mov pc, lr
 
halt:
    b halt 

;-------------------------------------------------------------------------------

;uart

#define ULCON0     (*((volatile unsigned long *)0x7F005000))
#define UCON0      (*((volatile unsigned long *)0x7F005004))
#define UFCON0     (*((volatile unsigned long *)0x7F005008))
#define UMCON0     (*((volatile unsigned long *)0x7F00500C))
#define UTRSTAT0   (*((volatile unsigned long *)0x7F005010))
#define UFSTAT0    (*((volatile unsigned long *)0x7F005018))
#define UTXH0      (*((volatile unsigned char *)0x7F005020))
#define URXH0      (*((volatile unsigned char *)0x7F005024))
#define UBRDIV0    (*((volatile unsigned short *)0x7F005028))
#define UDIVSLOT0  (*((volatile unsigned short *)0x7F00502C))
#define GPACON     (*((volatile unsigned long *)0x7F008000))

void init_uart(void)
{
 GPACON &= ~0xff;
 GPACON |= 0x22;  /* ULCON0 */
 ULCON0 = 0x3;  /* 数据位:8, 无较验, 停止位: 1, 8n1 */
 UCON0  = 0x5;  /* 使能UART发送、接收 */
 UFCON0 = 0x01; /* FIFO ENABLE */
 UMCON0 = 0;  /* 波特率 */
 /* DIV_VAL = (PCLK / (bps x 16 ) ) - 1  
  * PCLK = 66.5MHz 
  * bps = 115200 
  * DIV_VAL = (66500000 / (115200 x 16 ) ) - 1  
  *         = 35.08 
  */
 UBRDIV0   = 35;
 /* x/16 = 0.08 
  * x = 1 
  */
 UDIVSLOT0 = 0x1;
}

char getchar2(void)
{
 while ((UFSTAT0& (1<<6)) == 0 && (UFSTAT0& 0x3f) == 0);
 return URXH0;
}

void putchar2(char c)
{
 while ((UFSTAT0 & (1<<14)) );
 UTXH0 = c;
}

int main()
{
 char c; 
 init_uart(); 
 while (1)
 { 
  c = getchar2(); 
  putchar2(c);
 } 
 
 return 0;
}

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值