⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 define.h

📁 C51源码.其内文件包含spi
💻 H
字号:

#define byte  	unsigned char
#define BYTE  	unsigned char

#define uint  	unsigned int
#define UINT  	unsigned int

#define uchar 	unsigned char
#define ulong 	unsigned long
#define Byte 	unsigned char
#define Word 	unsigned int
#define WORD 	unsigned int
#define UINT 	unsigned int
#define byte 	unsigned char
#define word 	unsigned int
#define bool 	char
#define BOOL 	unsigned char

#define TRUE  1
#define true  1
#define FALSE 0
#define false 0
#ifndef NULL
#define NULL  0
#endif
#define null  0
#define SomeNOP(); _nop_();_nop_();_nop_();_nop_();

/*颜色定义*/
#define a_lyellow    3
#define a_lgreen0    6
#define a_lpink      5
#define a_lwhite     7
#define a_hyellow    11
#define a_hgreen0    14
#define a_hpink      13
#define a_hwhite     15
#define a_lred       1
#define a_lgreen     2
#define a_lblue      4
#define a_hred       9
#define a_hgreen     10
#define a_hblue      12
#define a_lblack     0

#define BLACK     0x0
#define RED       0x1
#define GREEN     0x2
#define YELLOW    0x3
#define BLUE      0x4
#define PINK      0x5
#define GREEN2    0x6
#define WHITE     0x7
/************************************************/
/*键盘键值表*/
#define ZERO    0
#define ONE     1
#define TWO     2
#define THREE   3
#define FOUR    4
#define FIVE    5
#define SIX     6
#define SEVEN   7
#define EIGHT   8
#define NINE    9
#define DOT     10
#define UP      11
#define DOWN    12
#define BACK    13
#define OK      14
#define CANCEL  15
/************************************************/


#define MBS_OK_ONLY        0x1
#define MBS_CANCEL_ONLY    0x2
#define MBS_OK_CANCEL      0x4
#define MBS_MODELESS       0x8

#define PS_SOLID           0x1
#define PS_DOT             0x2	

#define CHAR_WIDTH  4

#define WR_OPT 		0
#define RD_OPT  	1
#define TIME_INIT  	2
//定义138译码地址
#define   K0   XBYTE[0X8000]
#define   K1   XBYTE[0X9000]
#define   K2   XBYTE[0XA000]
#define   K3   XBYTE[0XB000]
#define   K4   XBYTE[0XC000]
#define   K5   XBYTE[0XD000]
#define   K6   XBYTE[0XE000]
#define   K7   XBYTE[0XF000]

//设置P4口相关引脚功能。
//P4口及其他高端口,不能位寻址,故定义可以位寻址的寄存器变量
byte bdata  PP4;
sbit P40	= PP4^0;
sbit WDI	= PP4^1;
sbit CLOSE	= PP4^2;
sbit D_I	= PP4^3;

#define SET_I				{D_I=0;		PP4|=0xf0;	P4=PP4;}
#define SET_D				{D_I=1;		PP4|=0xf0;	P4=PP4;}

#define OPEN_LCD_DISPLAY	{CLOSE=0;	PP4|=0xf0;	P4=PP4;}
#define CLOSE_LCD_DISPLAY	{CLOSE=0;	PP4|=0xf0;	P4=PP4;}

#define SET_W_DOG			{WDI=~WDI;	PP4|=0xf0;	P4=PP4;}

#define SELECT_P62256		{P40=0;		PP4|=0xf0;	P4=PP4;}							 
#define SELECT_YD501		{P40=1;		PP4|=0xf0;	P4=PP4;}

//设置灯显示等
byte    bdata  OutBuf;

sbit   Work = OutBuf^0;
sbit   UUUU = OutBuf^1;
sbit   GJGJ = OutBuf^2;
sbit   WXWX = OutBuf^3;
sbit   CDCC = OutBuf^4;
sbit   FDCC = OutBuf^5;
sbit   HHHH = OutBuf^6;
sbit   BJQQ = OutBuf^7;

void OpenBJQ();
void CloseBJQ();



#define SET_EDIT_BUF(items, bufs)  {edit_buf.edit_num = items; \
                                   edit_buf.edit = bufs;       \
                                   edit_buf.pre_edit = 0;      \
                                   edit_buf.cur_edit = 0;}     
								   
typedef struct tagEDIT
{
	unsigned char x;
	unsigned char y;

    unsigned char buf[11];

	unsigned char fdot;
    unsigned char bdot;
}EDIT;

typedef struct tagPOINT
{
	unsigned int x;
	unsigned int y;
}POINT;
typedef struct tagEDITBUF
{
	unsigned char edit_num;
	unsigned char cur_edit;
	unsigned char pre_edit;

	EDIT *edit;

}EDITBUF;


#define EDIT_HEAD   0x1
#define EDIT_END    0x2

typedef union tagUINT
{
	uchar byt[2];
	uint  integer;
}u_int;
typedef struct tagPEN
{
	unsigned char fcolor;
	unsigned char bcolor;
}PEN;
typedef struct tagRECT
{
	unsigned int left;
	unsigned int top;
	unsigned int right;
	unsigned int bottom;
}RECT;				
typedef struct STRUCT_SYSSCREEN
{
	RECT title_rect;
	PEN  title_pen;
	
	RECT client_rect;
	PEN  client_pen;

	RECT status_rect;
	PEN  status_pen;
}SCREEN;

typedef struct STRUCT_MESSAGEBOX
{
	RECT  mt_rect;
	RECT  t_rect;
	uchar tfcolor;
	uchar tbcolor;

	RECT  m_rect;
	uchar mfcolor;
	uchar mbcolor;

	uchar style;
}MESSAGEBOX;

uchar idata   a_fcolor;
uchar idata   a_bcolor;
uchar idata   a_bcolor_l;
uchar idata   a_bcolor_r;
uchar idata   a_fcolor_l;
uchar idata   a_fcolor_r;
PEN   idata   cPen;

//清屏函数声明
extern void Clrlcdram();
extern void Clrlcdram_L();
extern void Clrlcdram_R();
extern void Clrlcdram_D();
extern void Clrlcdram_U();
extern void Clrlcdram_B();
void DelayMs(uint cnt);
//键盘处理函数及端口定义
sbit  xXR4  =  P2^7;
sbit  xXR3  =  P2^6;
sbit  xXR2  =  P2^5;
sbit  xXR1  =  P2^4;

sbit  yYW4  =  P2^3;
sbit  yYW3  =  P2^2;
sbit  yYW2  =  P2^1;
sbit  yYW1  =  P2^0;

void CpuIinit();
void KeyIni();
byte GetKey();
/*********************************SPI***************************/
#define     SYSCLK   22118400          	// SYSCLK frequency in Hz
#define     SPI_READ_DATA_CMD       0x03
#define     SPI_PAGE_PROGRAM_CMD    0x02
#define     SPI_WRITE_ENABLE        0X06
#define     SPI_WRITE_DISABLE       0X04
#define     SPI_WRITE_STA_REG       0X01
#define     SPI_READ_STA_REG        0X05


sbit CS25 = P3^3;
sbit SPI_WP = P3^1;
sbit SPI_HOLD=P3^0;

void SPI0_Init (void);
//BYTE  CheckSPIF();
BYTE  SPI_WRITE_CMD(BYTE CMD);
BYTE  SPI_WRITE_STA(BYTE STA);
BYTE  SPI_READ_STA(BYTE *STA);
BYTE  SPI_Write_Pro(byte *addr,byte *buf,byte len);
BYTE  SPI_Read_Pro(byte *addr,byte *buf,byte len);

BYTE SPI_TEST_PRO();

////////////////////////////////////
//12864液晶
void prl0(uchar com);
void prr0(uchar com);
void prl1(uchar dat);
void prr1(uchar dat);
void IniLcd();
void clearlcd(void);
void dishzXX(uchar x,uchar y,uchar z,bit cpls);
///////////////////////////////////

void ProTime_10ms();
void ProTime_100ms();
void ProTime_200ms();
void ProTime_500ms();

typedef  struct
{
	void (*proc)(void);
	unsigned int time_val;
}__op_;

#define max_pro   4

__op_  code OP[max_pro]=
{
	{ProTime_10ms,10},{ProTime_100ms,100},\
	{ProTime_200ms,200},{ProTime_500ms,500}
};
unsigned int xdata OP_TIME[max_pro]; 

//串口设置
bit     Uart0SendTask=0;          //串口0发送标志,1有数据要发送,0没有数据要发送
bit     Uart0RecTask=0;
byte 	xdata 	 Uart0SendAll=0;         //串行口0要发送数量
byte 	xdata 	 Uart0SendNum=5;     	//串行口0已发送数量
byte 	xdata 	 Uart0RecNum=0;     		//串行口0已接收数量
uchar 	xdata 	 preDat  =0;
byte    xdata   Uart0RecLen;
byte	xdata	 Uart0SendBuff[256];       	//UART0发送数组
byte    xdata   Uart0RecBuff[256];      		//UART0接收数组
byte    xdata   Uart0RecBuf[256];       		//UART0接收数组

/********************************************************************/
bit Uart1SendTask=0;          //串口1发送标志,1有数据要发送,0没有数据要发送
bit Uart1RecTask=0;
uchar 	xdata 	preDat1 =0;
byte    xdata   Uart1RecLen;

byte 	xdata 	Uart1SendAll=0;         	//串行口1要发送数量
byte 	xdata 	Uart1SendNum=0;     		//串行口1已发送数量
byte 	xdata 	Uart1RecNum=0;     		//串行口1已接收数量

byte	xdata	Uart1SendBuff[256];       //UART1发送数组


byte	xdata	Uart1RecBuff[256];      //UART1接收数组
byte	xdata	Uart1RecBuf[256];       //UART1接收数组

#define  S_CHANNELS    1
#define  M_CHANNELS    0

sbit STADDR0 = P1^6;
sbit STADDR1 = P1^5;

sbit SRADDR0 = P1^4;
sbit SRADDR1 = P1^3;

sbit MS8123	 = P1^7;
sbit RST8123 = P1^2;

void SetWorkModel(bit model);
void Init8123();
void SetRChannelsNo(byte no);
BYTE Read8123Cmd();
void Write8123Cmd(byte cmd);
void Uart1Send();
void SetTChannelsNo(byte no);
void SetRChannelsNo(byte no);

//ADC  
uint temp;
typedef union 
{
	uint Dat;
	struct 
	{
		byte Hi;
		byte Li;
	}Byt;
}UINT_U;

UINT_U xdata AdDat;

uint xdata AdcBuff[10][256]={0};
byte xdata adcbufCnt=0;
byte CHAN;


//DAC
void DAC0Out(uint Val);

uint  xdata   OutVal;
bit           ad;
uint          ADCVal;
byte  xdata   datasoi[256]={0};
bit           hh=0 ;

//EDIT

void dishz168XX(uchar x,uchar y,uchar z,bit cpls);
uint xdata vsl[10];

#define WR_OPT 0
#define RD_OPT  1
#define TIME_INIT  2

uchar xdata  str_time[19]={2,0,0,0,11,0,0,11,0,0,28,0,0,10,0,0,10,0,0};
void Ds1307(opt, uchar word_addr, uchar num, uchar *buf);
byte xdata time_hexbuff[20];
byte xdata time_buff[20];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -