Cours:InfoS2 tdOutput corrige : Différence entre versions
Ligne 84 : | Ligne 84 : | ||
PORTD=(chenillard>>24)&0x00FF; | PORTD=(chenillard>>24)&0x00FF; | ||
_delay_ms(300); | _delay_ms(300); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <source lang=cpp> | ||
+ | #define F_CPU 16000000UL | ||
+ | #include <avr/io.h> | ||
+ | #include <util/delay.h> | ||
+ | uint32_t chenillard=1; | ||
+ | uint8_t max=31; | ||
+ | uint32_t accumulation=0; | ||
+ | uint32_t etatLed; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | DDRA = 0xFF; | ||
+ | DDRJ = 0xFF; | ||
+ | DDRC = 0xFF; | ||
+ | DDRD = 0xFF; | ||
+ | while(1) | ||
+ | { | ||
+ | |||
+ | chenillard = chenillard<<1; | ||
+ | if (chenillard>>max) | ||
+ | { | ||
+ | accumulation=accumulation|uint32_t(1)<<max; | ||
+ | max--; | ||
+ | chenillard=1; | ||
+ | if (max==0) | ||
+ | { | ||
+ | max=31; | ||
+ | chenillard=1; | ||
+ | accumulation=0; | ||
+ | } | ||
+ | } | ||
+ | etatLed=accumulation|chenillard; | ||
+ | PORTA=(etatLed>> 0)&0x00FF; | ||
+ | PORTJ=(etatLed>> 8)&0x00FF; | ||
+ | PORTC=(etatLed>>16)&0x00FF; | ||
+ | PORTD=(etatLed>>24)&0x00FF; | ||
+ | _delay_ms(30); | ||
} | } | ||
} | } | ||
</source> | </source> |
Version du 31 janvier 2023 à 17:21
Il s’agit d’une page protégée.
Chenillard(s)
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
uint32_t chenillard=1;
int8_t sens=1;
int main()
{
DDRA = 0xFF;
DDRJ = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
while(1)
{
if (sens==1)
{
chenillard <<=1;
if (chenillard==0x80000000) sens=-1;
}
else
{
chenillard >>=1;
if (chenillard==1) sens=1;
}
PORTA=(chenillard>> 0)&0x00FF;
PORTJ=(chenillard>> 8)&0x00FF;
PORTC=(chenillard>>16)&0x00FF;
PORTD=(chenillard>>24)&0x00FF;
_delay_ms(30);
}
}
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
uint32_t chenillard=0;
uint32_t chenillard1=0;
uint32_t chenillard2=0;
int main()
{
DDRA = 0xFF;
DDRJ = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
while(1)
{
chenillard1 <<=1;
chenillard2 >>=1;
if (chenillard1==0) chenillard1=1;
if (chenillard2==0) chenillard2=0x80000000;
chenillard = chenillard1 | chenillard2;
PORTA=(chenillard>> 0)&0x00FF;
PORTJ=(chenillard>> 8)&0x00FF;
PORTC=(chenillard>>16)&0x00FF;
PORTD=(chenillard>>24)&0x00FF;
_delay_ms(30);
}
}
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
uint32_t chenillard=0b101010;
int main()
{
DDRA = 0xFF;
DDRJ = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
while(1)
{
chenillard = (chenillard<<1) | (chenillard>>31);
PORTA=(chenillard>> 0)&0x00FF;
PORTJ=(chenillard>> 8)&0x00FF;
PORTC=(chenillard>>16)&0x00FF;
PORTD=(chenillard>>24)&0x00FF;
_delay_ms(300);
}
}
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
uint32_t chenillard=1;
uint8_t max=31;
uint32_t accumulation=0;
uint32_t etatLed;
int main()
{
DDRA = 0xFF;
DDRJ = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
while(1)
{
chenillard = chenillard<<1;
if (chenillard>>max)
{
accumulation=accumulation|uint32_t(1)<<max;
max--;
chenillard=1;
if (max==0)
{
max=31;
chenillard=1;
accumulation=0;
}
}
etatLed=accumulation|chenillard;
PORTA=(etatLed>> 0)&0x00FF;
PORTJ=(etatLed>> 8)&0x00FF;
PORTC=(etatLed>>16)&0x00FF;
PORTD=(etatLed>>24)&0x00FF;
_delay_ms(30);
}
}