收藏 分享(赏)

理论教材《嵌入式系统开发与应用教程》部分程序代码.doc

上传人:dreamzhangning 文档编号:2746456 上传时间:2018-09-26 格式:DOC 页数:71 大小:2.55MB
下载 相关 举报
理论教材《嵌入式系统开发与应用教程》部分程序代码.doc_第1页
第1页 / 共71页
理论教材《嵌入式系统开发与应用教程》部分程序代码.doc_第2页
第2页 / 共71页
理论教材《嵌入式系统开发与应用教程》部分程序代码.doc_第3页
第3页 / 共71页
理论教材《嵌入式系统开发与应用教程》部分程序代码.doc_第4页
第4页 / 共71页
理论教材《嵌入式系统开发与应用教程》部分程序代码.doc_第5页
第5页 / 共71页
点击查看更多>>
资源描述

1、嵌入式系统开发与应用实验教程光盘1嵌入式系统开发与应用实验教程第二版增加的光盘内容:嵌入式系统开发与应用教程/第五章1. 嵌入式系统开发与应用教程/第五章/5.3 嵌入式 C 语言程序设计基础/例程一 44blib.h例程一:例程一: “44blib.h”以下是“44blib.h”的定义:/* File: 44BLIB.H* Desc: Samsung 44B0X CPU function declare and common define*/#ifndef _44BLIB_H_#define _44BLIB_H_#ifdef _cplusplusextern “C“ #endif/常量本部分

2、内容定义了一些常量#define DebugOut Uart_Printf#define min(x1,x2) (x1x2)? x1:x2)#define ONESEC0 (62500) /16us resolution, max 1.04 sec#define ONESEC1 (31250) /32us resolution, max 2.09 sec#define ONESEC2 (15625) /64us resolution, max 4.19 sec#define ONESEC3 (7812) /128us resolution, max 8.38 sec#define ONESEC

3、4 (MCLK/128/(0xff+1) /60Mhz, 128*4us resolution, max 32.53 sec#define NULL 0#define EnterPWDN(clkcon) (void (*)(int)0xe0)(clkcon)#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS/* 8led control register address */#define LED8ADDR (*(volatile unsigned char *)(0x2140000)#define LCD 0xFF#define UART 0xFE/*44b

4、lib.c本部分内容对开发中用到的一些库函数作函数原型定义*/void Delay(int time); /Watchdog Timer is used.void DelayMs(int ms_time);void *malloc(unsigned nbyte); 嵌入式系统开发与应用实验教程光盘2void free(void *pt);void Port_Init(void);void Cache_Flush(void);void ChangeMemCon(unsigned *pMemCfg);void Uart_Select(int ch);void Uart_TxEmpty(int ch

5、);void Uart_Init(int mclk,int baud);char Uart_Getch(void);char Uart_GetKey(void);int Uart_GetIntNum(void);void Uart_SendByte(int data);void Uart_Printf(char *fmt,.);void Uart_SendString(char *pt);void Timer_Start(int divider); /Watchdog Timer is used.int Timer_Stop(void); /Watchdog Timer is used.voi

6、d Led_Display(int LedStatus);void Beep(int BeepStatus);void ChangePllValue(int m,int p,int s);#ifdef _cplusplus#endif#endif /* _44BLIB_H_ */ “44b.h“主要是用宏的方式定义了程序中所需的 44B0X 片上涉及到各模块中各寄存器的宏定义的地址。 “44b.h“内容如下所示:/* File: 44B.H* Desc: Samsung 44B0X CPU register define*/#ifndef _44B0X_H_#define _44B0X_H_#

7、ifdef _cplusplusextern “C“ #endif#include “option.h“/* System 本部分内容定义了 44b0 的系统配置寄存器地址*/#define rSYSCFG (*(volatile unsigned *)0x1c00000)/* Cache本部分定义了 44b0 中 2 个不可作 Cache 存储区的起始与结束地址的寄存器的地址*/#define rNCACHBE0 (*(volatile unsigned *)0x1c00004)嵌入式系统开发与应用实验教程光盘3#define rNCACHBE1 (*(volatile unsigned *

8、)0x1c00008)/* Bus control 本部分定义了 44b0 中存储总线控制器的优先级的寄存器地址*/#define rSBUSCON (*(volatile unsigned *)0x1c40000)/* Memory control 本部分定义了 44b0 中与存储器相关的寄存器地址*/#define rBWSCON (*(volatile unsigned *)0x1c80000)#define rBANKCON0 (*(volatile unsigned *)0x1c80004)#define rBANKCON1 (*(volatile unsigned *)0x1c80

9、008)#define rBANKCON2 (*(volatile unsigned *)0x1c8000c)#define rBANKCON3 (*(volatile unsigned *)0x1c80010)#define rBANKCON4 (*(volatile unsigned *)0x1c80014)#define rBANKCON5 (*(volatile unsigned *)0x1c80018)#define rBANKCON6 (*(volatile unsigned *)0x1c8001c)#define rBANKCON7 (*(volatile unsigned *)

10、0x1c80020)#define rREFRESH (*(volatile unsigned *)0x1c80024)#define rBANKSIZE (*(volatile unsigned *)0x1c80028)#define rMRSRB6 (*(volatile unsigned *)0x1c8002c)#define rMRSRB7 (*(volatile unsigned *)0x1c80030)/* UART 本部分定义了 44b0 中与 UART 相关的寄存器地址*/#define rULCON0 (*(volatile unsigned *)0x1d00000)#def

11、ine rULCON1 (*(volatile unsigned *)0x1d04000)#define rUCON0 (*(volatile unsigned *)0x1d00004)#define rUCON1 (*(volatile unsigned *)0x1d04004)#define rUFCON0 (*(volatile unsigned *)0x1d00008)#define rUFCON1 (*(volatile unsigned *)0x1d04008)#define rUMCON0 (*(volatile unsigned *)0x1d0000c)#define rUMC

12、ON1 (*(volatile unsigned *)0x1d0400c)#define rUTRSTAT0 (*(volatile unsigned *)0x1d00010)#define rUTRSTAT1 (*(volatile unsigned *)0x1d04010)#define rUERSTAT0 (*(volatile unsigned *)0x1d00014)#define rUERSTAT1 (*(volatile unsigned *)0x1d04014)#define rUFSTAT0 (*(volatile unsigned *)0x1d00018)#define r

13、UFSTAT1 (*(volatile unsigned *)0x1d04018)#define rUMSTAT0 (*(volatile unsigned *)0x1d0001c)#define rUMSTAT1 (*(volatile unsigned *)0x1d0401c)#define rUBRDIV0 (*(volatile unsigned *)0x1d00028)#define rUBRDIV1 (*(volatile unsigned *)0x1d04028)#ifdef _BIG_ENDIAN /当系统定义为大端存储模式时各寄存器的地址#define rUTXH0 (*(v

14、olatile unsigned char *)0x1d00023)#define rUTXH1 (*(volatile unsigned char *)0x1d04023)嵌入式系统开发与应用实验教程光盘4#define rURXH0 (*(volatile unsigned char *)0x1d00027)#define rURXH1 (*(volatile unsigned char *)0x1d04027)#define WrUTXH0(ch) (*(volatile unsigned char *)(0x1d00023)=(unsigned char)(ch)#define WrU

15、TXH1(ch) (*(volatile unsigned char *)(0x1d04023)=(unsigned char)(ch)#define RdURXH0() (*(volatile unsigned char *)(0x1d00027)#define RdURXH1() (*(volatile unsigned char *)(0x1d04027) #define UTXH0 (0x1d00020+3) /byte_access address by BDMA#define UTXH1 (0x1d04020+3)#define URXH0 (0x1d00024+3)#define

16、 URXH1 (0x1d04024+3)#else /Little Endian /当系统定义为小端存储模式时各寄存器的地址#define rUTXH0 (*(volatile unsigned char *)0x1d00020)#define rUTXH1 (*(volatile unsigned char *)0x1d04020)#define rURXH0 (*(volatile unsigned char *)0x1d00024)#define rURXH1 (*(volatile unsigned char *)0x1d04024)#define WrUTXH0(ch) (*(vol

17、atile unsigned char *)0x1d00020)=(unsigned char)(ch)#define WrUTXH1(ch) (*(volatile unsigned char *)0x1d04020)=(unsigned char)(ch)#define RdURXH0() (*(volatile unsigned char *)0x1d00024)#define RdURXH1() (*(volatile unsigned char *)0x1d04024)#define UTXH0 (0x1d00020) /byte_access address by BDMA#def

18、ine UTXH1 (0x1d04020)#define URXH0 (0x1d00024)#define URXH1 (0x1d04024)#endif/* SIO本部分定义了 44b0 中与同步 I/O 口相关的寄存器地址*/#define rSIOCON (*(volatile unsigned *)0x1d14000)#define rSIODAT (*(volatile unsigned *)0x1d14004)#define rSBRDR (*(volatile unsigned *)0x1d14008)#define rIVTCNT (*(volatile unsigned *)

19、0x1d1400c)#define rDCNTZ (*(volatile unsigned *)0x1d14010)/* IIS本部分定义了 44b0 中与音频播放器 IIS 相关的寄存器地址*/#define rIISCON (*(volatile unsigned *)0x1d18000)#define rIISMOD (*(volatile unsigned *)0x1d18004)#define rIISPSR (*(volatile unsigned *)0x1d18008)#define rIISFCON (*(volatile unsigned *)0x1d1800c)#ifde

20、f _BIG_ENDIAN#define IISFIF (volatile unsigned short *)0x1d18012)#else /Little Endian#define IISFIF (volatile unsigned short *)0x1d18010)#endif嵌入式系统开发与应用实验教程光盘5/* I/O PORT本部分定义了 44b0 中与 I/O 端口相关的寄存器地址*/#define rPCONA (*(volatile unsigned *)0x1d20000)#define rPDATA (*(volatile unsigned *)0x1d20004)#d

21、efine rPCONB (*(volatile unsigned *)0x1d20008)#define rPDATB (*(volatile unsigned *)0x1d2000c)#define rPCONC (*(volatile unsigned *)0x1d20010)#define rPDATC (*(volatile unsigned *)0x1d20014)#define rPUPC (*(volatile unsigned *)0x1d20018)#define rPCOND (*(volatile unsigned *)0x1d2001c)#define rPDATD

22、(*(volatile unsigned *)0x1d20020)#define rPUPD (*(volatile unsigned *)0x1d20024)#define rPCONE (*(volatile unsigned *)0x1d20028)#define rPDATE (*(volatile unsigned *)0x1d2002c)#define rPUPE (*(volatile unsigned *)0x1d20030)#define rPCONF (*(volatile unsigned *)0x1d20034)#define rPDATF (*(volatile un

23、signed *)0x1d20038)#define rPUPF (*(volatile unsigned *)0x1d2003c)#define rPCONG (*(volatile unsigned *)0x1d20040)#define rPDATG (*(volatile unsigned *)0x1d20044)#define rPUPG (*(volatile unsigned *)0x1d20048)#define rSPUCR (*(volatile unsigned *)0x1d2004c)#define rEXTINT (*(volatile unsigned *)0x1d

24、20050)#define rEXTINTPND (*(volatile unsigned *)0x1d20054)/* WATCHDOG本部分定义了 44b0 中与看门狗定义器相关的寄存器地址*/#define rWTCON (*(volatile unsigned *)0x1d30000)#define rWTDAT (*(volatile unsigned *)0x1d30004)#define rWTCNT (*(volatile unsigned *)0x1d30008)/* ADC本部分定义了 44b0 中与模数转换器相关的寄存器地址*/#define rADCCON (*(vol

25、atile unsigned *)0x1d40000)#define rADCPSR (*(volatile unsigned *)0x1d40004)#define rADCDAT (*(volatile unsigned *)0x1d40008)/* Timer嵌入式系统开发与应用实验教程光盘6本部分定义了 44b0 中与定时器相关的寄存器地址*/#define rTCFG0 (*(volatile unsigned *)0x1d50000)#define rTCFG1 (*(volatile unsigned *)0x1d50004)#define rTCON (*(volatile u

26、nsigned *)0x1d50008)#define rTCNTB0 (*(volatile unsigned *)0x1d5000c)#define rTCMPB0 (*(volatile unsigned *)0x1d50010)#define rTCNTO0 (*(volatile unsigned *)0x1d50014)#define rTCNTB1 (*(volatile unsigned *)0x1d50018)#define rTCMPB1 (*(volatile unsigned *)0x1d5001c)#define rTCNTO1 (*(volatile unsigne

27、d *)0x1d50020)#define rTCNTB2 (*(volatile unsigned *)0x1d50024)#define rTCMPB2 (*(volatile unsigned *)0x1d50028)#define rTCNTO2 (*(volatile unsigned *)0x1d5002c)#define rTCNTB3 (*(volatile unsigned *)0x1d50030)#define rTCMPB3 (*(volatile unsigned *)0x1d50034)#define rTCNTO3 (*(volatile unsigned *)0x

28、1d50038)#define rTCNTB4 (*(volatile unsigned *)0x1d5003c)#define rTCMPB4 (*(volatile unsigned *)0x1d50040)#define rTCNTO4 (*(volatile unsigned *)0x1d50044)#define rTCNTB5 (*(volatile unsigned *)0x1d50048)#define rTCNTO5 (*(volatile unsigned *)0x1d5004c)/* IIC本部分定义了 44b0 中与 IIC 总线相关的寄存器地址*/#define rI

29、ICCON (*(volatile unsigned *)0x1d60000)#define rIICSTAT (*(volatile unsigned *)0x1d60004)#define rIICADD (*(volatile unsigned *)0x1d60008)#define rIICDS (*(volatile unsigned *)0x1d6000c)/* RTC本部分定义了 44b0 中与实时时钟相关的寄存器地址*/#ifdef _BIG_ENDIAN /*存储模式为大端时各寄存器的地址 */#define rRTCCON (*(volatile unsigned char

30、 *)0x1d70043)#define rRTCALM (*(volatile unsigned char *)0x1d70053)#define rALMSEC (*(volatile unsigned char *)0x1d70057)#define rALMMIN (*(volatile unsigned char *)0x1d7005b)#define rALMHOUR (*(volatile unsigned char *)0x1d7005f)#define rALMDAY (*(volatile unsigned char *)0x1d70063)#define rALMMON

31、(*(volatile unsigned char *)0x1d70067)#define rALMYEAR (*(volatile unsigned char *)0x1d7006b)嵌入式系统开发与应用实验教程光盘7#define rRTCRST (*(volatile unsigned char *)0x1d7006f)#define rBCDSEC (*(volatile unsigned char *)0x1d70073)#define rBCDMIN (*(volatile unsigned char *)0x1d70077)#define rBCDHOUR (*(volatile

32、 unsigned char *)0x1d7007b)#define rBCDDAY (*(volatile unsigned char *)0x1d7007f)#define rBCDDATE (*(volatile unsigned char *)0x1d70083)#define rBCDMON (*(volatile unsigned char *)0x1d70087)#define rBCDYEAR (*(volatile unsigned char *)0x1d7008b)#define rTICINT (*(volatile unsigned char *)0x1d7008e)#

33、else /*存储模式为小端时各寄存器的地址*/#define rRTCCON (*(volatile unsigned char *)0x1d70040)#define rRTCALM (*(volatile unsigned char *)0x1d70050)#define rALMSEC (*(volatile unsigned char *)0x1d70054)#define rALMMIN (*(volatile unsigned char *)0x1d70058)#define rALMHOUR (*(volatile unsigned char *)0x1d7005c)#defi

34、ne rALMDAY (*(volatile unsigned char *)0x1d70060)#define rALMMON (*(volatile unsigned char *)0x1d70064)#define rALMYEAR (*(volatile unsigned char *)0x1d70068)#define rRTCRST (*(volatile unsigned char *)0x1d7006c)#define rBCDSEC (*(volatile unsigned char *)0x1d70070)#define rBCDMIN (*(volatile unsign

35、ed char *)0x1d70074)#define rBCDHOUR (*(volatile unsigned char *)0x1d70078)#define rBCDDAY (*(volatile unsigned char *)0x1d7007c)#define rBCDDATE (*(volatile unsigned char *)0x1d70080)#define rBCDMON (*(volatile unsigned char *)0x1d70084)#define rBCDYEAR (*(volatile unsigned char *)0x1d70088)#define

36、 rTICINT (*(volatile unsigned char *)0x1d7008c)#endif/* Clock volatile unsigned char *downPt;unsigned int fileSize;void *mallocPt=Image_RW_Limit;void (*restart)(void)=(void (*)(void)0x0;void (*run)(void)=(void (*)(void)DOWNLOAD_ADDRESS;/-SYSTEM-/static int delayLoopCount=400;void Delay(int time)/ ti

37、me=0: adjust the Delay function by WatchDog timer./ time0: the number of loop time/ 100us resolution./int i,adjust=0;if(time=0)time=200;adjust=1;delayLoopCount=400;rWTCON=(MCLK/1000000-1)0;time-)for(i=0;i12)12); /* Low level default */rEXTINT=0x0;/* UART */static int whichUart=0;void Uart_Init(int m

38、clk,int baud)int i;if(mclk=0)mclk=MCLK;rUFCON0=0x0; /FIFO disablerUFCON1=0x0;rUMCON0=0x0;rUMCON1=0x0;/UART0rULCON0=0x3; /Normal,No parity,1 stop,8 bitrUCON0=0x245; /rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or pollingrUBRDIV0=( (int)(mclk/16./baud + 0.5) -1 );/UART1

39、rULCON1=0x3;rUCON1=0x245;rUBRDIV1=( (int)(mclk/16./baud + 0.5) -1 );for(i=0;i0); /to align 4byteif( (int)mallocPt HEAPEND )mallocPt=returnPt;return NULL;return returnPt;void free(void *pt)mallocPt=pt;void Cache_Flush(void)嵌入式系统开发与应用实验教程光盘20int i,saveSyscfg;saveSyscfg=rSYSCFG;rSYSCFG=SYSCFG_0KB; for(

40、i=0x10004000;i0x10004800;i+=16) *(int *)i)=0x0; rSYSCFG=saveSyscfg; #ifndef _LIB_LED_off / if define _LIB_LED_off dont use LIB settings./* name: Led_Display* func: Led Display control function* para: LedStatus - leds status*/void Led_Display(int LedStatus)if(LedStatuselserPDATB=rPDATB|0x200;if(LedSt

41、atuselserPDATB=rPDATB|0x400;#endifvoid sys_init()/ Interrupt,Port and UART/* enable interrupt */rINTMOD=0x0;rINTCON=0x1;rI_ISPC = 0xffffffff; /* clear all interrupt pend */rEXTINTPND = 0xf; / clear EXTINTPND regPort_Init(); /* Initial 44B0Xs I/O port */LED8ADDR = 0 ;Led_Display(0xf);Delay(0); /* del

42、ay time */Uart_Init(0,115200); /* Initial Serial port 1 */4. 嵌入式系统开发与应用教程/第五章/5.3 嵌入式 C 语言程序设计实例/嵌入式系统开发与应用实验教程光盘21例程四 Flash.c例程四:例程四: Flash 测试实验代码Flash 测试实验代码如下所示:/* File: flash.c* Desc: SST39VF160 Flash program code*/*- 包含文件 -*/#include “flash.h“ /* flash 头文件*/*- 函数声明 -*/int Identify(int base_addr

43、);int erase_flash(int base_addr);int erase_sector(int base_addr);int wait_flash_ready(int address, pB0SIZE data);/*- 函数代码 -*/* name: Test_Flash* func: flash 测试程序*/void Test_Flash(void)char data256;int i;Uart_Printf(“nWrite 0x000-0xff to flash address 0x30000 .n“);for( i = 0 ; i 256 ; i+ )datai = i;i

44、f( Program(0x30000,data,256) = TRUE )Uart_Printf(“nFlash Write and Check Success!n“);/* name: Program* func: program data to flash* para: addr_base 目标 flash 的起始地址* pData - 源数据指针* data_size 源数据大小*/int Program(int addr_base, char* pData, int data_size)char sec_data4096; / sector dataint base_addr,sect

45、or_addr,length;嵌入式系统开发与应用实验教程光盘22int i,j,sect_num;short *pSrc;short *pDest;base_addr = (int)addr_base/*- 检查 flash 类型-*/if( Identify(base_addr) = FALSE )return;/* 计算扇区数目 */sect_num = (addr_base+data_size)/* 擦除每个扇区 */sector_addr = addr_base for( i = 0 ; i sect_num ; i+ )sector_addr = sector_addr + i*0x1000;/* 从扇区读数据 */for( j = 0 ; j 1024 ; j+ )(long *)sec_data)j = (long *)sector_addr)j;if( i = 0 )/* 复制长度 */length = 4096-(addr_base-sector_addr);length = (length data_size)? length : data_size;/* 复制目标数据到临时数据存放区 */for( j = 0 ; j length ; j+ )sec_dataaddr_base-sector_addr+j = pDataj;else if(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报