理论教材《嵌入式系统开发与应用技术教程》部分程序代码Word格式.docx
《理论教材《嵌入式系统开发与应用技术教程》部分程序代码Word格式.docx》由会员分享,可在线阅读,更多相关《理论教材《嵌入式系统开发与应用技术教程》部分程序代码Word格式.docx(97页珍藏版)》请在冰豆网上搜索。
x2)?
x1:
x2)
#definemax(x1,x2)((x1>
#defineONESEC0(62500)//16usresolution,max1.04sec
#defineONESEC1(31250)//32usresolution,max2.09sec
#defineONESEC2(15625)//64usresolution,max4.19sec
#defineONESEC3(7812)//128usresolution,max8.38sec
#defineONESEC4(MCLK/128/(0xff+1))//@60Mhz,128*4usresolution,max32.53sec
#defineNULL0
#defineEnterPWDN(clkcon)((void(*)(int))0xe0)(clkcon)
#defineDOWNLOAD_ADDRESS_RAM_STARTADDRESS
/*8ledcontrolregisteraddress*/
#defineLED8ADDR(*(volatileunsignedchar*)(0x2140000))
#defineLCD0xFF
#defineUART0xFE
/*44blib.c
本部分内容对开发中用到的一些库函数作函数原型定义*/
voidDelay(inttime);
//WatchdogTimerisused.
voidDelayMs(intms_time);
void*malloc(unsignednbyte);
voidfree(void*pt);
voidPort_Init(void);
voidCache_Flush(void);
voidChangeMemCon(unsigned*pMemCfg);
voidUart_Select(intch);
voidUart_TxEmpty(intch);
voidUart_Init(intmclk,intbaud);
charUart_Getch(void);
charUart_GetKey(void);
intUart_GetIntNum(void);
voidUart_SendByte(intdata);
voidUart_Printf(char*fmt,...);
voidUart_SendString(char*pt);
voidTimer_Start(intdivider);
//WatchdogTimerisused.
intTimer_Stop(void);
//WatchdogTimerisused.
voidLed_Display(intLedStatus);
voidBeep(intBeepStatus);
voidChangePllValue(intm,intp,ints);
}
#endif/*__44BLIB_H__*/
◆"
44b.h"
主要是用宏的方式定义了程序中所需的44B0X片上涉及到各模块中各寄存器的宏定义的地址。
内容如下所示:
/******************************************************************************
44B.H
Samsung44B0XCPUregisterdefine
******************************************************************************/
#ifndef__44B0X_H__
#define__44B0X_H__
#include"
option.h"
/*System
本部分内容定义了44b0的系统配置寄存器地址*/
#definerSYSCFG(*(volatileunsigned*)0x1c00000)
/*Cache
本部分定义了44b0中2个不可作Cache存储区的起始与结束地址的寄存器的地址*/
#definerNCACHBE0(*(volatileunsigned*)0x1c00004)
#definerNCACHBE1(*(volatileunsigned*)0x1c00008)
/*Buscontrol
本部分定义了44b0中存储总线控制器的优先级的寄存器地址*/
#definerSBUSCON(*(volatileunsigned*)0x1c40000)
/*Memorycontrol
本部分定义了44b0中与存储器相关的寄存器地址*/
#definerBWSCON(*(volatileunsigned*)0x1c80000)
#definerBANKCON0(*(volatileunsigned*)0x1c80004)
#definerBANKCON1(*(volatileunsigned*)0x1c80008)
#definerBANKCON2(*(volatileunsigned*)0x1c8000c)
#definerBANKCON3(*(volatileunsigned*)0x1c80010)
#definerBANKCON4(*(volatileunsigned*)0x1c80014)
#definerBANKCON5(*(volatileunsigned*)0x1c80018)
#definerBANKCON6(*(volatileunsigned*)0x1c8001c)
#definerBANKCON7(*(volatileunsigned*)0x1c80020)
#definerREFRESH(*(volatileunsigned*)0x1c80024)
#definerBANKSIZE(*(volatileunsigned*)0x1c80028)
#definerMRSRB6(*(volatileunsigned*)0x1c8002c)
#definerMRSRB7(*(volatileunsigned*)0x1c80030)
/*UART
本部分定义了44b0中与UART相关的寄存器地址*/
#definerULCON0(*(volatileunsigned*)0x1d00000)
#definerULCON1(*(volatileunsigned*)0x1d04000)
#definerUCON0(*(volatileunsigned*)0x1d00004)
#definerUCON1(*(volatileunsigned*)0x1d04004)
#definerUFCON0(*(volatileunsigned*)0x1d00008)
#definerUFCON1(*(volatileunsigned*)0x1d04008)
#definerUMCON0(*(volatileunsigned*)0x1d0000c)
#definerUMCON1(*(volatileunsigned*)0x1d0400c)
#definerUTRSTAT0(*(volatileunsigned*)0x1d00010)
#definerUTRSTAT1(*(volatileunsigned*)0x1d04010)
#definerUERSTAT0(*(volatileunsigned*)0x1d00014)
#definerUERSTAT1(*(volatileunsigned*)0x1d04014)
#definerUFSTAT0(*(volatileunsigned*)0x1d00018)
#definerUFSTAT1(*(volatileunsigned*)0x1d04018)
#definerUMSTAT0(*(volatileunsigned*)0x1d0001c)
#definerUMSTAT1(*(volatileunsigned*)0x1d0401c)
#definerUBRDIV0(*(volatileunsigned*)0x1d00028)
#definerUBRDIV1(*(volatileunsigned*)0x1d04028)
#ifdef__BIG_ENDIAN//当系统定义为大端存储模式时各寄存器的地址
#definerUTXH0(*(volatileunsignedchar*)0x1d00023)
#definerUTXH1(*(volatileunsignedchar*)0x1d04023)
#definerURXH0(*(volatileunsignedchar*)0x1d00027)
#definerURXH1(*(volatileunsignedchar*)0x1d04027)
#defineWrUTXH0(ch)(*(volatileunsignedchar*)(0x1d00023))=(unsignedchar)(ch)
#defineWrUTXH1(ch)(*(volatileunsignedchar*)(0x1d04023))=(unsignedchar)(ch)
#defineRdURXH0()(*(volatileunsignedchar*)(0x1d00027))
#defineRdURXH1()(*(volatileunsignedchar*)(0x1d04027))
#defineUTXH0(0x1d00020+3)//byte_accessaddressbyBDMA
#defineUTXH1(0x1d04020+3)
#defineURXH0(0x1d00024+3)
#defineURXH1(0x1d04024+3)
#else//LittleEndian//当系统定义为小端存储模式时各寄存器的地址
#definerUTXH0(*(volatileunsignedchar*)0x1d00020)
#definerUTXH1(*(volatileunsignedchar*)0x1d04020)
#definerURXH0(*(volatileunsignedchar*)0x1d00024)
#definerURXH1(*(volatileunsignedchar*)0x1d04024)
#defineWrUTXH0(ch)(*(volatileunsignedchar*)0x1d00020)=(unsignedchar)(ch)
#defineWrUTXH1(ch)(*(volatileunsignedchar*)0x1d04020)=(unsignedchar)(ch)
#defineRdURXH0()(*(volatileunsignedchar*)0x1d00024)
#defineRdURXH1()(*(volatileunsignedchar*)0x1d04024)
#defineUTXH0(0x1d00020)//byte_accessaddressbyBDMA
#defineUTXH1(0x1d04020)
#defineURXH0(0x1d00024)
#defineURXH1(0x1d04024)
/*SIO
本部分定义了44b0中与同步I/O口相关的寄存器地址*/
#definerSIOCON(*(volatileunsigned*)0x1d14000)
#definerSIODAT(*(volatileunsigned*)0x1d14004)
#definerSBRDR(*(volatileunsigned*)0x1d14008)
#definerIVTCNT(*(volatileunsigned*)0x1d1400c)
#definerDCNTZ(*(volatileunsigned*)0x1d14010)
/*IIS
本部分定义了44b0中与音频播放器IIS相关的寄存器地址*/
#definerIISCON(*(volatileunsigned*)0x1d18000)
#definerIISMOD(*(volatileunsigned*)0x1d18004)
#definerIISPSR(*(volatileunsigned*)0x1d18008)
#definerIISFCON(*(volatileunsigned*)0x1d1800c)
#ifdef__BIG_ENDIAN
#defineIISFIF((volatileunsignedshort*)0x1d18012)
#else//LittleEndian
#defineIISFIF((volatileunsignedshort*)0x1d18010)
/*I/OPORT
本部分定义了44b0中与I/O端口相关的寄存器地址*/
#definerPCONA(*(volatileunsigned*)0x1d20000)
#definerPDATA(*(volatileunsigned*)0x1d20004)
#definerPCONB(*(volatileunsigned*)0x1d20008)
#definerPDATB(*(volatileunsigned*)0x1d2000c)
#definerPCONC(*(volatileunsigned*)0x1d20010)
#definerPDATC(*(volatileunsigned*)0x1d20014)
#definerPUPC(*(volatileunsigned*)0x1d20018)
#definerPCOND(*(volatileunsigned*)0x1d2001c)
#definerPDATD(*(volatileunsigned*)0x1d20020)
#definerPUPD(*(volatileunsigned*)0x1d20024)
#definerPCONE(*(volatileunsigned*)0x1d20028)
#definerPDATE(*(volatileunsigned*)0x1d2002c)
#definerPUPE(*(volatileunsigned*)0x1d20030)
#definerPCONF(*(volatileunsigned*)0x1d20034)
#definerPDATF(*(volatileunsigned*)0x1d20038)
#definerPUPF(*(volatileunsigned*)0x1d2003c)
#definerPCONG(*(volatileunsigned*)0x1d20040)
#definerPDATG(*(volatileunsigned*)0x1d20044)
#definerPUPG(*(volatileunsigned*)0x1d20048)
#definerSPUCR(*(volatileunsigned*)0x1d2004c)
#definerEXTINT(*(volatileunsigned*)0x1d20050)
#definerEXTINTPND(*(volatileunsigned*)0x1d20054)
/*WATCHDOG
本部分定义了44b0中与看门狗定义器相关的寄存器地址*/
#definerWTCON(*(volatileunsigned*)0x1d30000)
#definerWTDAT(*(volatileunsigned*)0x1d30004)
#definerWTCNT(*(volatileunsigned*)0x1d30008)
/*ADC
本部分定义了44b0中与模数转换器相关的寄存器地址*/
#definerADCCON(*(volatileunsigned*)0x1d40000)
#definerADCPSR(*(volatileunsigned*)0x1d40004)
#definerADCDAT(*(volatileunsigned*)0x1d40008)
/*Timer
本部分定义了44b0中与定时器相关的寄存器地址*/
#definerTCFG0(*(volatileunsigned*)0x1d50000)
#definerTCFG1(*(volatileunsigned*)0x1d50004)
#definerTCON(*(volatileunsigned*)0x1d50008)
#definerTCNTB0(*(volatileunsigned*)0x1d5000c)
#definerTCMPB0(*(volatileunsigned*)0x1d50010)
#definerTCNTO0(*(volatileunsigned*)0x1d50014)
#definerTCNTB1(*(volatileunsigned*)0x1d50018)
#definerTCMPB1(*(volatileunsigned*)0x1d5001c)
#definerTCNTO1(*(volatileunsigned*)0x1d50020)
#definerTCNTB2(*(volatileunsigned*)0x1d50024)
#definerTCMPB2(*(volatileunsigned*)0x1d50028)
#definerTCNTO2(*(volatileunsigned*)0x1d5002c)
#definerTCNTB3(*(volatileunsigned*)0x1d50030)
#definerTCMPB3(*(volatileunsigned*)0x1d50034)
#definerTCNTO3(*(volatileunsigned*)0x1d50038)
#definerTCNTB4(*(volatileunsigned*)0x1d5003c)
#definerTCMPB4(*(volatileunsigned*)0x1d50040)
#definerTCNTO4(*(volatileunsigned*)0x1d50044)
#definerTCNTB5(*(volatileunsigned*)0x1d50048)
#definerTCNTO5(*(volatileunsigned*)0x1d5004c)
/*IIC
本部分定义了44b0中与IIC总线相关的寄存器地址*/
#definerIICCON(*(volatileunsigned*)0x1d60000)
#definerIICSTAT(*(volatileunsigned*)0x1d60004)
#definerIICADD(*(volatileunsigned*)0x1d60008)
#definerIICDS(*(volatileunsigned*)0x1d6000c)
/*RTC
本部分定义了44b0中与实时时钟相关的寄存器地址*/
#ifdef__BIG_ENDIAN/*存储模式为大端时各寄存器的地址*/
#definerRTCCON(*(volatileunsignedchar*)0x1d70043)
#definerRTCALM(*(volatileunsignedchar*)0x1d70053)
#definerALMSEC(*(volatileunsignedchar*)0x1d70057)
#definerALMMIN(*(volatileunsignedchar*)0x1d7005b)
#definerALMHOUR(*(volatileunsignedchar*)0x1d7005f)
#definerALMDAY(*(volatileunsignedchar*)0x1d70063)
#definerALMMON(*(volatileunsignedchar*)0x1d70067)
#definerALMYEAR(*(volatil