首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

pic168xa ADC程序(c语言)

pic168xa ADC程序(c语言)

pic168xa ADC程序(c语言)

#i nclude <pic.h>
#i nclude <pic168xa.h>
__CONFIG(0x1832);        
//芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡
const char TABLE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DELAY();
void DELAY11();
void init();
void display(unsigned int x);
void main()
{unsigned int result=0x0000;
  do
  {
   int i;
   result=0x0000;
   //for(i=4;i--;)
    // {
      init();
      DELAY();
      ADGO=0X01;
      while(ADGO)
      {result=ADRESH;
       result=result<<8;
       result=result+ADRESL;};
    // }
     // result=result>>3;
     for(i=10;--i;)
     {display(result);};
      //DELAY11();};
      
}while(1);
  
  }
void init()
  {
   TRISD=0X00;
   TRISB=0XE1;
   PORTD=0X00;
   ADCON1=0X8E;
   ADCON0=0XC1;
   DELAY();
  }
void display(unsigned int x)
  {int qian,bai,shi,ge;
   unsigned int temp;
     temp=x;
     qian=temp/0x3e8;
     PORTD=TABLE[qian];       //查表得百位显示的代码
     PORTB=0xef;           //RA3输出低电平,点亮百位显示
    // DELAY11();
     bai=(temp%0x3e8)/0x64;
     PORTD=TABLE[bai];       //查表得百位显示的代码
     PORTB=0xf7;           //RA3输出低电平,点亮百位显示
     //DELAY11();   
     shi=((temp%0x3e8)%0x64)/0xa;            //延时一定时间,保证显示亮度
     PORTD=TABLE[shi];       //查表得十位显示的代码
     PORTB=0xfb;             //RA4输出低电平,点亮十位显示
     //DELAY11();   
     ge=((temp%0x3e8)%0x64)%0xa;             //延时一定时间,保证亮度
     PORTD=TABLE[ge];        //求个位显示的代码
     PORTB=0xfd;             //RA5输出低电平,点亮个位显示
     DELAY11();
  }  
void DELAY()
  {
   int i;
   for(i=0x100;i--;);
  }
void DELAY11()
  {
   int i;
   for(i=0;i<=30;i++)
   continue;
  }
返回列表