1.学习单片机须注意以下几点: 首先你要明确学习单片机的目的是什么,对于大多数学习者来说,学习单片机的目的应该是应用,把它运用到你所在的行业或产品之中,单片机对于你的工作来说,只是一个工具或部件,那么在应用中我们选用单片机的标准是什么呢?四个字“够用就行”。可以说现在应用系统中绝大部分的项目,最简单的8位51单片机就可以胜任,现在真正需要高档单片机的项目还是少数。老板们 不会投入多余的钱去选用你推荐的所谓高级单片机,大部分人遵循“只买对的不买贵的”这样理性的原则,理性的人不会盲目的追随比尔 盖茨的不断升级,因为这些东西一方面有技术发展的需求,但是也有相当一部分是老板们为追求更大商业利益的炒作。因此我还是要说,如果你没有学过C51单片机的话,还是要学C51单片机。为什么?原因很简单,因为它是单片机的祖宗,后来的单片机都是在它的基础上开发出来的,是他的儿孙们。它也最容易学,更适合初学者。它的功能强大,物美价廉,大部分应用项目用它就够了,没有必要用高档的,当你学会了C51之后,如果确实需要用别的单片机,对于使用C语言编程的人来说,学习其它单片机还是比较容易的,写好的程序移植到其他单片机上也不是很难的事情,他们都是相通的. F-EeeOS学习板是明霞科技为“单片机和嵌入试操作系统应用”课程的专门设计的实验平台,它以AT89S52为范例介绍了MCS-51系列单片机各部件的C语言编程,产品开发中常用外设驱动程序编写的方法,目前流行的RTOS操作系统uCOS-Ⅱ在MCS-51系列单片机的移植和应用。 F-EeeOS学习板资源丰富,明霞科技为您提供了基础篇,提高篇,高级篇三种类型的实验,其中基础篇的实验能快速帮助您熟悉MCS51系列单片机各部件的使用,学习完基础篇后,您会对MCS51系列单片机有个清晰的认识,能够在单片机上实现简单的功能; 提高篇是为对单片机有了认识后准备的,在这篇中通过学习LCD显示,I/O口模拟IIC通信,RS232通信的驱动程序编写,您能熟悉常用外设开发的方法,能培养您以后在产品开发过程中良好的编程习惯和 编写模块化程序的方法,在您认真学习完提高篇的实验后您可以大声地说:“我已经进入单片机开发的大门!”;高级篇是对单片机开发更深一步的探讨,是为今后您学习更高级CPU做准备的,在这篇中明霞科技通过实验告诉您如何把目前流行的ucos操作系统移植到MCS51写列芯片上,如何快速掌握基于ucos操作系统开发自己的产品和如何快进行模块化程序设计,最后再通过闹钟程序事例帮助您对整个学习做最后的巩固。 最后我相信大家在完成这些实验后能熟练掌握单片机开发的方法,只要您认真完成了这些实验您今后一定能快速成长为一个优秀的单片机开发者!
有兴趣的请联系QQ:11830067 电话:13590189626(深圳号码)
如果学生团队购买价格更加优惠。 2.这是提供给用户学习模块化程序设计的例子(队列来实现串口的驱动). #define SCI_DRIVER /***************************************************************************************** *Copyright: MASNK Corporation * *File name: SciDriver.c * *Author: Kenny_wang * *Version: V1.0 * *Date: 2008/06/24 * ******************************************************************************************/
/***************************************************************************************** Hardware Environment: AT89S52 Crystal:6M Hz ******************************************************************************************/ /***************************************************************************************** *Modify List: * *1.2008/06/25 Kenny_wang *----(1).release the original version. * ******************************************************************************************/ #include "reg52.h" #include "SciDriverSciDriver.h" #include "SciDriverSourceFunLst.h" #include "SciDriverPortsSciconfig.h"
/******************************************************************************** * Constant Define * ********************************************************************************/ #define cQBufNormal 0 #define cQBufFull 1 #define cQBufEmpty 2
/******************************************************************************** * Queue structure * ********************************************************************************/ typedef struct{ unsigned char *pIn; unsigned char *pOut; unsigned char *pStart; unsigned int bLength; unsigned int wSize; }QUEUE;
/******************************************************************************** * Sci structure * * Including tranmit and receive queue structure and Tx,Rx threshold variabls * ********************************************************************************/ typedef struct{ unsigned char bTxStatus; unsigned int wTxLength; unsigned char *pbTx; QUEUE *pqRx; unsigned char bSciType; }SciStruct;
/******************************************************************************** * List of Sci structure and queue * ********************************************************************************/ SciStruct SciList; SciStruct *pSciIndex; QUEUE QList; unsigned char bSciRxBuf[MAX_SCI_BUF_SIZE]; unsigned char *pSciBuf = bSciRxBuf; unsigned char bSciNo = 0;
/******************************************************************************** * Internal Function Declaration * ********************************************************************************/ void sQInit(QUEUE *pq,unsigned char *pStart,unsigned int wSize); unsigned char sQDataIn(QUEUE *pq,unsigned char bData); unsigned char sQDataOut(QUEUE *pq,unsigned char *pData);
/******************************************************************************** *Function name: sQInit * *Parameters: pq: pointer to queue structure to be initialized * * start: start address of ring buffer * * size: the size of the ring buffer * *Description: initialize a queue structure * ********************************************************************************/ void sQInit(QUEUE *pq,unsigned char *pStart,unsigned int wSize) { pq->pIn = pStart; pq->pOut = pStart; pq->pStart = pStart; pq->bLength = 0; pq->wSize = wSize; }
/******************************************************************************** *Function name: sQDataIn * *Parameters: pq: pointer to queue structure to be initialized * * data: the data to be inserted into the queue * *Returns: cQBufNormal: data has been inserted into the queue * * cQBufFull: the buffer is full * *Description: insert a data into the queue * ********************************************************************************/ unsigned char sQDataIn(QUEUE *pq,unsigned char bData) { if(pq->bLength == pq->wSize) { if(pq->pIn == pq->pStart) { *(pq->pStart + pq->wSize) = bData; } else { *(pq->pIn-1) = bData; } return(cQBufFull); } else { *(pq->pIn) = bData; pq->bLength++; if(pq->pIn == pq->pStart + pq->wSize - 1) { pq->pIn = pq->pStart; } else { pq->pIn++; } return(cQBufNormal); } }
/******************************************************************************** *Function name: sQDataOut * *Parameters: pq: pointer to queue structure to be initialized * * pdata: the address to save the data * *Returns: cQBufNormal: data has been inserted into the queue * * cQBufEmpty: the buffer is empty * *Description: Get a data from the queue * ********************************************************************************/ unsigned char sQDataOut(QUEUE *pq,unsigned char *pData) { if(pq->bLength == 0) { return(cQBufEmpty); } *pData = *(pq->pOut); pq->bLength--; if(pq->pOut == pq->pStart + pq->wSize - 1) { pq->pOut = pq->pStart; } else { pq->pOut++; } return(cQBufNormal); }
/******************************************************************************** *Function Name: sInitialSci * *Parameters: bSciId: sci id * * *bRxBuf: receive buffer start address * * wRxSize: receive buffer length * * bTxBuf: transmit buffer start address * * wTxSize: transmit buffer length * * type: sci type * *Descriptions: assign and initialize the sci control struct to sci * ********************************************************************************/ void sInitialSci(unsigned int wRxSize,unsigned char bType) { QUEUE *pq; SciStruct *pSci;
pSci = &SciList; pSciIndex = pSci;
pSci->pqRx = &QList; pq = pSci->pqRx; sQInit(pq,pSciBuf,wRxSize); pSciBuf += wRxSize; bSciNo++;
pSci->bTxStatus = cSciTxRdy; pSci->wTxLength = 0;
pSci->bSciType = bType; }
/******************************************************************************** *Function Name: sSciRxISR * *Parameters: bSciId: sci id * *Description: This function is executed in Sci rx interrupt io2sci rx compare * * interrupt. * ********************************************************************************/ void sSciRxISR(void) { unsigned char bData; QUEUE *pq; SciStruct *pSci;
pSci = pSciIndex; pq = pSci->pqRx;
if(sbGetSciRxRdy() == cSciRxRdy) { sSciResetRx(); bData = sbGetSciRxData(); sQDataIn(pq,bData); } }
/******************************************************************************** *Function Name: sSciRead * *Parameters: bSciId: sci id * * *pBuf: address to save data received * *Returns: cSciRxBufEmpty: receive buffer is empty * * cSciRxRdy: get one byte data successfully * *Description: This function is executed in AP * ********************************************************************************/ unsigned char sSciRead(unsigned char *pBuf) { QUEUE *pq; unsigned char bTemp; SciStruct *pSci;
pSci = pSciIndex; pq = pSci->pqRx;
OS_ENTER_CRITICAL(); bTemp = sQDataOut(pq,pBuf); OS_EXIT_CRITICAL();
if(bTemp == cQBufEmpty) { return(cSciRxBufEmpty); } else { return(cSciRxRdy); } }
/******************************************************************************** *Function Name: sSciTxISR * *Parameters: bSciId: sci id * *Description: This function is executed in Sci Tx interrupt io2sci Tx compare * * interrupt. * ********************************************************************************/ void sSciTxISR(void) { SciStruct *pSci;
pSci = pSciIndex;
if(sbGetSciTxRdy() == cSciTxRdy) { if(pSci->wTxLength == 0) { pSci->bTxStatus = cSciTxRdy; sSciResetTx(); } else { sSciTxData(*(pSci->pbTx)); (pSci->pbTx)++; (pSci->wTxLength)--; sSciResetTx(); } } }
/******************************************************************************** *Function Name: sSciWrite * *Parameters: bSciId: sci id * * *pstart: start address of data to be sent * * wLength: the length of data to be send * *Returns: cSciTxBufFull: transmit buffer is empty * * cSciTxRdy: send one byte data successfully * *Description: This function is executed in AP * ********************************************************************************/ unsigned char sSciWrite(unsigned char *pStart,unsigned int wLength) { SciStruct *pSci;
pSci = pSciIndex;
if(pSci->bTxStatus == cSciTxBusy) { return(cSciTxBusy); }
OS_ENTER_CRITICAL(); pSci->pbTx = pStart; pSci->wTxLength = wLength; pSci->bTxStatus = cSciTxBusy;
sSciTxData(*(pSci->pbTx)); (pSci->pbTx)++; (pSci->wTxLength)--;
OS_EXIT_CRITICAL();
return(cSciTxRdy); }
/******************************************************************************** *Function Name: sbGetSciTxStatus * *Parameters: bSciId: sci id * *Returns: sci tx status cSciTxRdy * * cSciTxBusy * *Description: Get the sci trasmit status * ********************************************************************************/ unsigned char sbGetSciTxStatus(void) { SciStruct *pSci;
pSci = pSciIndex;
return(pSci->bTxStatus); }
/******************************************************************************** *Function Name: sSetSciBaudRate * *Parameters: bSciId: sci id * *Returns: bBaudrate Sci Baudrate * *Description: Set the sci baudrate * ********************************************************************************/ void sSetSciBaudRate(unsigned char bBaudrate) { sSciChangeBaudRate(bBaudrate); }
|