• ADC裸机程序


    硬件平台:JZ2440

    实现功能:通过采集触摸屏ADC的电压值,推算触摸xy坐标

    start.s

    init.c

    nand.c

    interrupt.c

    uart.c

    uart.h

    my_stdio.c

    my_stdio.h

    screen_touch.c

    screen_touch.h

    s3c24xx.h

    main.c

    start.s

    .extern main interrupt_init   adc_interrupt
    .text
    .global _start
    _start:
    
        b   Reset
    
    HandleUndef:
        b   HandleUndef 
     
    HandleSWI:
        b   HandleSWI
    
    HandlePrefetchAbort:
        b   HandlePrefetchAbort
    
    HandleDataAbort:
        b   HandleDataAbort
    
    HandleNotUsed:
        b   HandleNotUsed
    
        b   HandleIRQ
    
    HandleFIQ:
        b   HandleFIQ
    
    Reset:
          ldr sp,=4096
          bl  watchdog_init
          bl  clock_init
          bl  nand_init
          bl  sdram_init 
          
          ldr r0,=0x30000000
          mov r1,#4096
          mov r2,#(1024*16)
          bl  nand_read
          
          msr cpsr_c,#0xd2
          ldr sp,=0x31000000
          
          msr cpsr_c,#0xdf
          ldr sp,=0x34000000
          
          ldr lr,=interrupt_return 
          ldr pc,=interrupt_init
    interrupt_return:
          msr cpsr_c,#0x5f
    
          ldr lr,=main_return
          ldr pc,=main
    main_return:
          b main_return
          
    HandleIRQ:
          sub lr,lr,#4
          stmdb sp!,{r0-r12,lr}
    
          ldr lr,=adc_return 
          ldr pc,=adc_interrupt
    adc_return:
          ldmia sp!,{r0-r12,pc}^      
          
          
          
          
          
          

    init.c

    //watchdog
    #define WTCON      (*(volatile unsigned long *)0x53000000)
    
    //clock 
    #define LOCKTIME   (*(volatile unsigned long *)0x4c000000)
    #define MPLLCON    (*(volatile unsigned long *)0x4c000004)
    #define CLKDIVN    (*(volatile unsigned long *)0x4c000014)
    
    //sdram 
    #define BWSCON     (*(volatile unsigned long *)0x48000000)
    #define BANKCON0   (*(volatile unsigned long *)0x48000004)
    #define BANKCON1   (*(volatile unsigned long *)0x48000008)
    #define BANKCON2   (*(volatile unsigned long *)0x4800000c)
    #define BANKCON3   (*(volatile unsigned long *)0x48000010)
    #define BANKCON4   (*(volatile unsigned long *)0x48000014)
    #define BANKCON5   (*(volatile unsigned long *)0x48000018)
    #define BANKCON6   (*(volatile unsigned long *)0x4800001c)
    #define BANKCON7   (*(volatile unsigned long *)0x48000020)
    #define REFRESH    (*(volatile unsigned long *)0x48000024)
    #define BANKSIZE   (*(volatile unsigned long *)0x48000028)
    #define MRSRB6     (*(volatile unsigned long *)0x4800002c)
    #define MRSRB7     (*(volatile unsigned long *)0x48000030)
    
    void watchdog_init(void)
    {
        WTCON=0;
    }
    
    
    void clock_init(void)
    {
        CLKDIVN=0x03;    
        __asm__
        (
        "mrc p15,0,r1,c1,c0,0
    "
        "orr r1,r1,#0xc0000000
    "
        "mcr p15,0,r1,c1,c0,0
    "
        );
           MPLLCON=((0x5c<<12)|(0x01<<4)|(0x02));
    }
    
    void sdram_init(void)
    {
        volatile unsigned long *sdram_base=(volatile unsigned long *)0x48000000;
        sdram_base[0]  = 0x22011110;     
        sdram_base[1]  = 0x00000700;    
        sdram_base[2]  = 0x00000700;    
        sdram_base[3]  = 0x00000700;   
        sdram_base[4]  = 0x00000700;    
        sdram_base[5]  = 0x00000700;    
        sdram_base[6]  = 0x00000700;    
        sdram_base[7]  = 0x00018005;    
        sdram_base[8]  = 0x00018005;    
        sdram_base[9]  = 0x008C04F4;
        sdram_base[10] = 0x000000B1;    
        sdram_base[11] = 0x00000030;    
        sdram_base[12] = 0x00000030;     
        
    }

    nand.c

    #define LARGER_NAND_PAGE
    
    #define GSTATUS1        (*(volatile unsigned int *)0x560000B0)
    #define BUSY            1
    
    #define NAND_SECTOR_SIZE    512
    #define NAND_BLOCK_MASK     (NAND_SECTOR_SIZE - 1)
    
    #define NAND_SECTOR_SIZE_LP    2048
    #define NAND_BLOCK_MASK_LP     (NAND_SECTOR_SIZE_LP - 1)
    
    typedef unsigned int S3C24X0_REG32;
    
    
    /* NAND FLASH (see S3C2410 manual chapter 6) */
    typedef struct {
        S3C24X0_REG32   NFCONF;
        S3C24X0_REG32   NFCMD;
        S3C24X0_REG32   NFADDR;
        S3C24X0_REG32   NFDATA;
        S3C24X0_REG32   NFSTAT;
        S3C24X0_REG32   NFECC;
    } S3C2410_NAND;
    
    /* NAND FLASH (see S3C2440 manual chapter 6, www.100ask.net) */
    typedef struct {
        S3C24X0_REG32   NFCONF;
        S3C24X0_REG32   NFCONT;
        S3C24X0_REG32   NFCMD;
        S3C24X0_REG32   NFADDR;
        S3C24X0_REG32   NFDATA;
        S3C24X0_REG32   NFMECCD0;
        S3C24X0_REG32   NFMECCD1;
        S3C24X0_REG32   NFSECCD;
        S3C24X0_REG32   NFSTAT;
        S3C24X0_REG32   NFESTAT0;
        S3C24X0_REG32   NFESTAT1;
        S3C24X0_REG32   NFMECC0;
        S3C24X0_REG32   NFMECC1;
        S3C24X0_REG32   NFSECC;
        S3C24X0_REG32   NFSBLK;
        S3C24X0_REG32   NFEBLK;
    } S3C2440_NAND;
    
    
    typedef struct {
        void (*nand_reset)(void);
        void (*wait_idle)(void);
        void (*nand_select_chip)(void);
        void (*nand_deselect_chip)(void);
        void (*write_cmd)(int cmd);
        void (*write_addr)(unsigned int addr);
        unsigned char (*read_data)(void);
    }t_nand_chip;
    
    static S3C2410_NAND * s3c2410nand = (S3C2410_NAND *)0x4e000000;
    static S3C2440_NAND * s3c2440nand = (S3C2440_NAND *)0x4e000000;
    
    static t_nand_chip nand_chip;
    
    /* 供外部调用的函数 */
    void nand_init(void);
    void nand_read(unsigned char *buf, unsigned long start_addr, int size);
    
    /* NAND Flash操作的总入口, 它们将调用S3C2410或S3C2440的相应函数 */
    static void nand_reset(void);
    static void wait_idle(void);
    static void nand_select_chip(void);
    static void nand_deselect_chip(void);
    static void write_cmd(int cmd);
    static void write_addr(unsigned int addr);
    static unsigned char read_data(void);
    
    /* S3C2410的NAND Flash处理函数 */
    static void s3c2410_nand_reset(void);
    static void s3c2410_wait_idle(void);
    static void s3c2410_nand_select_chip(void);
    static void s3c2410_nand_deselect_chip(void);
    static void s3c2410_write_cmd(int cmd);
    static void s3c2410_write_addr(unsigned int addr);
    static unsigned char s3c2410_read_data();
    
    /* S3C2440的NAND Flash处理函数 */
    static void s3c2440_nand_reset(void);
    static void s3c2440_wait_idle(void);
    static void s3c2440_nand_select_chip(void);
    static void s3c2440_nand_deselect_chip(void);
    static void s3c2440_write_cmd(int cmd);
    static void s3c2440_write_addr(unsigned int addr);
    static unsigned char s3c2440_read_data(void);
    
    /* S3C2410的NAND Flash操作函数 */
    
    /* 复位 */
    static void s3c2410_nand_reset(void)
    {
        s3c2410_nand_select_chip();
        s3c2410_write_cmd(0xff);  // 复位命令
        s3c2410_wait_idle();
        s3c2410_nand_deselect_chip();
    }
    
    /* 等待NAND Flash就绪 */
    static void s3c2410_wait_idle(void)
    {
        int i;
        volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFSTAT;
        while(!(*p & BUSY))
            for(i=0; i<10; i++);
    }
    
    /* 发出片选信号 */
    static void s3c2410_nand_select_chip(void)
    {
        int i;
        s3c2410nand->NFCONF &= ~(1<<11);
        for(i=0; i<10; i++);    
    }
    
    /* 取消片选信号 */
    static void s3c2410_nand_deselect_chip(void)
    {
        s3c2410nand->NFCONF |= (1<<11);
    }
    
    /* 发出命令 */
    static void s3c2410_write_cmd(int cmd)
    {
        volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFCMD;
        *p = cmd;
    }
    
    /* 发出地址 */
    static void s3c2410_write_addr(unsigned int addr)
    {
        int i;
        volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFADDR;
        
        *p = addr & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 9) & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 17) & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 25) & 0xff;
        for(i=0; i<10; i++);
    }
    
    /* 读取数据 */
    static unsigned char s3c2410_read_data(void)
    {
        volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFDATA;
        return *p;
    }
    
    /* S3C2440的NAND Flash操作函数 */
    
    /* 复位 */
    static void s3c2440_nand_reset(void)
    {
        s3c2440_nand_select_chip();
        s3c2440_write_cmd(0xff);  // 复位命令
        s3c2440_wait_idle();
        s3c2440_nand_deselect_chip();
    }
    
    /* 等待NAND Flash就绪 */
    static void s3c2440_wait_idle(void)
    {
        int i;
        volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFSTAT;
        while(!(*p & BUSY))
            for(i=0; i<10; i++);
    }
    
    /* 发出片选信号 */
    static void s3c2440_nand_select_chip(void)
    {
        int i;
        s3c2440nand->NFCONT &= ~(1<<1);
        for(i=0; i<10; i++);    
    }
    
    /* 取消片选信号 */
    static void s3c2440_nand_deselect_chip(void)
    {
        s3c2440nand->NFCONT |= (1<<1);
    }
    
    /* 发出命令 */
    static void s3c2440_write_cmd(int cmd)
    {
        volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFCMD;
        *p = cmd;
    }
    
    /* 发出地址 */
    static void s3c2440_write_addr(unsigned int addr)
    {
        int i;
        volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;
        
        *p = addr & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 9) & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 17) & 0xff;
        for(i=0; i<10; i++);
        *p = (addr >> 25) & 0xff;
        for(i=0; i<10; i++);
    }
    
    
    static void s3c2440_write_addr_lp(unsigned int addr)
    {
        int i;
        volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;
        int col, page;
    
        col = addr & NAND_BLOCK_MASK_LP;
        page = addr / NAND_SECTOR_SIZE_LP;
        
        *p = col & 0xff;            /* Column Address A0~A7 */
        for(i=0; i<10; i++);        
        *p = (col >> 8) & 0x0f;     /* Column Address A8~A11 */
        for(i=0; i<10; i++);
        *p = page & 0xff;            /* Row Address A12~A19 */
        for(i=0; i<10; i++);
        *p = (page >> 8) & 0xff;    /* Row Address A20~A27 */
        for(i=0; i<10; i++);
        *p = (page >> 16) & 0x03;    /* Row Address A28~A29 */
        for(i=0; i<10; i++);
    }
    
    
    /* 读取数据 */
    static unsigned char s3c2440_read_data(void)
    {
        volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFDATA;
        return *p;
    }
    
    
    /* 在第一次使用NAND Flash前,复位一下NAND Flash */
    static void nand_reset(void)
    {
        nand_chip.nand_reset();
    }
    
    static void wait_idle(void)
    {
        nand_chip.wait_idle();
    }
    
    static void nand_select_chip(void)
    {
        int i;
        nand_chip.nand_select_chip();
        for(i=0; i<10; i++);
    }
    
    static void nand_deselect_chip(void)
    {
        nand_chip.nand_deselect_chip();
    }
    
    static void write_cmd(int cmd)
    {
        nand_chip.write_cmd(cmd);
    }
    static void write_addr(unsigned int addr)
    {
        nand_chip.write_addr(addr);
    }
    
    static unsigned char read_data(void)
    {
        return nand_chip.read_data();
    }
    
    
    /* 初始化NAND Flash */
    void nand_init(void)
    {
    #define TACLS   0
    #define TWRPH0  3
    #define TWRPH1  0
    
        /* 判断是S3C2410还是S3C2440 */
        if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))
        {
            nand_chip.nand_reset         = s3c2410_nand_reset;
            nand_chip.wait_idle          = s3c2410_wait_idle;
            nand_chip.nand_select_chip   = s3c2410_nand_select_chip;
            nand_chip.nand_deselect_chip = s3c2410_nand_deselect_chip;
            nand_chip.write_cmd          = s3c2410_write_cmd;
            nand_chip.write_addr         = s3c2410_write_addr;
            nand_chip.read_data          = s3c2410_read_data;
    
            /* 使能NAND Flash控制器, 初始化ECC, 禁止片选, 设置时序 */
            s3c2410nand->NFCONF = (1<<15)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);
        }
        else
        {
            nand_chip.nand_reset         = s3c2440_nand_reset;
            nand_chip.wait_idle          = s3c2440_wait_idle;
            nand_chip.nand_select_chip   = s3c2440_nand_select_chip;
            nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip;
            nand_chip.write_cmd          = s3c2440_write_cmd;
    #ifdef LARGER_NAND_PAGE
            nand_chip.write_addr         = s3c2440_write_addr_lp;
    #else
            nand_chip.write_addr         = s3c2440_write_addr;
    #endif
            nand_chip.read_data          = s3c2440_read_data;
    
            /* 设置时序 */
            s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4);
            /* 使能NAND Flash控制器, 初始化ECC, 禁止片选 */
            s3c2440nand->NFCONT = (1<<4)|(1<<1)|(1<<0);
        }
        
        /* 复位NAND Flash */
        nand_reset();
    }
    
    
    /* 读函数 */
    void nand_read(unsigned char *buf, unsigned long start_addr, int size)
    {
        int i, j;
    
    #ifdef LARGER_NAND_PAGE
        if ((start_addr & NAND_BLOCK_MASK_LP) || (size & NAND_BLOCK_MASK_LP)) {
            return ;    /* 地址或长度不对齐 */
        }
    #else
        if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
            return ;    /* 地址或长度不对齐 */
        }
    #endif    
    
        /* 选中芯片 */
        nand_select_chip();
    
        for(i=start_addr; i < (start_addr + size);) {
          /* 发出READ0命令 */
          write_cmd(0);
    
          /* Write Address */
          write_addr(i);
    #ifdef LARGER_NAND_PAGE
          write_cmd(0x30);        
    #endif
          wait_idle();
    
    #ifdef LARGER_NAND_PAGE
          for(j=0; j < NAND_SECTOR_SIZE_LP; j++, i++) {
    #else
          for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
    #endif
              *buf = read_data();
              buf++;
          }
        }
    
        /* 取消片选信号 */
        nand_deselect_chip();
        
        return ;
    }

    interrupt.c

    #include"s3c24xx.h"
    
    
    void (*isr_handle_isr[32])(void);
    
    void interrupt_init(void)
    {
        INTMOD=0x0;
        INTMSK=0xffffffff;
    }
     
    
    void adc_interrupt(void)
    {
        unsigned long offset=INTOFFSET;
        
        SRCPND=1<<offset;    
        INTPND=INTPND;    
        isr_handle_isr[oft]();
    }

    uart.c

    #include"uart.h"
    
    
    //uart 
    #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  UERSTAT0    (*(volatile unsigned long *)0x50000014)
    #define  UTXH0       (*(volatile unsigned char *)0x50000020)
    #define  URXH0       (*(volatile unsigned char *)0x50000024)
    #define  UBRDIV0     (*(volatile unsigned long *)0x50000028)
    
    //GPH
    #define  GPHCON      (*(volatile unsigned long *)0x56000070)
    #define  GPHDAT      (*(volatile unsigned long *)0x56000074)
    #define  GPHUP       (*(volatile unsigned long *)0x56000078)
    
    
    void uart0_init(void)
    {
        GPHCON|=0xa0;
        GPHUP=0x0c;
        
        ULCON0=0x03;    
        UCON0=0x05;
        UFCON0=0x00;     
        UMCON0=0x00;     
        UBRDIV0=((50000000/(115200*16))-1);    
    }
    
    unsigned char my_getchar(void)
    {
        while(!(UTRSTAT0 & 0x01));
        return URXH0;
    }
    
    
    void my_putchar(unsigned char date)
    {
        while(!(UTRSTAT0 & 0x02));
        UTXH0=date;
    }
    
    unsigned char getc(void)
    {
         while(!(UTRSTAT0 & 0x01));
         return URXH0;
    }
    
    void putc(unsigned char c)
    {
        while(!(UTRSTAT0 & 0x02));
        UTXH0=c;
    }

    uart.h

    #ifndef _UART_H_ 
    #define _UART_H_ 
    
    void uart0_init(void);
    unsigned char my_getchar(void);
    void my_putchar(unsigned char date);
    
    unsigned char getc(void);
    void putc(unsigned char c);
    
    
    #endif

    my_stdio.c

    #include"uart.h"
    #include"my_stdio.h"
    
    
    typedef char* va_list;
    
    #define int_sizeof(type)             ((sizeof(int)+sizeof(type)-1)&~(sizeof(int)-1))
    
    #define va_start(para_p,first_para)  (para_p=(va_list)&first_para+int_sizeof(first_para)) 
    #define va_arg(para_p,type)          (*(type *)((para_p+=int_sizeof(type))-int_sizeof(type)))  
    #define va_end(para_p)               (para_p=(va_list)0)  
    
    
    void my_printf(const char *format, ...)
    {
        va_list temp ;
        char *string = format;     
        va_start(temp, format);    
    
        while (*string)
        {
            if (*string == '%')
            {
                switch (*++string)
                {
                   case 'c':     {  my_putchar(va_arg(temp,char)); break; }
                   case 's':
                   {
                       char* p = va_arg(temp,char*);
                       while (*p != 0) my_putchar(*p++);
                       break;
                   }
    
                   case 'p':
                   {               
                       unsigned int addr = (unsigned int)&va_arg(temp, unsigned int), sheft = 0xf0000000;
                       unsigned char temp = 0,count=0;
                       my_putchar('0');
                       my_putchar('x');
                       while (count<32)
                       {
                           temp = (unsigned char)(((sheft >> count)&addr) >> (32 - count - 4)) ; 
                           if (temp < 10) my_putchar(temp + 48);
                           if (temp >= 10) my_putchar(temp+65-10);
                           count += 4;
                       }
                       break;
                   }
    
                   case 'd':
                   {
                       int value = va_arg(temp, int),num=100000000;
                       if (value == 0) my_putchar(48);
                       if (value & 0x80000000)    //负数
                       {
                           my_putchar('-');
                           num = -10000000;
                       }
                       else                       //正数.;            
                       while (!(value / num))
                               { 
                                   num /= 10; 
                                   if (num == 0)
                                   {
                                       my_putchar(0);
                                       return;
                                   }
                                }
                              while (num != 0)
                                   {
                                       my_putchar(value / num+48);
                                       value %= num;
                                       num /= 10;
                                   }
                              break;
                   }
    
                   case 'f':
                   {
                       char *str = "Sorry: function is not available";
                       while (*str != 0) my_putchar(*str++);
                   }
    
                default: break;
                }
            }
            string++;
        }
        va_end(temp);
    }                    

    my_stdio.h

    #ifndef  _OWN_STDIO_H_
    #define  _OWN_STDIO_H_
    
    
    
    
    void my_printf(const char *format,...);
    
    
    
    
    
    
    #endif

    screen_touch.c

    #include"s3c24xx.h"
    #include"stdio.h"
    
    // ADCCON寄存器
    #define PRESCALE_DIS        (0 << 14)
    #define PRESCALE_EN         (1 << 14)
    #define PRSCVL(x)           ((x) << 6)
    #define ADC_INPUT(x)        ((x) << 3)
    #define ADC_START           (1 << 0)
    #define ADC_ENDCVT          (1 << 15)
    
    // ADCTSC寄存器
    #define UD_SEN          (1 << 8)
    #define DOWN_INT        (UD_SEN*0)
    #define UP_INT          (UD_SEN*1)
    #define YM_SEN          (1 << 7)
    #define YM_HIZ          (YM_SEN*0)
    #define YM_GND          (YM_SEN*1)
    #define YP_SEN          (1 << 6)
    #define YP_EXTVLT       (YP_SEN*0)
    #define YP_AIN          (YP_SEN*1)
    #define XM_SEN          (1 << 5)
    #define XM_HIZ          (XM_SEN*0)
    #define XM_GND          (XM_SEN*1)
    #define XP_SEN          (1 << 4)
    #define XP_EXTVLT       (XP_SEN*0)
    #define XP_AIN          (XP_SEN*1)
    #define XP_PULL_UP      (1 << 3)
    #define XP_PULL_UP_EN   (XP_PULL_UP*0)
    #define XP_PULL_UP_DIS  (XP_PULL_UP*1)
    #define AUTO_PST        (1 << 2)
    #define CONVERT_MAN     (AUTO_PST*0)
    #define CONVERT_AUTO    (AUTO_PST*1)
    #define XP_PST(x)       (x << 0)
    
    #define NOP_MODE        0
    #define X_AXIS_MODE     1
    #define Y_AXIS_MODE     2
    #define WAIT_INT_MODE   3
    
    
    
    #define wait_down_int() { ADCTSC = DOWN_INT | XP_PULL_UP_EN | 
                              XP_AIN | XM_HIZ | YP_AIN | YM_GND | 
                              XP_PST(WAIT_INT_MODE); }
    
    #define wait_up_int()   { ADCTSC = UP_INT | XP_PULL_UP_EN | XP_AIN | XM_HIZ | 
                              YP_AIN | YM_GND | XP_PST(WAIT_INT_MODE); }
    
    #define mode_auto_xy()  { ADCTSC = CONVERT_AUTO | XP_PULL_UP_DIS | XP_PST(NOP_MODE); }
    
    
    extern void (*isr_handle_array[50])(void);
    
    static void screen_touch_interrupt(void)
    {
         
        printf("xdata = %4d, ydata = %4d
    ", (int)(ADCDAT0 & 0x3ff), (int)(ADCDAT1 & 0x3ff));
        wait_up_int();        
        SUBSRCPND |= BIT_SUB_ADC;
        SRCPND    |= BIT_ADC;
        INTPND    |= BIT_ADC;
    }
    
    
    void screen_touch(void)
    {
        isr_handle_isr[ISR_ADC_OFT]=screen_touch_interrupt;
        INTMSK &= ~BIT_ADC;        
        INTSUBMSK &= ~(BIT_SUB_TC); 
        INTSUBMSK &= ~(BIT_SUB_ADC); 
        ADCCON = PRESCALE_EN | PRSCVL(49);
        ADCDLY = 50000;
        wait_down_int();    
        INTSUBMSK |= BIT_SUB_TC;
        INTSUBMSK |= BIT_SUB_ADC;
        INTMSK |= BIT_ADC;
        
        
        
    }

    screen_touch.h

    #ifndef _SCREEN_TOUCH_H_
    #define _SCREEN_TOUCH_H_
    
    
    void screen_touch(void);
    
    
    #endif

    s3c24xx.h

    /* WOTCH DOG register */
    #define     WTCON           (*(volatile unsigned long *)0x53000000)
    #define     WTDAT           (*(volatile unsigned long *)0x53000004)
    #define     WTCNT           (*(volatile unsigned long *)0x53000008)
    
    /* SDRAM regisers */
    #define     MEM_CTL_BASE    0x48000000
    #define     SDRAM_BASE      0x30000000
    
    /* GPIO registers */
    #define GPACON              (*(volatile unsigned long *)0x56000000)
    #define GPADAT              (*(volatile unsigned long *)0x56000004)
    
    #define GPBCON              (*(volatile unsigned long *)0x56000010)
    #define GPBDAT              (*(volatile unsigned long *)0x56000014)
    #define GPBUP               (*(volatile unsigned long *)0x56000018)
    
    #define GPCCON              (*(volatile unsigned long *)0x56000020)
    #define GPCDAT              (*(volatile unsigned long *)0x56000024)
    #define GPCUP               (*(volatile unsigned long *)0x56000028)
    
    #define GPDCON              (*(volatile unsigned long *)0x56000030)
    #define GPDDAT              (*(volatile unsigned long *)0x56000034)
    #define GPDUP               (*(volatile unsigned long *)0x56000038)
    
    #define GPECON                (*(volatile unsigned long *)0x56000040)
    #define GPEDAT                (*(volatile unsigned long *)0x56000044)
    #define GPEUP                 (*(volatile unsigned long *)0x56000048)
    
    #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)
    
    // ADC
    #define ADCCON      (*(volatile unsigned long *)0x58000000)    //ADC control
    #define ADCTSC      (*(volatile unsigned long *)0x58000004)    //ADC touch screen control
    #define ADCDLY      (*(volatile unsigned long *)0x58000008)    //ADC start or Interval Delay
    #define ADCDAT0     (*(volatile unsigned long *)0x5800000c)    //ADC conversion data 0
    #define ADCDAT1     (*(volatile unsigned long *)0x58000010)    //ADC conversion data 1
    #define ADCUPDN     (*(volatile unsigned long *)0x58000014)    //Stylus Up/Down interrupt status
    
    
    /*UART registers*/
    #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)
    
    
    /*interrupt registes*/
    #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)
    
    /*external interrupt registers*/
    #define EINTMASK            (*(volatile unsigned long *)0x560000a4)
    #define EINTPEND            (*(volatile unsigned long *)0x560000a8)
    
    /*clock registers*/
    #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)
    
    
    /*PWM & Timer registers*/
    #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)
    
    /* I2C registers */
    #define IICCON      (*(volatile unsigned char *)0x54000000) // IIC control
    #define IICSTAT     (*(volatile unsigned char *)0x54000004) // IIC status
    #define IICADD      (*(volatile unsigned char *)0x54000008) // IIC address
    #define IICDS       (*(volatile unsigned char *)0x5400000c) // IIC data shift
    
    // LCD CONTROLLER
    #define LCDCON1     (*(volatile unsigned long *)0x4d000000) //LCD control 1
    #define LCDCON2     (*(volatile unsigned long *)0x4d000004) //LCD control 2
    #define LCDCON3     (*(volatile unsigned long *)0x4d000008) //LCD control 3
    #define LCDCON4     (*(volatile unsigned long *)0x4d00000c) //LCD control 4
    #define LCDCON5     (*(volatile unsigned long *)0x4d000010) //LCD control 5
    #define LCDSADDR1   (*(volatile unsigned long *)0x4d000014) //STN/TFT Frame buffer start address 1
    #define LCDSADDR2   (*(volatile unsigned long *)0x4d000018) //STN/TFT Frame buffer start address 2
    #define LCDSADDR3   (*(volatile unsigned long *)0x4d00001c) //STN/TFT Virtual screen address set
    #define REDLUT      (*(volatile unsigned long *)0x4d000020) //STN Red lookup table
    #define GREENLUT    (*(volatile unsigned long *)0x4d000024) //STN Green lookup table 
    #define BLUELUT     (*(volatile unsigned long *)0x4d000028) //STN Blue lookup table
    #define DITHMODE    (*(volatile unsigned long *)0x4d00004c) //STN Dithering mode
    #define TPAL        (*(volatile unsigned long *)0x4d000050) //TFT Temporary palette
    #define LCDINTPND   (*(volatile unsigned long *)0x4d000054) //LCD Interrupt pending
    #define LCDSRCPND   (*(volatile unsigned long *)0x4d000058) //LCD Interrupt source
    #define LCDINTMSK   (*(volatile unsigned long *)0x4d00005c) //LCD Interrupt mask
    #define LPCSEL      (*(volatile unsigned long *)0x4d000060) //LPC3600 Control
    #define PALETTE     0x4d000400                              //Palette start address
    
    #define ISR_EINT0_OFT     0
    #define ISR_EINT1_OFT     1
    #define ISR_EINT2_OFT     2
    #define ISR_EINT3_OFT     3
    #define ISR_EINT4_7_OFT   4
    #define ISR_EINT8_23_OFT  5
    #define ISR_NOTUSED6_OFT  6
    #define ISR_BAT_FLT_OFT   7
    #define ISR_TICK_OFT      8
    #define ISR_WDT_OFT       9
    #define ISR_TIMER0_OFT    10
    #define ISR_TIMER1_OFT    11
    #define ISR_TIMER2_OFT    12
    #define ISR_TIMER3_OFT    13
    #define ISR_TIMER4_OFT    14
    #define ISR_UART2_OFT     15
    #define ISR_LCD_OFT       16
    #define ISR_DMA0_OFT      17
    #define ISR_DMA1_OFT      18
    #define ISR_DMA2_OFT      19
    #define ISR_DMA3_OFT      20
    #define ISR_SDI_OFT       21
    #define ISR_SPI0_OFT      22
    #define ISR_UART1_OFT     23
    #define ISR_NOTUSED24_OFT 24
    #define ISR_USBD_OFT      25
    #define ISR_USBH_OFT      26
    #define ISR_IIC_OFT       27
    #define ISR_UART0_OFT     28
    #define ISR_SPI1_OFT      29
    #define ISR_RTC_OFT       30
    #define ISR_ADC_OFT       31
    
    
    // PENDING BIT
    #define BIT_EINT0        (0x1)
    #define BIT_EINT1        (0x1<<1)
    #define BIT_EINT2        (0x1<<2)
    #define BIT_EINT3        (0x1<<3)
    #define BIT_EINT4_7        (0x1<<4)
    #define BIT_EINT8_23    (0x1<<5)
    #define BIT_CAM            (0x1<<6)        // Added for 2440.
    #define BIT_BAT_FLT        (0x1<<7)
    #define BIT_TICK        (0x1<<8)
    #define BIT_WDT_AC97    (0x1<<9)
    #define BIT_TIMER0        (0x1<<10)
    #define BIT_TIMER1        (0x1<<11)
    #define BIT_TIMER2        (0x1<<12)
    #define BIT_TIMER3        (0x1<<13)
    #define BIT_TIMER4        (0x1<<14)
    #define BIT_UART2        (0x1<<15)
    #define BIT_LCD            (0x1<<16)
    #define BIT_DMA0        (0x1<<17)
    #define BIT_DMA1        (0x1<<18)
    #define BIT_DMA2        (0x1<<19)
    #define BIT_DMA3        (0x1<<20)
    #define BIT_SDI            (0x1<<21)
    #define BIT_SPI0        (0x1<<22)
    #define BIT_UART1        (0x1<<23)
    #define BIT_NFCON        (0x1<<24)        // Added for 2440.
    #define BIT_USBD        (0x1<<25)
    #define BIT_USBH        (0x1<<26)
    #define BIT_IIC            (0x1<<27)
    #define BIT_UART0        (0x1<<28)
    #define BIT_SPI1        (0x1<<29)
    #define BIT_RTC            (0x1<<30)
    #define BIT_ADC            (0x1<<31)
    #define BIT_ALLMSK        (0xffffffff)
    
    #define BIT_SUB_ALLMSK    (0x7fff)
    #define BIT_SUB_AC97     (0x1<<14)
    #define BIT_SUB_WDT     (0x1<<13)
    #define BIT_SUB_CAM_S    (0x1<<12)        // Added for 2440.
    #define BIT_SUB_CAM_C    (0x1<<11)        // Added for 2440.
    #define BIT_SUB_ADC        (0x1<<10)
    #define BIT_SUB_TC        (0x1<<9)
    #define BIT_SUB_ERR2    (0x1<<8)
    #define BIT_SUB_TXD2    (0x1<<7)
    #define BIT_SUB_RXD2    (0x1<<6)
    #define BIT_SUB_ERR1    (0x1<<5)
    #define BIT_SUB_TXD1    (0x1<<4)
    #define BIT_SUB_RXD1    (0x1<<3)
    #define BIT_SUB_ERR0    (0x1<<2)
    #define BIT_SUB_TXD0    (0x1<<1)
    #define BIT_SUB_RXD0    (0x1<<0)
    
    #define GSTATUS1    (*(volatile unsigned long *)0x560000B0)

    main.c

    #include"uart.h"
    #include"my_stdio.h"
    #include"screen_touch.h"
    
    
    void raise(int sig_nr){;}
    
    
    int main(void)
    {
         uart0_init();
       while(1)
         screen_touch();
         return 0;
    }

    uart.lds

    SECTIONS
    {
      . = 0x00000000;
      .init : AT(0){start.o init.o nand.o}
      . = 0x30000000;
      .text : AT(4096){*(.text)}
      .rodata ALIGN(4) :  AT((LOADADDR(.text)+SIZEOF(.text)+3)&~(0x03)) {*(.rodata*)}
      .data  ALIGN(4) :  AT((LOADADDR(.rodata)+SIZEOF(.rodata)+3)&~(0x03)) {*(.data)}
      .bss   : {*(.bss) *(COMMON)}
    }

    Makefile:

    objs:= start.o init.o uart.o nand.o main.o my_stdio.o scrennt_touch.o interrupt.o lib/libc.a
    
    CC            =arm-linux-gcc 
    LD            =arm-linux-ld 
    AR            =arm-linux-ar 
    OBJCOPY       =arm-linux-objcopy 
    OBJDUMP       =arm-linux-objdump
    
    INCLUDEDIR    :=$(shell pwd)/include 
    CFLAGS        :=-Wall -O2
    CPPFLAGS      :=-nostdinc -I$(INCLUDEDIR)
    
    export     CC LD OBJCOPY OBJDUMP INCLUDEDIR CFLAGS CPPFLAGS
    
    uart.bin:$(objs)
        arm-linux-ld -Tuart.lds -o uart_elf $^ libgcc.a
        arm-linux-objcopy -O binary -S uart_elf $@
        arm-linux-objdump -D -m arm uart_elf > uart.dis
    
    .PHONY:lib/libc.a
    lib/libc.a:
        cd lib;make;cd ..
    
    
    %.o:%.s
        $(CC) $(CPPFLAGS) $(FLAGS)-o $@ -c $<
    
    %.o:%.c
        $(CC) $(CPPFLAGS) $(FLAGS) -o $@ -c $<
    
    clean:
        make  clean -C lib
        rm -f *.o *.bin *.dis uart_elf
        
        
        
        
        
        
  • 相关阅读:
    ##微信登陆,给大家分享一个第三方登陆
    ##Solr的各种版本下载
    ##redis在linux上的安装详解
    ##activeMq的简介与安装
    ##Springboot框架--配置文件介绍
    论面向服务架构及其应用
    MVC架构模式
    第八周总结
    细化架构阅读笔记
    第五周总结
  • 原文地址:https://www.cnblogs.com/zsy12138/p/10408377.html
Copyright © 2020-2023  润新知