/芯片的工作頻率為22.1184MHz 主機源碼
#include<STC15F2K60S2.H>
#include <INTRINS.H>
#include<ABSACC.H>
#include<STDIO.H>
#include "AD_SPI.H"
#include "AD_UartInit.H"
#define ulong unsigned long // 4 byte
#define uint unsigned int //2 byte 0-65535
#define uchar unsigned char // byte 0-255
#define nop8(); {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();};
void Delay20us();
void Delay50ms();
uchar *AD_array_point;
uchar xdata AD_ZERO[144] _at_ 0x20;
uchar k,i,j;
void main()
{
Delay50ms();
AD_UartInit();
AD_InitSpi();
IE2 |= ESPI;
EA = 1;
while(1){
for(j=0;j<144;j++) //RAM初始化
{
AD_ZERO[j]=0;
}
/**********************/
while(!RI); //*****
RI=0;
for(k=0;k<144;k++) //72通道采樣
{
AD_ZERO[k]= k;
}
/********發送數組到從機***************/
AD_array_point=AD_ZERO; //定位調零數組
for(k=0;k<144;k++)
{
SS=0;
SPDAT=*AD_array_point;
AD_array_point++;
Delay20us();
Delay20us();
Delay20us();
Delay20us();
Delay20us();
Delay20us();
}
/***********顯示發送到從機的數組*********************/
AD_array_point=AD_ZERO;
for(k=0;k<144;k++)
{
TI=1;
printf("0X%bx\n",AD_ZERO[k]); //0928屏蔽
}
}
}
void Delay50ms() //@22.1184MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 5;
j = 52;
k = 195;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void spi_isr() interrupt 9 using 1 //SPI中斷服務程序 9 (004BH)
{
SPSTAT = SPIF | WCOL; //清除SPI狀態位
SS = 1; //拉高從機的SS
}
void Delay20us() //@22.1184MHz
{
unsigned char i;
i = 108;
while (--i);
}
|