天天看點

ADS1.2裸闆調試mini2440序列槽 (含源碼)

~~~~~~~~~~~~~~  head.S   ~~~~~~~~~~~~~~~~~~~

  ;*******************************************

; File:head.S

; 功能:設定SDRAM,将程式複制到SDRAM,然後跳到SDRAM繼續執行

;******************************************       

                                IMPORT     Main         ;聲明外部引用

         IMPORT     disable_watch_dog   

         IMPORT     clock_init    

         IMPOR      memsetup  

         AREA     HEAD, CODE, READONLY

         ENTRY

         CODE32  

start                                              ;程式入口點

Reset                  

        ldr sp, =0x32008000           ; 設定棧指針,以下都是C函數,調用前需要設好棧

        bl  disable_watch_dog         ; 關閉WATCHDOG,否則CPU會不斷重新開機

        bl  clock_init                ; 設定MPLL,改變FCLK、HCLK、PCLK

        bl  memsetup                  ; 設定存儲控制器以使用SDRAM

        ldr pc, =on_sdram                   ; 跳到SDRAM中繼續執行

on_sdram

        ldr sp, =0x34000000           ; 設定棧指針,

        ldr lr, =halt_loop            ; 設定傳回位址

        ldr pc, =Main                 ; 調用main函數

halt_loop

        b   halt_loop          END     ################  init.c   ################# #include "s3c24xx.h"

void disable_watch_dog(void);

void clock_init(void);

void memsetup(void);

void disable_watch_dog(void)

{

    WTCON = 0;  // 關閉WATCHDOG很簡單,往這個寄存器寫0即可

}   #define S3C2440_MPLL_200MHZ     ((0x5c<<12)|(0x01<<4)|(0x02))

void clock_init(void)

{

    CLKDIVN  = 0x03;            // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1    

__asm{

    mrc    p15, 0, r1, c1, c0, 0         

    orr    r1, r1, #0xc0000000         

    mcr    p15, 0, r1, c1, c0, 0       

    }     MPLLCON = S3C2440_MPLL_200MHZ; 

}  

void memsetup(void)

{

    volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;    

    p[0] = 0x22011110;     //BWSCON

    p[1] = 0x00000700;     //BANKCON0

    p[2] = 0x00000700;     //BANKCON1

    p[3] = 0x00000700;     //BANKCON2

    p[4] = 0x00000700;     //BANKCON3  

    p[5] = 0x00000700;     //BANKCON4

    p[6] = 0x00000700;     //BANKCON5

    p[7] = 0x00018005;     //BANKCON6

    p[8] = 0x00018005;     //BANKCON7

    p[9]  = 0x008C04F4;

    p[10] = 0x000000B1;     //BANKSIZE

    p[11] = 0x00000030;     //MRSRB6

    p[12] = 0x00000030;     //MRSRB7

}

$$$$$$$$$$$$$$$$  serial.h   $$$$$$$$$$$$$$$   void uart0_init(void);

void putc(unsigned char c);

unsigned char getc(void);

int isDigit(unsigned char c);

int isLetter(unsigned char c);

  ****************  serial.c  **************** #include "s3c24xx.h"

#include "serial.h" #define TXD0READY   (1<<2)

#define RXD0READY   (1) #define PCLK            50000000    // init.c中的clock_init函數設定PCLK為50MHz

#define UART_CLK        PCLK        //  UART0的時鐘源設為PCLK

#define UART_BAUD_RATE  115200      // 波特率

#define UART_BRD        ((UART_CLK  / (UART_BAUD_RATE * 16)) - 1)

void uart0_init(void)

{

    GPHCON  |= 0xa0;    // GPH2,GPH3用作TXD0,RXD0

    GPHUP   = 0x0c;     // GPH2,GPH3内部上拉     ULCON0  = 0x03;     // 8N1(8個資料位,無較驗,1個停止位)

    UCON0   = 0x05;     // 查詢方式,UART時鐘源為PCLK

    UFCON0  = 0x00;     // 不使用FIFO

    UMCON0  = 0x00;     // 不使用流控

    UBRDIV0 = UART_BRD; // 波特率為115200

}

void putc(unsigned char c)

{

    while (!(UTRSTAT0 & TXD0READY));

    UTXH0 = c;

}

unsigned char getc(void)

{

    while (!(UTRSTAT0 & RXD0READY));

    return URXH0;

}

int isDigit(unsigned char c)

{

    if (c >= '0' && c <= '9')

        return 1;

    else

        return 0;       

}

int isLetter(unsigned char c)

{

    if (c >= 'a' && c <= 'z')

        return 1;

    else if (c >= 'A' && c <= 'Z')

        return 1;       

    else

        return 0;

}

  &&&&&&&&&&&&&  main.c &&&&&&&&&&&&&&&&&&   #include "serial.h"

int Main()

{

    unsigned char c;

    uart0_init();   // 波特率115200,8N1(8個資料位,無校驗位,1個停止位)     while(1)

    {

         // 從序列槽接收資料後,判斷其是否數字或子母,若是則加2後輸出

        c = getc();                       //接收資料

        if (isDigit(c) || isLetter(c))     //判斷

            putc(c+2);                      //加2後輸出

   }     return 0;

}

    %%%%%%%%%%%%%  s3c2440   %%%%%%%%%%%%%%%%%%%

#define     WTCON           (*(volatile unsigned long *)0x53000000)

#define     MEM_CTL_BASE    0x48000000

#define     SDRAM_BASE      0x30000000

#define NFCONF              (*(volatile unsigned int  *)0x4e000000)

#define NFCMD               (*(volatile unsigned char *)0x4e000004)

#define NFADDR              (*(volatile unsigned char *)0x4e000008)

#define NFDATA              (*(volatile unsigned char *)0x4e00000c)

#define NFSTAT              (*(volatile unsigned char *)0x4e000010)

#define GPBCON              (*(volatile unsigned long *)0x56000010)

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

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

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

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

#define GPGUP               (*(volatile unsigned long *)0x56000068) #define GPHCON              (*(volatile unsigned long *)0x56000070)

#define GPHDAT              (*(volatile unsigned long *)0x56000074)

#define GPHUP               (*(volatile unsigned long *)0x56000078)  

#define ULCON0              (*(volatile unsigned long *)0x50000000)

#define UCON0               (*(volatile unsigned long *)0x50000004)

#define UFCON0              (*(volatile unsigned long *)0x50000008)

#define UMCON0              (*(volatile unsigned long *)0x5000000c)

#define UTRSTAT0            (*(volatile unsigned long *)0x50000010)

#define UTXH0               (*(volatile unsigned char *)0x50000020)

#define URXH0               (*(volatile unsigned char *)0x50000024)

#define UBRDIV0             (*(volatile unsigned long *)0x50000028)

#define SRCPND              (*(volatile unsigned long *)0x4A000000)

#define INTMOD              (*(volatile unsigned long *)0x4A000004)

#define INTMSK              (*(volatile unsigned long *)0x4A000008)

#define PRIORITY            (*(volatile unsigned long *)0x4A00000c)

#define INTPND              (*(volatile unsigned long *)0x4A000010)

#define INTOFFSET           (*(volatile unsigned long *)0x4A000014)

#define SUBSRCPND           (*(volatile unsigned long *)0x4A000018)

#define INTSUBMSK           (*(volatile unsigned long *)0x4A00001c)

#define EINTMASK            (*(volatile unsigned long *)0x560000a4)

#define EINTPEND            (*(volatile unsigned long *)0x560000a8)

#define LOCKTIME  (*(volatile unsigned long *)0x4c000000)

#define MPLLCON  (*(volatile unsigned long *)0x4c000004)

#define UPLLCON  (*(volatile unsigned long *)0x4c000008)

#define CLKCON  (*(volatile unsigned long *)0x4c00000c)

#define CLKSLOW  (*(volatile unsigned long *)0x4c000010)

#define CLKDIVN  (*(volatile unsigned long *)0x4c000014)

#define TCFG0  (*(volatile unsigned long *)0x51000000)

#define TCFG1  (*(volatile unsigned long *)0x51000004)

#define TCON  (*(volatile unsigned long *)0x51000008)

#define TCNTB0  (*(volatile unsigned long *)0x5100000c)

#define TCMPB0  (*(volatile unsigned long *)0x51000010)

#define TCNTO0  (*(volatile unsigned long *)0x51000014) #define GSTATUS1    (*(volatile unsigned long *)0x560000B0)

繼續閱讀