« SE3 PSE Binome2023-7 » : différence entre les versions
Aller à la navigation
Aller à la recherche
(→Code 1) |
(→Code 1) |
||
Ligne 13 : | Ligne 13 : | ||
#include<stdio.h> | #include<stdio.h> | ||
#include<stdlib.h> | #include<stdlib.h> | ||
void config(unsigned int bit, unsigned char port, unsigned int io) | void config(unsigned int bit, unsigned char port, unsigned int io) | ||
{ | { | ||
Ligne 32 : | Ligne 29 : | ||
} | } | ||
} | } | ||
void put_bit(unsigned int bit, unsigned char port, unsigned int io) | |||
void put_bit(unsigned int bit, unsigned char port, unsigned int io) | |||
{ | { | ||
if (io == 1) | if (io == 1) | ||
Ligne 48 : | Ligne 44 : | ||
} | } | ||
} | } | ||
int get_bit(unsigned int bit, unsigned char port) | |||
int get_bit(unsigned int bit, unsigned char port) | |||
{ | { | ||
if (port == 'B') return 1 & (PINB>>bit); | if (port == 'B') return 1 & (PINB>>bit); | ||
Ligne 56 : | Ligne 51 : | ||
return -1; | return -1; | ||
} | } | ||
int main(void) | |||
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; }