spi_slave_1._c

来自「用ICC编写的程序包括SPI」· _C 代码 · 共 56 行

_C
56
字号
#pragma interrupt_handler spi_stc_isr:11
unsigned char CntByte=0;
unsigned char frame[4];
unsigned char temp;
//数据包格式:第一个字节是表示是命令还是数据包:0xaa是命令包
//											    0x55是数据包
//			  第二,三个字节是表示什么命令及数据
//			  第四个字节表示校验码。4=1&2+3
void spi_stc_isr(void)
{
  temp=SPDR;
  if(CntByte<4)
  frame[CntByte]=temp;
  else
  {
  i=0;
  if(frame[3]==(frame[0]&frame[1]+frame[2]))
  	{
	 switch(frame[0])
	   case 0xaa:
	        {
			switch(frame[1])
			case 0x01:
			  putSPIchar(0x55);
			  putSPIchar(*(unsigned char*)(qep_cnt));
			  putSPIchar(*((unsigned char*)(qep_cnt)+1));
			  putSPIchar(*(unsigned char*)(qep_cnt)&0x55+*((unsigned char*)(qep_cnt)+1));
			  break;
			case 0x02:
			  putSPIchar(0x55);
			  putSPIchar(*(unsigned char*)(qep_cnt+1));
			  putSPIchar(*((unsigned char*)(qep_cnt+1)+1));
			  putSPIchar(*(unsigned char*)(qep_cnt+1)&0x55+*((unsigned char*)(qep_cnt+1)+1));
			  break;
			 default:
			  break;
			}
	   case 0x55:	
	   case 0x00:
  
  














}

⌨️ 快捷键说明

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