⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taila.c

📁 A simple C program to strobe the LEDsvia Port D. The strobe rate is to be set by adjusting the volta
💻 C
字号:
/* tailA.c	ENEL206 Assignment 2 Part A
 *		ATmega8 taillight circuit
 * Last edited:	5-7-2004
 * Purpose:	A simple C program to strobe the LEDsvia Port D.
 *      The strobe rate is to be set by adjusting the voltage
 *      drop over a potentiometer that is sampled by an ADC.
 */
 
#include <avr/io.h>

int main(void)
{
   // LS LED set to on initially (0 = LED off)
   unsigned char pattern = 0x00;
   
   // ADC configuration:
   ADMUX = (1 << REFS0) | (1 << ADLAR);
    	// Vcc is reference, left adjusted value, input from PC0.
   ADCSRA = (1 << ADEN) | 0x07;
    	// Enable the ADC, prescaler factor = 128.

	
   TCCR1A = 0; 	// Timer 1 control registers set for:
   TCCR1B = 0x0C;// prescaler = /256,mode = CTC using OCR1A.
				
   DDRD = 0xFF;	// All Port D pins configured for output

   while (1)   // Loop forever
   {

      pattern = ~pattern;	// reverse pattern
      PORTD = pattern;	// Update LEDs 

      // Start a conversion 
	  ADCSRA |= (1 << ADSC);
      
      // Read the 8-bit left adjusted ADC result.
      // ues ADCH to decide the length of a duty cycle.
      // inrease the duty cycle by shift lest 4.
      OCR1A = (0x0F | ADCH) << 4; 

      while (!(TIFR & (1 << OCF1A)));	// Test OCF1A flag in TIFR
        	    //  (i.e. wait 0.1 sec from last counter reset)
      TIFR |= (1 << OCF1A);		// Reset flag bit 
				//  (i.e. write 1 to it)
   }

   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -