c8051f330 C程序源代码

hopeless3172 12 0 rar 2022-09-23 06:09:40

//------------------------------------------------------------------------------------

//此程序为ADC转换程序,可以选择向ADC0BUSY写1或用定时器0,1,2,3作为ADC的启动信号。

//

//------------------------------------------------------------------------------------

//头文件定义

//------------------------------------------------------------------------------------

//

#include               

#include

//-----------------------------------------------------------------------------

// 定义16位特殊功能寄存器

//-----------------------------------------------------------------------------

sfr16 ADC0     = 0xbd;               

sfr16 TMR0RL   = 0xca;                                                                                              

sfr16 TMR1RL   = 0xca;                

sfr16 TMR2RL   =0xca;                

sfr16 TMR3RL   =0xca;              

sfr16 TMR0     = 0xCC;             

sfr16 TMR1     = 0xCC;               

sfr16 TMR2     = 0xcc;              

sfr16 TMR3     = 0xcc;              

//-----------------------------------------------------------------------------

// 全局变量定义

//-----------------------------------------------------------------------------

char i;

int result;                      

//-----------------------------------------------------------------------------

//定义常量

//-----------------------------------------------------------------------------

#define SYSCLK       49000000       

#define SAMPLE_RATE  50000            

//------------------------------------------------------------------------------------

// 定义函数

//------------------------------------------------------------------------------------

void SYSCLK_Init (void);

void PORT_Init (void);

void TImer0_Init (int counts);

void TImer1_Init (int counts);

void TImer2_Init (int counts);

void TImer3_Init (int counts);

void ADC0_Init(void);

void ADC0_ISR (void);

void ADC0_CNVS_ADC0h(void);

//------------------------------------------------------------------------------------

// 主程序

//------------------------------------------------------------------------------------

void main (void)

{  

    int ADCRESULT[50] ;

  int k;                

    PCA0MD &= ~0x40;                       // 禁止看门狗             

 

   SYSCLK_Init ();                  

 

   PORT_Init ();

 

   Timer0_Init (SYSCLK/SAMPLE_RATE); 

   //Timer1_Init (SYSCLK/SAMPLE_RATE);     //选择相应的启动方式

   //Timer2_Init (SYSCLK/SAMPLE_RATE);

   //Timer3_Init (SYSCLK/SAMPLE_RATE);      

   ADC0_Init();

   EA=1;

   while(1)

            {

    

 //ADC0_CNVS_ADC0h(); 

 k=ADC0;

   ADCRESULT[i]=result;                   //此处设断点,观察ADCRESULT的结果

          }

   }

用户评论
请输入评论内容
评分:
暂无评论