Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. Aufgabe 1
  2. -------------------------------------------------------------------------------------------------------------
  3. #include <asf.h>
  4. #include "interrupt.h"
  5.  
  6. int main (void)
  7. {
  8. sei();
  9.  
  10. //Konfiguration Pins
  11. DDRB |= (1<<PINB);
  12.  
  13. //Konfiguration Timer
  14. TCCR0 |= (1<<CS02) | (1<<CS00); //prescale 1024
  15. TIMSK |= (1<<TOIE0); //interrupt an
  16.  
  17.  
  18. TCNT0 = 255; //1ms warten
  19. Count = 0;
  20. State = 0;
  21.  
  22.  
  23. while (1)
  24. {
  25.  
  26. }
  27. }
  28.  
  29.  
  30. ISR (TIMER0_OVF_vect)
  31. {
  32. if (State == 0)
  33. {
  34. State = 1;
  35. PORTB |= (1<<PB0);
  36. }
  37.  
  38. else
  39. {
  40. State = 0;
  41. PORTB &= ~(1<<PB0);
  42. }
  43.  
  44. TCNT0 = 255; //1ms warten
  45. }
  46.  
  47. Aufgabe 2
  48. -------------------------------------------------------------------------------------------------------------
  49.  
  50. #include <asf.h>
  51. #include "interrupt.h"
  52.  
  53. int main (void)
  54. {
  55. sei();
  56.  
  57. //Konfiguration Ports
  58. DDRB = 0xFF; //alle als ausgang
  59.  
  60. //Konfiguration ADC
  61. ADMUX |= (1<<REFS0) | (1<<ADLAR);
  62. ADCSRA |= (1<< ADEN) | (1<<ADIE);
  63.  
  64.  
  65. while (1)
  66. {
  67. ADCSRA |= (1<<ADSC); //ADC starten
  68. }
  69.  
  70. }
  71.  
  72. ISR (ADC_vect)
  73. {
  74. PORTB = ADCH; //ADC Ergebniss bei PORTB ausgeben
  75. }
  76.  
  77. Aufgabe 3
  78. -------------------------------------------------------------------------------------------------------------
  79.  
  80. #include <asf.h>
  81. #include "interrupt.h"
  82.  
  83. volatile int Count;
  84. volatile int State;
  85.  
  86. int main (void)
  87. {
  88. sei();
  89.  
  90. //Konfiguration Ports
  91. DDRB |= (1<<PINB);
  92.  
  93. //Konfiguration Timer
  94. TCCR0 |= (1<<CS02) | (1<<CS00); //prescale 1024
  95. TIMSK |= (1<<TOIE0); //interrupt an
  96.  
  97. //Konfiguration ADC
  98. ADMUX |= (1<<REFS0) | (1<<ADLAR);
  99. ADCSRA |= (1<< ADEN);
  100.  
  101.  
  102. TCNT0 = 255; //0,25s warten
  103. Count = 0;
  104. State = 0;
  105.  
  106.  
  107. while (1)
  108. {
  109.  
  110. }
  111.  
  112. }
  113.  
  114. ISR (TIMER0_OVF_vect)
  115. {
  116. //HIGH
  117. //Es wird High, dannach wird 1ms gewartet
  118. if (State == 0)
  119. {
  120. State = 1;
  121. PORTB |= (1<<PB0);
  122. TCNT0 = 255; //1ms warten
  123. }
  124.  
  125. //LOW
  126. else
  127. {
  128. ADCSRA |= (1<<ADSC); //ADC starten
  129. while ( !( ADCSRA & (1<<ADIF)) );
  130.  
  131. State = 0;
  132. PORTB &= ~(1<<PB0);
  133. TCNT0 = 255-ADCH; //1ms warten
  134. }
  135. }
  136.  
  137. Aufgabe 3+
  138. -------------------------------------------------------------------------------------------------------------
  139.  
  140. #include <asf.h>
  141. #include "interrupt.h"
  142.  
  143. volatile int Count;
  144. volatile int State;
  145.  
  146. int main (void)
  147. {
  148. sei();
  149.  
  150. //Konfiguration Ports
  151. DDRB |= (1<<PINB);
  152.  
  153. //Konfiguration Timer
  154. TCCR0 |= (1<<CS01); //prescale 8
  155. TIMSK |= (1<<TOIE0); //interrupt an
  156.  
  157. //Konfiguration ADC
  158. ADMUX |= (1<<REFS0) | (1<<ADLAR);
  159. ADCSRA |= (1<< ADEN);
  160.  
  161.  
  162. TCNT0 = 255; //8µs warten
  163. Count = 0;
  164. State = 0;
  165.  
  166.  
  167. while (1)
  168. {
  169.  
  170. }
  171.  
  172. }
  173.  
  174. ISR (TIMER0_OVF_vect)
  175. {
  176. //HIGH
  177. //Es wird High, dannach wird 1ms gewartet
  178. if (State == 0)
  179. {
  180. State = 1;
  181. PORTB |= (1<<PB0);
  182. TCNT0 = 255; //8µs warten
  183. }
  184.  
  185. //LOW
  186. else
  187. {
  188. ADCSRA |= (1<<ADSC); //ADC starten
  189. while ( !( ADCSRA & (1<<ADIF)) );
  190.  
  191. State = 0;
  192. PORTB &= ~(1<<PB0);
  193. TCNT0 = 255-ADCH; //8µs-2ms warten
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement