« SE3 PSE Binome2023-7 » : différence entre les versions

De projets-se.plil.fr
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Ligne 56 : Ligne 56 :
     config(2,'C',1);
     config(2,'C',1);
     config(4,'C',1);
     config(4,'C',1);
     put_bit(2,'C',1);
     put_bit(2,'C',1);
     put_bit(4,'C',1);
     put_bit(4,'C',1);
     while (1);
     while (1);
     return 0;
     return 0;
  }
  }

Version du 11 mars 2024 à 17:00

Manette

Photos

Photo du PCB
Photo de la Schématique

Fichier:SE3-pad.zip

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;
}