×
单片机 > 单片机程序设计 > 详情

pic168xa ADC程序(c语言)

发布时间:2020-05-16 发布时间:
|
#i nclude

#i nclude
 __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;
  }


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
AVR单片机中RC电容触摸的感应原理解析