WinAVR Windows 10 Error Compile

Copy this file:

madwizard.org/download/electronics/msys-1.0-vista64.zip

to utils\bin directory (WinAVR)

 

Sumber: http://www.avrfreaks.net/forum/windows-81-compilation-error?page=all

Keypad 3×4 ATMega Atmel Studio

file .c

#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include "keypad_lib.h"

char read_keypad()
{
	DDR_keypad = 0b00001111;
	/* 1 2 3
	   4 5 6
	   7 8 9
	   * 0 #
	*/
	
	PORT_keypad = 0b11111110;
	//scan baris 1
	if(PIN_keypad == 0b11101110)
	{
		return ('1');	
	}
	else if(PIN_keypad == 0b11011110)
	{
		return ('2');
	}
	else if(PIN_keypad == 0b10111110)
	{
		return ('3');
	}
	
	//scan baris 2	
	PORT_keypad = 0b11111101;
	if(PIN_keypad == 0b11101101)
	{
		return ('4');
	}
	else if(PIN_keypad == 0b11011101)
	{
		return ('5');
	}
	else if(PIN_keypad == 0b10111101)
	{
		return ('6');
	}
	
	//scan baris 3
	PORT_keypad = 0b11111011;
	if(PIN_keypad == 0b11101011)
	{
		return ('7');
	}
	else if(PIN_keypad == 0b11011011)
	{
		return ('8');
	}
	else if(PIN_keypad == 0b10111011)
	{
		return ('9');
	}
	
	//scan baris 4
	PORT_keypad = 0b11110111;
	if(PIN_keypad == 0b11100111)
	{
		return ('*');
	}
	else if(PIN_keypad == 0b11010111)
	{
		return ('0');
	}
	else if(PIN_keypad == 0b10110111)
	{
		return ('#');
	}
	return ('$');
}

file .h

#ifndef KEYPAD_LIB_H_
#define KEYPAD_LIB_H_

#include <inttypes.h>
#include <avr/pgmspace.h>

#define PORT_keypad PORTB
#define PIN_keypad PINB
#define DDR_keypad DDRB

extern char read_keypad();

#endif /* KEYPAD_LIB_H_ */

I2C ATMega Atmel Studio

file .c

#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <compat/twi.h>
#include "i2c_lib.h"

void I2C_Init(void)
{
	//set SCL to 400kHz
	TWSR = 0x00;
	TWBR = 0x0C;
	//enable TWI
	TWCR = (1<<TWEN);
}

void I2C_Start(void)
{
	TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
	while ((TWCR & (1<<TWINT)) == 0);
}

//send stop signal
void I2C_Stop(void)
{
	TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
}

void I2C_Write(uint8_t u8data)
{
	TWDR = u8data;
	TWCR = (1<<TWINT)|(1<<TWEN);
	while ((TWCR & (1<<TWINT)) == 0);
}

uint8_t I2C_ReadACK(void)
{
	TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
	while ((TWCR & (1<<TWINT)) == 0);
	return TWDR;
}

//read byte with NACK
uint8_t I2C_ReadNACK(void)
{
	TWCR = (1<<TWINT)|(1<<TWEN);
	while ((TWCR & (1<<TWINT)) == 0);
	return TWDR;
}

uint8_t I2C_GetStatus(void)
{
	uint8_t status;
	//mask status
	status = TWSR & 0xF8;
	return status;
}

file .h

#ifndef I2C_LIB_H_
#define I2C_LIB_H_

extern void I2C_Init(void);

extern void I2C_Start(void);

//send stop signal
extern void I2C_Stop(void);

extern void I2C_Write(uint8_t u8data);

extern uint8_t I2C_ReadACK(void);

//read byte with NACK
extern uint8_t I2C_ReadNACK(void);

extern uint8_t I2C_GetStatus(void);

#endif /* I2C_LIB_H_ */

Setting New Project Atmel Studio

Berikut setting Atmel Studio untuk xtal, float LCD,& Optimization


Tambahkan pada main program
atmel_set1
Klik kanan pada Solution Explorer Nama Project -> Properties
atmel_set2
Add symbol nilai xtal
atmel_set3
atmel_set4
Optimization Level jadi -Os
atmel_set5
Centang Use vprintf library
atmel_set6
Isi other linker flags
atmel_set7

UART Interrupt ATMega128 Atmel Studio

#ifndef F_CPU
#define F_CPU 11059200UL // or whatever may be your frequency
#endif

#include <avr/io.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdio.h>

#ifndef UPE
#define UPE 2
#endif

#ifndef DOR
#define DOR 3
#endif

#ifndef FE
#define FE 4
#endif

#ifndef UDRE
#define UDRE 5
#endif

#ifndef RXC
#define RXC 7
#endif

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 32
char rx_buffer0[RX_BUFFER_SIZE0];

#if RX_BUFFER_SIZE0 <= 256
unsigned char rx_wr_index0,rx_rd_index0,rx_counter0;
#else
unsigned int rx_wr_index0,rx_rd_index0,rx_counter0;
#endif

// This flag is set on USART0 Receiver buffer overflow
uint8_t rx_buffer_overflow0;

// USART0 Receiver interrupt service routine
ISR(USART0_RX_vect)
{
	char status,data;
	status=UCSR0A;
	data=UDR0;
	if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
	{
		rx_buffer0[rx_wr_index0++]=data;
		#if RX_BUFFER_SIZE0 == 256
		// special case for receiver buffer size=256
		if (++rx_counter0 == 0) rx_buffer_overflow0=1;
		#else
		if (rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
		if (++rx_counter0 == RX_BUFFER_SIZE0)
		{
			rx_counter0=0;
			rx_buffer_overflow0=1;
		}
		#endif
	}
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char _getchar(void)
{
	uint8_t counter1 = 0,
			counter2 = 0,
			counter3 = 0;
	char data;
	uint8_t cc;
	while(rx_counter0==0)
	{
		_delay_us(0);
	};
	data=rx_buffer0[rx_rd_index0++];
	#if RX_BUFFER_SIZE0 != 256
	if (rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
	#endif
	cli();
	--rx_counter0;
	sei();
	return data;
}
#pragma used-
#endif

// USART0 Transmitter buffer
#define TX_BUFFER_SIZE0 32
char tx_buffer0[TX_BUFFER_SIZE0];

#if TX_BUFFER_SIZE0 <= 256
unsigned char tx_wr_index0,tx_rd_index0,tx_counter0;
#else
unsigned int tx_wr_index0,tx_rd_index0,tx_counter0;
#endif

// USART0 Transmitter interrupt service routine
ISR(USART0_TX_vect)
{
	if (tx_counter0)
	{
		--tx_counter0;
		UDR0=tx_buffer0[tx_rd_index0++];
		#if TX_BUFFER_SIZE0 != 256
		if (tx_rd_index0 == TX_BUFFER_SIZE0) tx_rd_index0=0;
		#endif
	}
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART0 Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void _putchar(char c)
{
	while (tx_counter0 == TX_BUFFER_SIZE0)
	{
		_delay_us(0);
	};
	cli();
	if (tx_counter0 || ((UCSR0A & DATA_REGISTER_EMPTY)==0))
	{
		tx_buffer0[tx_wr_index0++]=c;
		#if TX_BUFFER_SIZE0 != 256
		if (tx_wr_index0 == TX_BUFFER_SIZE0) tx_wr_index0=0;
		#endif
		++tx_counter0;
	}
	else
	UDR0=c;
	sei();
}
#pragma used-
#endif

// USART1 Receiver buffer
#define RX_BUFFER_SIZE1 32
char rx_buffer1[RX_BUFFER_SIZE1];

#if RX_BUFFER_SIZE1 <= 256
unsigned char rx_wr_index1,rx_rd_index1,rx_counter1;
#else
unsigned int rx_wr_index1,rx_rd_index1,rx_counter1;
#endif

// This flag is set on USART1 Receiver buffer overflow
uint8_t rx_buffer_overflow1;

// USART1 Receiver interrupt service routine
ISR(USART1_RX_vect)
{
	char status,data;
	status=UCSR1A;
	data=UDR1;
	if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
	{
		rx_buffer1[rx_wr_index1++]=data;
		#if RX_BUFFER_SIZE1 == 256
		// special case for receiver buffer size=256
		if (++rx_counter1 == 0) rx_buffer_overflow1=1;
		#else
		if (rx_wr_index1 == RX_BUFFER_SIZE1) rx_wr_index1=0;
		if (++rx_counter1 == RX_BUFFER_SIZE1)
		{
			rx_counter1=0;
			rx_buffer_overflow1=1;
		}
		#endif
	}
}

// Get a character from the USART1 Receiver buffer
#pragma used+
char _getchar1(void)
{
	uint8_t counter1 = 0,
			counter2 = 0,
			counter3 = 0;
	char data;
	while (rx_counter1==0)
	{
		_delay_us(0);	
	};
	data=rx_buffer1[rx_rd_index1++];
	#if RX_BUFFER_SIZE1 != 256
	if (rx_rd_index1 == RX_BUFFER_SIZE1) rx_rd_index1=0;
	#endif
	cli();
	--rx_counter1;
	sei();
	return data;
}
#pragma used-
// USART1 Transmitter buffer
#define TX_BUFFER_SIZE1 32
char tx_buffer1[TX_BUFFER_SIZE1];

#if TX_BUFFER_SIZE1 <= 256
unsigned char tx_wr_index1,tx_rd_index1,tx_counter1;
#else
unsigned int tx_wr_index1,tx_rd_index1,tx_counter1;
#endif

// USART1 Transmitter interrupt service routine
ISR(USART1_TX_vect)
{
	if (tx_counter1)
	{
		--tx_counter1;
		UDR1=tx_buffer1[tx_rd_index1++];
		#if TX_BUFFER_SIZE1 != 256
		if (tx_rd_index1 == TX_BUFFER_SIZE1) tx_rd_index1=0;
		#endif
	}
}

// Write a character to the USART1 Transmitter buffer
#pragma used+
void _putchar1(char c)
{
	while (tx_counter1 == TX_BUFFER_SIZE1)
	{
		_delay_us(0);
	};
	cli();
	if (tx_counter1 || ((UCSR1A & DATA_REGISTER_EMPTY)==0))
	{
		tx_buffer1[tx_wr_index1++]=c;
		#if TX_BUFFER_SIZE1 != 256
		if (tx_wr_index1 == TX_BUFFER_SIZE1) tx_wr_index1=0;
		#endif
		++tx_counter1;
	}
	else
	UDR1=c;
	sei();
}
#pragma used-

main program

int main(void)
{
	char buffer = 0;
	// USART0 initialization
	// Communication Parameters: 8 Data, 1 Stop, No Parity
	// USART0 Receiver: On
	// USART0 Transmitter: On
	// USART0 Mode: Asynchronous
	// USART0 Baud Rate: 9600
	UCSR0A=0x00;
	UCSR0B=0xD8;
	UCSR0C=0x06;
	UBRR0H=0x00;
	UBRR0L=0x47;

	// USART1 initialization
	// Communication Parameters: 8 Data, 1 Stop, No Parity
	// USART1 Receiver: On
	// USART1 Transmitter: On
	// USART1 Mode: Asynchronous
	// USART1 Baud Rate: 9600
	UCSR1A=0x00;
	UCSR1B=0xD8;
	UCSR1C=0x06;
	UBRR1H=0x00;
	UBRR1L=0x47;

	// Analog Comparator initialization
	// Analog Comparator: Off
	// Analog Comparator Input Capture by Timer/Counter 1: Off
	ACSR=0x80;
	SFIOR=0x00;

	sei();
    while(1)
    {
        //TODO:: Please write your application code 
		buffer = _getchar();
		_putchar(buffer);
    }
}