📄 main.c
字号:
/******************************************************************************
*
* (c) copyright Freescale Semiconductor Hong Kong Ltd. 2004
* ALL RIGHTS RESERVED
*
*******************************************************************************
** THIS CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE **
** MICROCONTROLLERS. IT HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST. IT IS **
** PROVIDED 'AS SEEN' WITH NO GUARANTEES AND NO PROMISE OF SUPPORT. **
*******************************************************************************
*
* FILE: main.c REVISION 0.2
*
* DESCRIPTION: Application code is placed here.
* This module handles all tasks for initialization.
* It is invoked by _Startup right after start12.c was being
* finished.
*
* COMPILER: Metrowerks VERSION: ADS v1.2 (initial version)
* VERSION: ADS v2.0 (Demo alpha/beta version)
* VERSION: ADS v3.1 (Demo version)
*
* NOTES
* -----
* All modules remain at their reset addresses.
*
*
* UPDATED HISTORY:
*
* REV YYYY.MM.DD AUTHOR DESCRIPTION OF CHANGE
* --- ---------- ------ ---------------------
* 0.0 2002.04.27 Kenny Lam Initial version
* 0.1 2002.09.12 Kenny Lam Demo beta version
* 0.2 2004.04.12 Kenny Lam Demo version
* 0.2 2005.09.10 Kenny Lam Demo version for HZ256
*
******************************************************************************/
/* Freescale is not obligated to provide any support, upgrades or new */
/* releases of the Software. Freescale may make changes to the Software at */
/* any time, without any obligation to notify or provide updated versions of */
/* the Software to you. Freescale expressly disclaims any warranty for the */
/* Software. The Software is provided as is, without warranty of any kind, */
/* either express or implied, including, without limitation, the implied */
/* warranties of merchantability, fitness for a particular purpose, or */
/* non-infringement. You assume the entire risk arising out of the use or */
/* performance of the Software, or any systems you design using the software */
/* (if any). Nothing may be construed as a warranty or representation by */
/* Freescale that the Software or any derivative work developed with or */
/* incorporating the Software will be free from infringement of the */
/* intellectual property rights of third parties. In no event will Freescale */
/* be liable, whether in contract, tort, or otherwise, for any incidental, */
/* special, indirect, consequential or punitive damages, including, but not */
/* limited to, damages for any loss of use, loss of time, inconvenience, */
/* commercial loss, or lost profits, savings, or revenues to the full extent */
/* such may be disclaimed by law. The Software is not fault tolerant and is */
/* not designed, manufactured or intended by Freescale for incorporation */
/* into products intended for use or resale in on-line control equipment in */
/* hazardous, dangerous to life or potentially life-threatening environments */
/* requiring fail-safe performance, such as in the operation of nuclear */
/* facilities, aircraft navigation or communication systems, air traffic */
/* control, direct life support machines or weapons systems, in which the */
/* failure of products could lead directly to death, personal injury or */
/* severe physical or environmental damage (High Risk Activities). You */
/* specifically represent and warrant that you will not use the Software or */
/* any derivative work of the Software for High Risk Activities. */
/* Freescale and the Freescale logos are registered trademarks of Freescale */
/* Semiconductor Inc. */
/*****************************************************************************/
#include <hidef.h>
#include "cluster_includes.h"
#include "H256Port.h"
#include "LCDPort.h"
#include "Const.h"
#define _GLOBAL_DECL_
#include "GlobalVar.h"
#include "mscan.h"
#include "ds1302.h"
#define CAN_MSG_ID 1
#define cEEpromStart 0x400
#define cEEpromEnd 0x7ff //???????????????
/****************************************************************************
* main() -
*
* Main subroutine
****************************************************************************/
//pk7--key1
//pe7--key2
/*
void delayMS(unsigned int delayData)
{
unsigned int i,j;
for(j=0;j<delayData;j++)
{
for(i=0;i<100;i++)
;
}
}
*/
unsigned char writeEEprom(unsigned int addr,unsigned int data)
{
static unsigned int *paddr;
if((ECLKDIV&0x80)!=0x80)
{
ECLKDIV=0x28;
}
if((addr<cEEpromStart)||(addr>cEEpromEnd))
{
return 1;
}
if((addr%2)!=0)
{
return 1;
}
if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1))
{
ESTAT|=0x30;
return 1;
}
paddr=(unsigned int *)(0x400);
while(!(ESTAT&0x80)) ;
*paddr=data; //???????????????????/
ECMD=0x20;
ESTAT|=0x80;
if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1))
{
ESTAT|=0x30;
return 1;
}
while((ESTAT&0x40)==0);
return 0;
/*
unsigned char cee=0;
if((ECLKDIV&0x80)!=0x80)
{
ECLKDIV=0x28;
}
EEloopBack:
EADDRHI=(unsigned char)(addr>>8);
EADDRLO=(unsigned char)(addr&0xff);
EDATAHI=(unsigned char)(data>>8);
EDATALO=(unsigned char)(data&0xff);
ECMD=0x20;
ESTAT|=0x80;
if((ESTAT&0x20)==0)
{ //1
if((ESTAT&0x10)==0)
{ //2
// if((ESTAT&0x80)==0) no need to justify
{ //3
EEloopOut:
if((ESTAT&0x40)==0)
cee=1;
while((ESTAT&0x40)==0);
return cee;
} //3
// else
// {
//next write?????????????/
//if next write??
//goto EEloopBack;
//else
// goto EEloopOut; //only one word is writed
// }
} //2
else
{
ESTAT|=0x10;
goto EEloopBack;
}
}//1
else
{
ESTAT|=0x20;
goto EEloopBack;
}
*/
}
unsigned char eraseEEprom(unsigned int addr)
{
unsigned int *paddr;
if((ECLKDIV&0x80)!=0x80)
{
ECLKDIV=0x28;
}
if((addr<cEEpromStart)||(addr>cEEpromEnd))
{
return 1;
}
if((addr%4)!=0)
{
return 1;
}
if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1))
{
ESTAT|=0x30;
return 1;
}
paddr=(unsigned int *)addr;
while(!(ESTAT&0x80)) ;
*paddr=0xff;
ECMD=0x40;
ESTAT|=0x80;
if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1))
{
ESTAT|=0x30;
return 1;
}
while(!(ESTAT&0x80)) ; //???????????????????
while((ESTAT&0x40)==0);
return 0;
/*
unsigned char cee=0;
if((ECLKDIV&0x80)!=0x80)
{
ECLKDIV=0x28;
}
EraserBack:
EADDRHI=(unsigned char)(addr>>8);
EADDRLO=(unsigned char)(addr&0xff);
//EDATAHI=(unsigned char)(data>>8);
//EDATALO=(unsigned char)(data&0xff);
ECMD=0x40;
ESTAT|=0x80;
if((ESTAT&0x20)==0)
{ //1
if((ESTAT&0x10)==0)
{ //2
// if((ESTAT&0x80)==0) no need to justify
{ //3
if((ESTAT&0x40)==0)
cee=1;
while((ESTAT&0x40)==0);
return cee;
} //3
} //2
else
{
ESTAT|=0x10;
goto EraserBack;
}
}//1
else
{
ESTAT|=0x20;
goto EraserBack;
}
*/
}
unsigned char readEEprom(unsigned int addr )
{
return (*((volatile unsigned char*)(addr))) ;
}
void initEEprom(void)
{
ECLKDIV=0x28;
}
void WriteCommLcd6432(unsigned char CmdData)
{
unsigned char i ;
PORTT=PORTT|0x80;
delayMS(1);
//lcd2CS=1;
PORTT=PORTT|0x20;
delayMS(1);
//lcd2Data=1;
for(i=0;i<5;i++)
{
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
}
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT&0xdf;
delayMS(1);
//lcdData=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //rw 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //rs 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x80)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x80; //d7
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x40)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x40; //d6
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x20)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x20; //d5
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x10)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x10; //d4
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT&0xdf;
delayMS(1);
//lcdData=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; // 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; // 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x08)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x08; //d3
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x04)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x04; //d2
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x02)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x02; //d1
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
if(CmdData&0x01)
{
PORTT=PORTT|0x20;
delayMS(1);
}
else
{
PORTT=PORTT&0xdf;
delayMS(1);
}
//lcdData=CmdData&0x01; //d0
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1;
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT&0xdf;
delayMS(1);
//lcdData=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; // 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; // 0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //0
PORTT=PORTT&0xbf;
delayMS(1);
//lcdClock=0;
PORTT=PORTT|0x40;
delayMS(1);
//lcdClock=1; //0
PORTT=PORTT&0xbf;
delayMS(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -