標(biāo)題: PIC16F917單片機(jī)ADC程序與Proteus仿真圖 [打印本頁]

作者: Sdstechsds    時間: 2021-8-27 00:36
標(biāo)題: PIC16F917單片機(jī)ADC程序與Proteus仿真圖
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include<pic.h>




  2.         void disp_adc_LED();

  3.         main()


  4.         {

  5.         int count ;

  6.            PORTB = 0 ;

  7.            count = 0 ;


  8.         TRISA = 0xFF ;                        // input
  9.         TRISB = 0x00 ;                        // output


  10.         RA0 = 0 ;






  11.         ADCON0 = 0x85 ;                                //                Right justified  , V ref+ = V dd  ,  Ch 1

  12.         ADCON1 = 0x30 ;







  13.                 for(;;)
  14.                         {
  15. do_conv:



  16.         ADCON0,GODONE = 1 ;







  17.         wait_eoc   :    while ( ADCON0,GODONE != 0 )






  18.         {
  19.                 goto wait_eoc   ;
  20.         }






  21.                 disp_adc_LED();




  22.                 for ( count = 0xf0 ; count > 0 ; count -- ) ;




  23.                         }




  24.         }












  25.   void disp_adc_LED()

  26. {
  27.         unsigned int i ;

  28.         i = ( ADRESH * 256 ) + ADRESL ;




  29.         if ( i > 896 )
  30.                 PORTB = 0x0F        ;

  31.         else

  32.         if ( i > 768 )
  33.                 PORTB = 0x0E        ;

  34.         else

  35.         if ( i > 640 )
  36.                 PORTB = 0x0C        ;
  37.         else

  38.         if ( i > 512 )
  39.                 PORTB = 0x08        ;


  40.         else
  41.         
  42.         if ( i > 384 )
  43.                 PORTB = 0x10        ;

  44.         else

  45.         if ( i > 256 )
  46.                 PORTB = 0x30        ;

  47.         else

  48.         if ( i > 128 )
  49.                 PORTB = 0x70        ;

  50.         else
  51.                 PORTB = 0xF0        ;









  52. }


  53. // ASSUMPTION :

  54. //         Gyro left  -->         OP < 2.5V ( Low Nibble LEDs )

  55. //         Gyro Right -->         OP > 2.5V ( High Niblle LEDs )
復(fù)制代碼

所有資料51hei附件下載,Proteus7.5版本的仿真圖:
16F917 ADC.zip (20.92 KB, 下載次數(shù): 15)
delay_pic.X.zip (52.2 KB, 下載次數(shù): 12)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1