久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: ATtiny13-RGB-LED-Colormixer源程序 [打印本頁]

作者: pannygg    時間: 2018-8-6 22:29
標題: ATtiny13-RGB-LED-Colormixer源程序
RGB LED MIXER- In this project we used the attiny 13 microcntroller for operating the RGB LED AND COLOR MIXING.


單片機源程序如下:

  1. /*
  2. Chapter - 2
  3. Project - 3 RGB Colormixer

  4. */

  5. #include<avr/io.h>
  6. #include<avr/interrupt.h>
  7. #define F_CPU 9600000UL
  8. #include<util/delay.h>

  9. //Prototypes

  10. //This function is called to switch on the LED at the
  11. //Required stage of PWM cycle
  12. void abc(unsigned char a,unsigned char b,unsigned char c,unsigned char status);

  13. //This function read the value of ADC from selected channel
  14. unsigned char read_adc(unsigned char channel);


  15. //Global variables
  16. volatile unsigned char e;
  17. volatile unsigned char pwm[3]={255,255,255};


  18. int main(void)
  19. {


  20.         DDRB  &= ~((1<<3)|(1<<4)|(1<<5));//ADC inputs
  21.        
  22.         //Initially LEDs should be off
  23.         DDRB |=  (1<<0|1<<1|1<<2);
  24.         PORTB |= (1<<0)|(1<<1)|(1<<2);
  25.        
  26.         //ADC init
  27.        
  28.         ADMUX =  0b00100000; //ADC0 (default),ADLAR,VCc
  29.         ADCSRA = 0b10000010; //prescaled by 4
  30.        
  31.         //Timer Initialisation
  32.         TCCR0A = 0x00;
  33.         TCCR0B = 0x01;//No Prescaling
  34.         TIMSK0 = 1<<TOIE0;//Overflow Interrupt Enabled
  35.         sei();//Global Interrupts Enabled

  36.         while(1)
  37.         {       
  38.        
  39.                 pwm[0]=read_adc(0);
  40.                 pwm[1]=read_adc(2);
  41.                 pwm[2]=read_adc(3);
  42.                
  43.                 _delay_ms(2);//Just a small delay       
  44.        
  45.         }

  46.        

  47. }


  48. //Overflow routine for Timer 0
  49. ISR(TIM0_OVF_vect)
  50. {
  51.        
  52.         //Value of e decides the no of levels of PWM.
  53.         //This has 256 levels for e - 0 to 255
  54.         //0 - complete on and 255 is complete off
  55.        
  56.         if(e==255)
  57.         {
  58.                 e=0;
  59.                 PORTB |= (1<<0)|(1<<1)|(1<<2);
  60.         }

  61.         abc(pwm[0],pwm[1],pwm[2],e);
  62.        
  63.         e++;
  64.        
  65. }


  66. //This function is called to switch on the LED at the
  67. //Required stage of PWM cycle
  68. void abc(unsigned char a,unsigned char b,unsigned char c,unsigned char status)
  69. {

  70.         if((status==a))
  71.         {
  72.                 PORTB&= ~(1<<0);
  73.         }
  74.         if((status==b))
  75.         {
  76.                 PORTB&= ~(1<<1);
  77.         }
  78.         if((status==c))
  79.         {
  80.                 PORTB&= ~(1<<2);
  81.         }
  82.        
  83. }

  84. //This function read the value of ADC from selected channel
  85. unsigned char read_adc(unsigned char channel)
  86. {
  87.        
  88.         unsigned char k;
  89.         unsigned int adcvalue=0;
  90.         ADMUX = ADMUX&(0b11111100); //clear channel select bits
  91.         ADMUX |= channel;        
  92.        
  93.         //neglect first reading after changing channel
  94.         ADCSRA |= 1<<ADSC;
  95.         while(ADCSRA&(1<<ADSC));//Wait
  96.         adcvalue=ADCH;
  97.         adcvalue=0;//neglectreading
  98.         for(k=0;k<=7;k++)
  99.         {
  100.                 ADCSRA |= 1<<ADSC;
  101.                 while(ADCSRA&(1<<ADSC));//Wait
  102.                 adcvalue += ADCH;
  103.         }
  104.         return (adcvalue>>3); //divide by 8
  105.        
  106. }

復制代碼

所有資料51hei提供下載:
Project-3-RGB-LED-Colormixer.rar (116.49 KB, 下載次數: 21)



作者: 1106998808    時間: 2019-10-30 16:40
你這個用arduino軟件打開燒錄不了




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 日韩精品一区二区三区第95 | 天天爱av | 在线看91 | 欧美日韩在线免费观看 | 日本精品视频一区二区三区四区 | 欧美视频 | 在线播放国产一区二区三区 | 国产亚洲成av人片在线观看桃 | 免费看淫片 | a级在线 | 久久久久久高潮国产精品视 | 亚洲精品99 | 亚洲欧洲一区二区 | 欧美情趣视频 | 日韩欧美三级 | 成人免费视频 | 亚洲小视频在线播放 | 亚洲视频欧美视频 | 一区二区三区视频在线免费观看 | 999热视频| 一区中文字幕 | 91精品国产91久久久久久最新 | 国产欧美久久精品 | 日韩在线欧美 | 色播av| 草b视频 | 国产精品无码永久免费888 | 国产丝袜一区二区三区免费视频 | 黄色毛片视频 | 欧美日韩1区2区 | 美美女高清毛片视频免费观看 | 久久久www成人免费精品 | 国产一级久久久久 | 日韩a在线观看 | 日韩在线观看中文字幕 | 久艹网站 | 国产一区二区三区久久 | 午夜看片 | 伊人网综合在线 | 国产精品伦理一区二区三区 | 国产成人99久久亚洲综合精品 |