请教,关于STC8051的PCA模块
STC8051的PCA模块是什么东西?新手,没见过这东西,汇编教材上好像都没有这模块!有没有相关资料?请各位大虾指点指点!下面这程序主要是那个PCA模块不知道是什么东西,还有那3个子函数#include <reg51.h>
#include <intrins.h>
char a,b,count;
typedef unsigned char BYTE;
typedef unsigned int WORD;
/*Declare SFR associated with the ADC */
sfr ADC_CONTR = 0xBC; //ADC control register
//ADC控制寄存器
sfr ADC_RES = 0xBD; //ADC high 8-bit result register
//ADC的高8位结果寄存器
sfr ADC_LOW2 = 0xBE; //ADC low 2-bit result register
//ADC的低2位结果寄存器
sfr P1ASF = 0x9D; //P1 secondary function control register
//P1的辅助功能控制寄存器
/*Define ADC operation const for ADC_CONTR*/ //定义常量ADC_CONTR ADC操作
#define ADC_POWER 0x80 //ADC power control bit
//ADC的功率控制位
#define ADC_FLAG 0x10 //ADC complete flag
//ADC的完成标志
#define ADC_START 0x08 //ADC start control bit
//ADC启动控制位
#define ADC_SPEEDLL 0x00 //540 clocks //540时钟
#define ADC_SPEEDL 0x20 //360 clocks //360时钟
#define ADC_SPEEDH 0x40 //180 clocks //180时钟
#define ADC_SPEEDHH 0x60 //90 clocks //90时钟
/*Declare SFR associated with the PCA */ //SFR与PCA的相关声明
sfr CCON = 0xD8; //PCA control register //PCA的控制寄存器
sbit CCF0 = CCON^0; //PCA module-0 interrupt flag //PCA模块0中断标志位
sbit CCF1 = CCON^1; //PCA module-1 interrupt flag //PCA模块1中断标志
sbit CR = CCON^6; //PCA timer run control bit //PCA定时器的运行控制位
sbit CF = CCON^7; //PCA timer overflow flag //PCA定时器溢出标志
sfr CMOD = 0xD9; //PCA mode register //PCA的模式寄存器
sfr CL = 0xE9; //PCA base timer LOW //PCA的基础定时器的低位
sfr CH = 0xF9; //PCA base timer HIGH //PCA的基础定时器的高位
sfr CCAPM0 = 0xDA; //PCA module-0 mode register //PCA模块- 0模式寄存器
sfr CCAP0L = 0xEA; //PCA module-0 capture register LOW //PCA模块0捕获寄存器低
sfr CCAP0H = 0xFA; //PCA module-0 capture register HIGH //PCA模块0捕获高字节
sfr CCAPM1 = 0xDB; //PCA module-mode register //PCA模块模式寄存器
sfr CCAP1L = 0xEB; //PCA module-capture register LOW //PCA模块捕获寄存器的低
sfr CCAP1H = 0xFB; //PCA module-capture register HIGH //PCA模块捕获寄存器高字节
sfr PCAPWM0 = 0xf2;
sfr PCAPWM1 = 0xf3;
void InitADC(void);
void AD_get(void);
void Delay(WORD n);
BYTE GetADCResult(BYTE ch);
WORD AD_hei=0x7f; //AD比较值
WORD AD_value;
void main()
{
long int t;
InitADC();
AD_get();
P0=0X00;
t=10000000;
while(t)
{ t--;
a=AD_value;
P2=AD_value;
if(a>b) //b哪来的值??
b=a;
}
while(1)
{
P2=b;
}
}//AD采集值存储数组
void AD_get(void)
{
AD_value=GetADCResult(0xc8); //Show Channel0 //显示通道0
AD_value=GetADCResult(0xc9); //Show Channel1 //显示通道1
AD_value=GetADCResult(0xca); //Show Channel2 //显示通道2
AD_value=GetADCResult(0xcd); //Show Channel3 //显示通道3
AD_value=GetADCResult(0xce); //Show Channel4 //显示通道4
}
void timeinit()//定时器初始化
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
}
BYTE GetADCResult(BYTE ch)
{
ADC_CONTR =ch;
_nop_(); //Must wait before inquiry
//必须等待调查
_nop_();
_nop_();
_nop_();
while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag
//等待完成标志
ADC_CONTR &= ~ADC_FLAG; //Close ADC
//关闭的ADC
return ADC_RES; //Return ADC result
//返回ADC结果
}
void InitADC()
{
P1ASF = 0x67; //Open 8 channels ADC function
//打开8通道ADC功能
ADC_RES = 0; //Clear previous result
//清除以前的结果
ADC_CONTR = 0xc0;
Delay(2); //ADC power-on and delay
//ADC的功耗和延迟
}
/*----------------------------
Software delay function //软件延时功能
----------------------------*/
void Delay(WORD n)
{
WORD x;
while (n--)
{
x = 5000;
while (x--);
}
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}
页:
[1]