« SE3 PSE Binome2023-7 » : différence entre les versions
Aller à la navigation
Aller à la recherche
Aucun résumé des modifications |
(→Code 1) |
||
Ligne 10 : | Ligne 10 : | ||
=== Code 1 === | === Code 1 === | ||
#include<avr/io.h> | #include<avr/io.h> | ||
#include<stdio.h> | #include<stdio.h> | ||
#include<stdlib.h> | #include<stdlib.h> | ||
Ligne 33 : | Ligne 33 : | ||
} | } | ||
void put_bit(unsigned int bit, unsigned char port, unsigned int io) | |||
{ | { | ||
if (io == 1) | if (io == 1) | ||
Ligne 49 : | Ligne 49 : | ||
} | } | ||
int get_bit(unsigned int bit, unsigned char port) | |||
{ | { | ||
if (port == 'B') return 1 & (PINB>>bit); | if (port == 'B') return 1 & (PINB>>bit); | ||
Ligne 57 : | Ligne 57 : | ||
} | } | ||
int main(void) | |||
{ | { | ||
//Setup | //Setup |
Version du 11 mars 2024 à 16:59
Manette
Photos
Programmation AVR
Allumage de LEDS
Code 1
#include<avr/io.h> #include<stdio.h> #include<stdlib.h>
void config(unsigned int bit, unsigned char port, unsigned int io) { if (io == 1) { if (port == 'B') DDRB |= (io<<bit); if (port == 'C') DDRC |= (io<<bit); if (port == 'D') DDRD |= (io<<bit); } else if (io == 0) { if (port == 'B') DDRB &= ~(1<<bit); if (port == 'C') DDRC &= ~(1<<bit); if (port == 'D') DDRD &= ~(1<<bit); } }
void put_bit(unsigned int bit, unsigned char port, unsigned int io)
{ if (io == 1) { if (port == 'B') PORTB |= (io<<bit); if (port == 'C') PORTC |= (io<<bit); if (port == 'D') PORTD |= (io<<bit); } else if (io == 0) { if (port == 'B') PORTB &= ~(1<<bit); if (port == 'C') PORTC &= ~(1<<bit); if (port == 'D') PORTD &= ~(1<<bit); } }
int get_bit(unsigned int bit, unsigned char port)
{ if (port == 'B') return 1 & (PINB>>bit); if (port == 'C') return 1 & (PINC>>bit); if (port == 'D') return 1 & (PIND>>bit); return -1; }
int main(void)
{ //Setup config(2,'C',1); config(4,'C',1);
put_bit(2,'C',1); put_bit(4,'C',1);
while (1); return 0; }