Cours:InfoS2 tdInput corrige : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
(Page créée avec « <accesscontrol>Acces:Prof</accesscontrol> <source lang=cpp> // Compiler: Avrgcc device: atmega640 #define F_CPU 16000000UL #include <avr/io.h> #include <util/delay.h> u... »)
 
 
(Une révision intermédiaire par le même utilisateur non affichée)
Ligne 1 : Ligne 1 :
<accesscontrol>Acces:Prof</accesscontrol>
 
 
 
<source lang=cpp>
 
<source lang=cpp>
// Compiler: Avrgcc device: atmega640
+
// Compiler: Avrgcc device: atmega328
 
 
 
#define F_CPU 16000000UL
 
#define F_CPU 16000000UL
 
#include <avr/io.h>
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <util/delay.h>
uint32_t chenillard=1;
 
uint8_t max=31;
 
uint32_t accumulation=0;
 
uint32_t etatLed;
 
 
 
int main()
 
int main()
 
{
 
{
DDRA = 0xFF;
+
// led PD0
DDRJ = 0xFF;
+
DDRD|=(1<<PD0);
DDRC = 0xFF;
+
//colonne 3 en sortie :
DDRD = 0xFF;
+
DDRB  |= (1<<PB2);
 +
// colonne 3 à 0
 +
PORTB &=~(1<<PB2);
 +
//ligne 1 en entrée
 +
DDRC &=~(1<<PC2);
 +
//pull-up sur ligne 1
 +
PORTC |= (1<<PC2);
 
while(1)
 
while(1)
 
{
 
{
chenillard = chenillard<<1;
+
if (bit_is_clear(PINC,PC2))
if ((chenillard>>max)!=0)
 
 
{
 
{
chenillard=1;
+
PORTD|=(1<<PD0);
 +
}
 +
else
 +
{
 +
PORTD&=~(1<<PD0);
 
}
 
}
etatLed=chenillard;
 
PORTA= etatLed;
 
PORTJ= etatLed>> 8;
 
PORTC= etatLed>>16;
 
PORTD= etatLed>>24;
 
_delay_ms(10);
 
 
}
 
}
 
}
 
}
 
</source>
 
</source>

Version actuelle datée du 7 février 2025 à 15:29

// Compiler: Avrgcc device: atmega328
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main()
{
	// led PD0
	DDRD|=(1<<PD0);
	//colonne 3 en sortie :
	DDRB  |= (1<<PB2);
	// colonne 3 à 0
	PORTB &=~(1<<PB2);
	//ligne 1 en entrée
	DDRC &=~(1<<PC2);
	//pull-up sur ligne 1
	PORTC |= (1<<PC2);
	while(1)
	{
		if (bit_is_clear(PINC,PC2))
		{
			PORTD|=(1<<PD0);
		}
		else
		{
			PORTD&=~(1<<PD0);
		}
	}
}