#include <iom16v.h>
#define LED_DDR DDRD
#define LED_PORT PORTD
/*--------------------------------------------------------------------
程序名称:
程序功能:
注意事项:
提示说明:
输 入:
返 回:
--------------------------------------------------------------------*/
void main(void)
{
uint8 i,j;
LED_DDR=0XFF;
while(1)
{
for(i=0;i<4;i++)
{
LED_PORT^=0xFF; //我闪!拚命闪!
delay50ms(10);
}
j=0x01;
for(i=0;i<8;i++)
{
j<<=1;
LED_PORT=j; //我左闪!
delay50ms(10);
}
j=0x80;
for(i=0;i<8;i++)
{
j>>=1;
LED_PORT=j; //我右闪!
delay50ms(10);
}
}
}
#ifndef Software_H
#define Software_H
#include <math.h>
#include <string.h>
/* 兼容一般程序员的常用写法 */
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef signed char schar;
typedef signed int sint;
typedef signed long slong;
/* 为方便移植,建议使用下面写法 */
typedef unsigned char bool;
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
typedef signed char sint8;
typedef signed int sint16;
typedef signed long sint32;
typedef signed char int8;
typedef signed int int16;
typedef signed long int32;
/* 下面写法一般不推荐 */
//typedef unsigned char ubyte;
//typedef unsigned int uword;
//typedef unsigned long udword;
//typedef signed char sbyte;
//typedef signed int sword;
//typedef signed long sdword;
/* 一般程序定义的默认值 */
//#define NULL 0
//#define EOF -1
//#define TRUE 1
//#define FALSE 0
//#define YES 1
//#define NO 0
//#define ON 1
//#define OFF 0
//#define ENABLE 1
//#define DISABLE 0
//#define CRR 1
//#define ERR 0
//#define RIGHT 1
//#define WRONG 0
//#define SUCCESS 1
//#define FAILURE 0
//#define PI 3.1415926 //3.1415926535897932
/* 如果你手头上的RAM实在很紧,不如尝试下面的define~ */
//#define _CALLOC(a) ( (a *)calloc(n,sizeof(a)) )
//#define _MALLOC(a) ( (a *)malloc(sizeof(a)) )
//#define _MIN(a,b) ( (a) < (b) ? (a) : (b) )
//#define _MAX(a,b) ( (a) > (b) ? (a) : (b) )
//#define _EXCHANGE(a,b) { int t; t=a; a=b; b=t; }
//#define _TOLOWER(c) ( (c)+32 )
//#define _TOUPPER(c) ( (c)-32 )
//#ifndef BIT
//#define BIT(x) ( 1<<(x) )
//#endif
/*--------------------------------------------------------------------
程序全称:数据拆字程序
程序功能:
注意事项:D<=999999,C<=6
提示说明:调用speaData(12,2),得到dataElem[0]=2,dataElem[1]=1
输 入:
返 回:无
--------------------------------------------------------------------*/
uint8 dataElem[6];
void speaData(uint32 dat,sint8 len)
{
uint8 i;
uint32 j,y;
for(i=0,j=1;i<len;i++)
{
y=dat/j;
dataElem[i]=y%10;
j*=10;
}
}
/*--------------------------------------------------------------------
程序全称:十进制强制转换为十六进制
程序功能:
注意事项:
提示说明:调用changeIntToHex(33),return 0x33
输 入:
返 回:
--------------------------------------------------------------------*/
#define changeIntToHex(dec) ( ( ((dec)/10) <<4 ) + ((dec)%10) )
/*--------------------------------------------------------------------
程序全称:十进制化为十六进制,并以十进制格式返回
程序功能:
注意事项:传参必须为 unsigned 类型,否则移位结果可能吓你一跳
提示说明:调用converseIntToHex(33),return 21
输 入:
返 回:
--------------------------------------------------------------------*/
#define converseIntToHex(dec) ( ( ((dec)>>4) *10 ) + ((dec)%16) )
/*--------------------------------------------------------------------
程序全称:十六进制强制转换为十进制
程序功能:
注意事项:传参必须为 unsigned 类型,否则移位结果可能吓你一跳
提示说明:调用changeHexToInt(0x33),return 33
输 入:
返 回:
--------------------------------------------------------------------*/
#define changeHexToInt(hex) ( ( ((hex)>>4) *10 ) + ((hex)%16) )
/*--------------------------------------------------------------------
程序全称:十六进制化为十进制,并以十六进制格式返回
程序功能:
注意事项:
提示说明:调用converseHexToInt(0x33),return 0x51
输 入:
返 回:
--------------------------------------------------------------------*/
#define converseHexToInt(hex) ( ( ((hex)/10) <<4 ) + ((hex)%10) )
#endif
评论0