Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- *
- * Created on: 28 lut 2015
- * Author: miszczo
- *
- *; ============================================
- *; H A R D W A R E I N F O R M A T I O N
- *; ============================================
- *;
- *;
- *; ____________
- *; / ATtiny13 |
- *; | |
- *; RESET o--|RES VCC|--o +5V VCC
- *; | |
- *; ADC o--|PB3 PB2|--o SCK
- *; | |
- *; LED o--|PB4 PB1|--o MISO
- *; | |
- *; 0 V o--|GND PB0|--o MOSI
- *; |_____________|
- *;
- */
- #include <avr/io.h>
- #include <util/delay.h>
- #define LED_OFF PORTB |=(1<<PB4)
- #define LED_ON PORTB &= ~(1<<PB4)
- uint8_t get_random(void);
- int main()
- {
- DDRB = (1<<PB4);
- while(1){
- if(get_random()) LED_ON;
- else LED_OFF;
- _delay_ms(400);
- }
- }
- // funckaj zwaraca losowa wartosc 1 lub 0
- uint8_t get_random(void){
- ADMUX = (1<<MUX0)|(1<<MUX1); // pomiar na PB3
- //ustawienia adc, adc enable , preskaler 128 , start conversion,
- ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) | (1<<ADSC);
- while(ADCSRA&(1<<ADSC));//wait for end conversion
- return (ADCL&0x01);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement