Emission Nombre

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//clock frequency of the microcontroller 16MHz)

#define F_CPU 1600000UL

//kind of microcontroller (ATmega 328P)


#define __AVR_ATmega328P__

//include the delay function


#include <util/delay.h>

//include the delay function


#include <avr/io.h>

int Serial_init(){
UCSR0A |= (1 << U2X0);
UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00);
UBRR0H |= 0;
UBRR0L |= 16;
DDRD &= ~(1 <<2);
PORTD |= (1 <<2); // Pullup
DDRD &= ~(1 <<3);
PORTD |= (1 <<3); // Pullup
}

int Serial_send_char(char c) {
while ((UCSR0A & (1 << UDRE0))==0) {}
UDR0=c;
}
char Serial_read_char(void) {
while ((UCSR0A & (1 << RXC0))==0);{}
return UDR0;
}
void Serial_send_nbr (uint16_t valeur) {
int mask=1000;
while(mask!=0)
{
int chiffre = valeur /mask ;
char affiche=chiffre + 0x30;
Serial_send_char (affiche);
valeur -= mask*chiffre ;
mask/=10 ;
}
}

int main (void) {


Serial_init();
for (int i=0;i<1000;i++)
{
Serial_send_nbr (i);
Serial_send_char ('\n');
Serial_send_char ('\r');
_delay_ms(1000);
}
}

You might also like