找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 10563|回復(fù): 11
收起左側(cè)

基于Atmega16的電壓表制作 程序+原理圖

  [復(fù)制鏈接]
ID:100924 發(fā)表于 2016-1-1 14:10 | 顯示全部樓層 |閱讀模式
附帶proteus設(shè)計(jì)圖 電路圖 大圖在附件里面
0.png
  1. /*****************************************************
  2. Project :
  3. Version :
  4. Date    : 2015-10-29
  5. Author  :tengzaiba
  6. Chip type               : ATmega16
  7. AVR Core Clock frequency: 8.000000 MHz
  8. *****************************************************/
  9. #include <mega16.h>
  10. #include <delay.h>
  11. // Declare your global variables here
  12. char LCD_7[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
  13. char dis_buff[4];
  14. unsigned int votage=0;
  15. unsigned int vot1;
  16. // Timer 0 overflow interrupt service routine
  17. interrupt [TIM0_OVF] void timer0_ovf_isr(void)
  18. {
  19. // Place your code here
  20. // Read the 8 most significant bits
  21. // of the AD conversion result
  22. PORTC.7=~PORTC.7;
  23. delay_us(20);
  24. while ((ADCSRA & 0x10)==0);
  25. ADCSRA|=0x10;
  26. vot1=ADCW;
  27. votage=(unsigned long)vot1*5000/1024;
  28. }

  29. void display(unsigned int vot)
  30. {
  31. // move vot to dis_buff
  32. char i;
  33. char j;
  34. for (i=0;i<4;i++)
  35.    {
  36.            dis_buff[i]=vot % 10;
  37.            vot/=10;
  38.    }
  39. // dis_buff to LEDs
  40. for (j=0;j<=3;j++)
  41.    {
  42.            PORTC=LCD_7[dis_buff[j]];
  43.            PORTA=~(1<<j);
  44.            delay_ms(2);
  45.            PORTA=0x0f;
  46.    }
  47. }

  48. void main(void)
  49. {
  50. // Declare your local variables here

  51. // Input/Output Ports initialization
  52. // Port A initialization
  53. // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
  54. // State7=T State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0
  55. PORTA=0x00;
  56. DDRA=0x0F;

  57. // Port B initialization
  58. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
  59. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
  60. PORTB=0x00;
  61. DDRB=0x00;

  62. // Port C initialization
  63. // Func7=In Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  64. // State7=T State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
  65. PORTC=0x00;
  66. DDRC=0xFF;

  67. // Timer/Counter 0 initialization
  68. // Clock source: System Clock
  69. // Clock value: Timer 0 Stopped
  70. // Mode: Normal top=FFh
  71. // OC0 output: Disconnected
  72. TCCR0=0x03;
  73. TCNT0=0x00;
  74. OCR0=0x00;

  75. // External Interrupt(s) initialization
  76. // INT0: Off
  77. // INT1: Off
  78. // INT2: Off
  79. MCUCR=0x00;
  80. MCUCSR=0x00;

  81. // Timer(s)/Counter(s) Interrupt(s) initialization
  82. TIMSK=0x01;

  83. // Analog Comparator initialization
  84. // Analog Comparator: Off
  85. // Analog Comparator Input Capture by Timer/Counter 1: Off
  86. ACSR=0x80;
  87. SFIOR=0x00;

  88. // ADC initialization
  89. // ADC Clock frequency: 1000.000 kHz
  90. // ADC Voltage Reference: AREF pin
  91. // ADC Auto Trigger Source: Timer0 Overflow
  92. // Only the 8 most significant bits of
  93. // the AD conversion result are used
  94. ADMUX=0x47;
  95. ADCSRA=0xA3;
  96. SFIOR&=0x1F;
  97. SFIOR|=0x80;

  98. // Global enable interrupts
  99. #asm("sei")

  100. while (1)
  101.       {
  102.                
  103.                   display(votage);
  104.       };
  105. }
復(fù)制代碼


AVR16電壓表制作.rar

60.88 KB, 下載次數(shù): 124, 下載積分: 黑幣 -5

電壓表制作

評(píng)分

參與人數(shù) 2黑幣 +51 收起 理由
51單片機(jī)1234 + 1 很給力!
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

ID:109699 發(fā)表于 2016-3-19 15:37 | 顯示全部樓層
謝謝樓主的分享
回復(fù)

使用道具 舉報(bào)

ID:25999 發(fā)表于 2016-7-27 09:01 | 顯示全部樓層
下載學(xué)習(xí)一下
回復(fù)

使用道具 舉報(bào)

ID:200118 發(fā)表于 2017-5-26 22:44 | 顯示全部樓層
謝謝分享
回復(fù)

使用道具 舉報(bào)

ID:76408 發(fā)表于 2018-1-31 16:27 | 顯示全部樓層
好東西,我收藏了等待下載。
回復(fù)

使用道具 舉報(bào)

ID:8222 發(fā)表于 2018-10-25 11:16 | 顯示全部樓層
謝謝分享。
回復(fù)

使用道具 舉報(bào)

ID:419259 發(fā)表于 2018-11-1 17:40 | 顯示全部樓層
不錯(cuò)的貼子,很想要資源
回復(fù)

使用道具 舉報(bào)

ID:229361 發(fā)表于 2019-1-21 09:58 | 顯示全部樓層
很不錯(cuò),學(xué)習(xí)了
回復(fù)

使用道具 舉報(bào)

ID:76408 發(fā)表于 2019-3-4 08:35 | 顯示全部樓層
謝謝樓主,我很需要,收藏了!
回復(fù)

使用道具 舉報(bào)

ID:76408 發(fā)表于 2019-8-8 22:56 | 顯示全部樓層
謝謝樓主,我下載了
回復(fù)

使用道具 舉報(bào)

ID:76408 發(fā)表于 2019-11-24 14:00 | 顯示全部樓層
謝謝樓主辛苦了。。。。。。
回復(fù)

使用道具 舉報(bào)

ID:138997 發(fā)表于 2019-12-14 16:34 | 顯示全部樓層
剛學(xué)習(xí)avr單片機(jī),仿制一個(gè)來(lái)提高自信心。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表