How to write a C Program Dimmer Example in C Programming Language ?
Solution:
- #define F_CPU 8000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- volatile unsigned char h=20;
- ISR(TIMER0_COMP_vect) {
- TCCR0=0b00001000;
- PORTD|=(1<<PD5);
- _delay_us(10);
- PORTD&=~(1<<PD5);
- TIMSK=0;
- TCNT0=0;
- }
- ISR(_VECTOR(1))
- {
- OCR0=h;
- TCCR0=0b00001101;
- TIMSK=0b00000010;
- }
- int main(void)
- {
- //DECLARACION DE ENTRADAS Y SALIDAS
- DDRD=0b00100001;
- PORTD=0b11101110;
- //Declaración de interrupciones
- MCUCR=0b00000001;
- //Enable external interrupt 0
- GICR=0b01000000;
- asm("SEI");
- while(1)
- {
- //SUMA
- if(!(PIND&(1<<PIND1))) // Está en cero el PIN 7 del puerto D????
- {
- _delay_ms(10); //Espero 10ms para ver si no es ruido
- if(!(PIND&(1<<PIND1))) // Está todavía en cero el PIN 7 del puerto D????
- {
- h=h+2;
- if(h>60)
- {
- h=60;
- }
- while(!(PIND&(1<<PIND1)))
- {
- }
- }
- }
- //resta
- if(!(PIND&(1<<PIND3)))
- {
- _delay_ms(10); //Espero 10ms para ver si no es ruido
- if(!(PIND&(1<<PIND3))) // Está todavía en cero el PIN 7 del puerto A????
- {
- h=h-2;
- if(h<4)
- {
- h=4;
- }
- while(!(PIND&(1<<PIND3)))
- {
- }
- }
- }
- }
- }
Learn More :
Example
- C Program String - Alphabet Count Example
- C Program Array Example: Average
- C Program Array Example: Reverse
- C Program Switch - Case Example
- C Program if - else if - else Example
- C Program Friend & Operator: Point2D Example
- C Program Friend & Operator: Vector Example
- C Program Recursion Example
- C Program Structure Example-2
- C Program Structure Example
- C Program Pointer Example
- C Program Function Example
- C Program String Example
- C Program Character Example
- C Program sizeof & memcpy Example
- C Program Array Example
- C Program Side Length Example
- C Program Pipes()
- C Program 0-1000 to Ordinary
- C Program Roboturtle
- C Program to Destroys a Mailbox
- C Program to Destroys a semaphore
- C Code for Testing the pH Meter V1.0
- APA 102c test program
- How To Retarget the C Library printf function to the UART.