139 lines
3.3 KiB
C
139 lines
3.3 KiB
C
/* ******************************************************** *
|
|
*
|
|
* Simple Template for ATMEL Microcontroller *
|
|
* -------------------------------------------------------- *
|
|
* Created on: 25.07.2016
|
|
* Author: Paolo Iocco
|
|
* ******************************************************** */
|
|
/* ******************************************************** *
|
|
ATtiny 88 / Mega 168 / Mega 328 Pin map
|
|
+-\/-+
|
|
/Reset PC6 1|o |28 PC5 ADC5
|
|
RXD PD0 2| |27 PC4 ADC4
|
|
TXD PD1 3| |26 PC3 ADC3
|
|
PD2 4| |25 PC2 ADC2
|
|
OC2B PD3 5| |24 PC1 ADC1
|
|
PD4 6| |23 PC0 ADC0
|
|
VCC 7| |22 GND
|
|
GND 8| |21 AREF
|
|
OSC1 PB6 9| |20 VCC
|
|
OSC2 PB7 10| |19 PB5 SCK
|
|
OC0B PD5 11| |18 PB4 MISO
|
|
AIN0 OC0A PD6 12| |17 PB3 OC2A MOSI
|
|
AIN1 PD7 13| |16 PB2 OC1B
|
|
PB0 14| |15 PB1 OC1A
|
|
+----+
|
|
* ******************************************************** */
|
|
|
|
#ifndef F_CPU
|
|
#define F_CPU 8000000
|
|
#endif
|
|
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#define BAUD 9600
|
|
#define m168p
|
|
#include <util/setbaud.h>
|
|
|
|
/* Definizioni per il m168p */
|
|
#ifdef m168p
|
|
#define UCSRA UCSR0A
|
|
#define UCSRB UCSR0B
|
|
#define UCSRC UCSR0C
|
|
#define UBRRH UBRR0H
|
|
#define UBRRL UBRR0L
|
|
#define U2X U2X0
|
|
#define UDRE UDRE0
|
|
#define UDR UDR0
|
|
#endif
|
|
/* fine definizioni per il m168p*/
|
|
|
|
/* Inizializza la porta seriale */
|
|
void uart_init(void)
|
|
{
|
|
UBRRH = UBRRH_VALUE;
|
|
UBRRL = UBRRL_VALUE;
|
|
#if USE_2X0
|
|
UCSRA |= (1 << U2X);
|
|
#else
|
|
UCSRA &= ~(1 << U2X);
|
|
#endif
|
|
|
|
UCSRC= _BV(UCSZ01) | _BV(UCSZ00); // 8 N 1
|
|
UCSRB= (1<<TXEN0);
|
|
// UCSRB= (1<<RXEN0)|(1<<TXEN0);
|
|
}
|
|
|
|
/* uart_putc(): scrive un carattere sulla porta seriale*/
|
|
int uart_putc(unsigned char c)
|
|
{
|
|
while (!(UCSRA & (1<<UDRE))) { /* warten bis Senden moeglich */
|
|
}
|
|
UDR = c; /* sende Zeichen */
|
|
return 0;
|
|
}
|
|
|
|
/* uart_puts(): scrive una stringa sulla porta seriale*/
|
|
void uart_puts (char *s)
|
|
{
|
|
while (*s) {
|
|
uart_putc(*s);
|
|
s++;
|
|
}
|
|
}
|
|
|
|
/* Funzioni oer il display Digole */
|
|
|
|
/* Main - Programma principale*/
|
|
int main (void)
|
|
{
|
|
unsigned char zwischenspeicher;
|
|
DDRC = 0b00000001;
|
|
|
|
uart_init();
|
|
_delay_ms(3000);
|
|
uart_puts("CL");
|
|
uart_puts("DSS");
|
|
uart_putc(0);
|
|
uart_puts("TT* Love Silvia *\n");
|
|
uart_puts("TRT");
|
|
uart_puts("TT* Love Silvia *\n");
|
|
uart_puts("TRT");
|
|
uart_puts("TT* Love Silvia *\n");
|
|
uart_puts("TRT");
|
|
uart_puts("TT* Love Silvia *\n");
|
|
uart_puts("TRT");
|
|
uart_puts("TT* Love Silvia *\n");
|
|
uart_puts("TRT");
|
|
|
|
/*
|
|
uart_puts("SF");
|
|
uart_putc(6);
|
|
uart_puts("TT12345678901234567890123456789012\n");
|
|
|
|
uart_puts("SF");
|
|
uart_putc(10);
|
|
uart_puts("TRT");
|
|
uart_puts("TT123456789012345678901\n");
|
|
|
|
uart_puts("SF");
|
|
uart_putc(0);
|
|
uart_puts("TRT");
|
|
uart_puts("TT1234567890123456\n");
|
|
|
|
uart_puts("SF");
|
|
uart_putc(18);
|
|
uart_puts("TRT");
|
|
uart_puts("TT12345678901234\n");
|
|
*/
|
|
|
|
while(1) {
|
|
zwischenspeicher = PORTC;
|
|
zwischenspeicher = zwischenspeicher ^ 0b00000001;
|
|
PORTC = zwischenspeicher;
|
|
_delay_ms(500);
|
|
}
|
|
return 0;
|
|
}
|
|
|