虫虫首页|资源下载|资源专辑|精品软件
登录|注册

您现在的位置是:虫虫下载站 > 资源下载 > C/C++语言编程 > c8051f330 C程序源代码

c8051f330 C程序源代码

  • 资源大小:24 K
  • 上传时间: 2013-10-13
  • 上传用户:shanon
  • 资源积分:2 下载积分
  • 标      签: c8051f330 C程序 源代码

资 源 简 介

//------------------------------------------------------------------------------------
//此程序为ADC转换程序,可以选择向ADC0BUSY写1或用定时器0,1,2,3作为ADC的启动信号。
//
//------------------------------------------------------------------------------------
//头文件定义
//------------------------------------------------------------------------------------
//
#include <c8051f330.h>              
#include <stdio.h>

//-----------------------------------------------------------------------------
// 定义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的结果
          }
   }

相 关 资 源