OLED 使用手册及c51、k60、x128程序


OLED屏的使用帮助及基于c51 k60 x128的参考程序
资源截图
代码片段和文件信息
/*
 * File:        alloc.c
 * Purpose:     generic malloc() and free() engine
 *
 * Notes:       99% of this code stolen/borrowed from the K&R C
 *              examples.
 *
 */

#include “common.h“
#include “stdlib.h“

#pragma section = “HEAP“

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

/*
 * This struct forms the minimum block size which is allocated and
 * also forms the linked list for the memory space used with alloc()
 * and free().  It is padded so that on a 32-bit machine all malloc‘ed
 * pointers are 16-byte aligned.
 */
typedef struct ALLOC_HDR
{
    struct
    {
        struct ALLOC_HDR     *ptr;
        unsigned int size;
    } s;
    unsigned int align;
    unsigned int pad;
} ALLOC_HDR;

static ALLOC_HDR base;
static ALLOC_HDR *freep = NULL;

/********************************************************************/
void
free (void *ap)
{
    ALLOC_HDR *bp *p;

    bp = (ALLOC_HDR *)ap - 1;   /* point to block header */
    for (p = freep; !((bp > p) && (bp < p->s.ptr)) ; p = p->s.ptr)
    {
        if ((p >= p->s.ptr) && ((bp > p) || (bp < p->s.ptr)))
        {
            break; /* freed block at start or end of arena */
        }
    }

    if ((bp + bp->s.size) == p->s.ptr)
    {
        bp->s.size += p->s.ptr->s.size;
        bp->s.ptr = p->s.ptr->s.ptr;
    }
    else
    {
        bp->s.ptr = p->s.ptr;
    }

    if ((p + p->s.size) == bp)
    {
        p->s.size += bp->s.size;
        p->s.ptr = bp->s.ptr;
    }
    else
    {
        p->s.ptr = bp;
    }

    freep = p;
}

/********************************************************************/
void *
malloc (unsigned nbytes)
{
    /* Get addresses for the HEAP start and end */
#if (defined(CW))
      extern char __HEAP_START;
      extern char __HEAP_END[];
    #elif (defined(IAR))
      char* __HEAP_START = __section_begin(“HEAP“);
      char* __HEAP_END = __section_end(“HEAP“);
    #endif
   
    ALLOC_HDR *p *prevp;
    unsigned nunits;

    nunits = ((nbytes+sizeof(ALLOC_HDR)-1) / sizeof(ALLOC_HDR)) + 1;

    if ((prevp = freep) == NULL)
    {
        p = (ALLOC_HDR *)__HEAP_START;
        p->s.size = ( ((uint32)__HEAP_END - (uint32)__HEAP_START)
            / sizeof(ALLOC_HDR) );
        p->s.ptr = &base;
        base.s.ptr = p;
        base.s.size = 0;
        prevp = freep = &base;
    }

    for (p = prevp->s.ptr; ; prevp = p p = p->s.ptr)
    {
        if (p->s.size >= nunits)
        {
            if (p->s.size == nunits)
            {
                prevp->s.ptr = p->s.ptr;
            }
            else
            {
                p->s.size -= nunits;
                p += p->s.size;
                p->s.size = nunits;
            }
            freep = prevp;
            return (void *)(p + 1);
        }

        if (p == freep)
            return NULL;
    }
}

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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-02-26 20:11  原文件
     目录           0  2014-02-26 20:10  原文件OLED-K60
     文件       28370  2014-02-26 20:10  原文件OLED-K60DEMOK_Kinetis_GPIO_Example.dep
     文件       52169  2013-01-13 23:29  原文件OLED-K60DEMOK_Kinetis_GPIO_Example.ewd
     文件       52981  2013-01-09 19:03  原文件OLED-K60DEMOK_Kinetis_GPIO_Example.ewp
     文件         180  2012-11-07 15:35  原文件OLED-K60DEMOK_Kinetis_GPIO_Example.eww
     目录           0  2013-01-24 21:51  原文件OLED-K60Debug
     目录           0  2014-02-26 20:10  原文件OLED-K60DebugExe
     文件       23095  2014-02-26 20:10  原文件OLED-K60DebugExeDEMOK_Kinetis_GPIO_Example.hex
     文件      184984  2014-02-26 20:10  原文件OLED-K60DebugExeDEMOK_Kinetis_GPIO_Example.out
     目录           0  2014-02-26 20:33  原文件OLED-K60DebugList
     目录           0  2014-02-26 20:10  原文件OLED-K60DebugObj
     文件        1763  2014-02-26 20:10  原文件OLED-K60DebugObjDEMOK_Kinetis_GPIO_Example.pbd
     文件       22900  2013-01-13 23:14  原文件OLED-K60DebugObjFTM.o
     文件       70692  2013-01-13 23:19  原文件OLED-K60DebugObjLQ12864.o
     文件       10000  2013-01-13 23:14  原文件OLED-K60DebugObjPIT.o
     文件       27632  2013-01-13 23:14  原文件OLED-K60DebugObjadc.o
     文件       12072  2013-01-13 23:14  原文件OLED-K60DebugObjalloc.o
     文件       17536  2013-01-13 23:14  原文件OLED-K60DebugObjarm_cm4.o
     文件        8680  2013-01-13 23:14  原文件OLED-K60DebugObjassert.o
     文件        1920  2012-11-10 22:21  原文件OLED-K60DebugObjcrt0.o
     文件        9580  2013-01-13 23:14  原文件OLED-K60DebugObjdelay.o
     文件        8712  2013-01-13 23:14  原文件OLED-K60DebugObjexti.o
     文件       18628  2013-01-13 23:14  原文件OLED-K60DebugObjgpio.o
     文件       10664  2013-01-13 23:14  原文件OLED-K60DebugObjio.o
     文件        3908  2013-01-09 19:02  原文件OLED-K60DebugObjisr.o
     文件        7672  2013-01-13 23:14  原文件OLED-K60DebugObjlptmr.o
     文件        8720  2014-02-26 20:10  原文件OLED-K60DebugObjmain.o
     文件       14104  2013-01-13 23:14  原文件OLED-K60DebugObjmcg.o
     文件       11520  2013-01-09 19:02  原文件OLED-K60DebugObjmemtest.o
     文件       26304  2013-01-13 23:14  原文件OLED-K60DebugObjprintf.o
............此处省略977个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)