標題: avr單片機精練的兩路ADC代碼+仿真圖 [打印本頁]

作者: jinsheng7533967    時間: 2018-12-20 15:52
標題: avr單片機精練的兩路ADC代碼+仿真圖
電路原理圖如下:


  1. #include <iom16v.h>
  2. #include <macros.h>
  3. #define uchar unsigned char
  4. #define uchar  unsigned int

  5. const uchar SEG_CODE[] =
  6. {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};

  7. uchar display[] = {0,0,0,10,0,0,0,10};

  8. void delay(uint mS);         


  9. void  main()
  10. {
  11.         
  12.         uchar  i;
  13.         
  14.         DDRA = 0xfc;   
  15.         
  16.         DDRC = 0xff;   PORTC = 0x00;
  17.         
  18.         DDRD = 0xff;   PORTD = 0x00;
  19.         
  20.         ADCSRA = 0xE6;
  21.         
  22.         delay(300);
  23.         
  24.         
  25.         while(1)
  26.                
  27.         {
  28.                
  29.                 ADC_num(0);  ADC_num(1);
  30.                
  31.                 for(i = 0; i < 8; i++)
  32.                 {
  33.                         PORTC = 0xff;
  34.                         
  35.                         PORTD = BIT(i);
  36.                         
  37.                         PORTC = SEG_CODE[display[i]];
  38.                         
  39.                         if(i == 0)PORTC &= 0x7F ;

  40.                      else if(i == 4)PORTC &= 0x7F ;
  41.                         
  42.                         delay(4);
  43.                         
  44.                 }
  45.         }
  46.         
  47. }


  48. void delay(uint mS)         
  49. {
  50.   uchar x,y;
  51.                 for(x=0;x<mS;x++)
  52.                         for(y=0;y<10;y++);
  53. }
復制代碼


完整代碼附件中

avr_精練的兩路ADC.rar (20.61 KB, 下載次數: 47)






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