ARE - Automatyka, Robotyka, Elektronika - Produkty w naszej ofercie

20090624 Programy dla ATmega16_32.zip

ARE0021_ARE0024 Płytka ewaluacyjna.pdf

// Zmiany względem pliku ARE 2008
PORTD ----> PORDC
DDRA -----> DDRC
char www[16] = ...    ---> char www[17] = ...
char Email [16] = ... ---> char Email [17] = ...
define RS 1  // Do którego pinu płytki podłączono
define RW 2  //  piny LCD
define E 3

obraz.png

/**************************************/
/*              ARE 2008              */
/*      e-mail: [email protected]      */
/*      www   : are.net.pl            */
/**************************************/

#define F_CPU 16000000UL  // 16 MHz
//#define F_CPU 14.7456E6
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <string.h>

void delay_ms(int ms)
	{
	volatile long unsigned int i;
	for(i=0;i<ms;i++)
		_delay_ms(1);
	}
	
void delay_us(int us)
	{
	volatile long unsigned int i;
	for(i=0;i<us;i++)
		_delay_us(1);
	}

//RS PA0
//RW PA1
//E  PA2
//DATA PD

/* To:
  #define RS 0
  #define RW 1
  #define E  2
trzeba zamienić na to: */
#define RS 1
#define RW 2
#define E  3

void LCD2x16_init(void)
{
PORTC &= ~(1<<RS);
PORTC &= ~(1<<RW);

PORTC |= (1<<E);
PORTD = 0x38;   // dwie linie, 5x7 punktow
PORTC &=~(1<<E);
_delay_us(120);

PORTC |= (1<<E);
PORTD = 0x0e;   // wlacz wyswietlacz, kursor, miganie
PORTC &=~(1<<E);
_delay_us(120);

PORTC |= (1<<E);
PORTD = 0x06;
PORTC &=~(1<<E);
_delay_us(120);
}

void LCD2x16_clear(void){
PORTC &= ~(1<<RS);
PORTC &= ~(1<<RW);

PORTC |= (1<<E);
PORTD = 0x01;
PORTC &=~(1<<E);
delay_ms(120);
}

void LCD2x16_putchar(int data)
{
PORTC |= (1<<RS);
PORTC &= ~(1<<RW);

PORTC |= (1<<E);
PORTD = data;
PORTC &=~(1<<E);
_delay_us(120);
}

void LCD2x16_pos(int wiersz, int kolumna)
{
PORTC &= ~(1<<RS);
PORTC &= ~(1<<RW);

PORTC |= (1<<E);
delay_ms(1);
PORTD = 0x80+(wiersz-1)*0x40+(kolumna-1);
delay_ms(1);
PORTC &=~(1<<E);
_delay_us(120);
}

int main(void){
char www[17] = "www-> are.net.pl";
char email[17] = "[email protected]";
char tmp[16];

int i;
int j=4;

DDRD = 0xff;
PORTD = 0x00;
DDRC = 0xff;
PORTC = 0x00;

_delay_ms(200);

LCD2x16_init();
LCD2x16_clear();

    for(i=0;i < 16;i++)
		LCD2x16_putchar(www[i]);
	LCD2x16_pos(2,1);
	for(i=0;i < 16;i++)
		LCD2x16_putchar(email[i]);

delay_ms(3000);
LCD2x16_clear();
for(i=0;i < 16;i++)
	LCD2x16_putchar(www[i]);

while(1)
	{
	//LCD2x16_clear();
	LCD2x16_pos(2,1);
	sprintf(tmp,"Dzialam juz %2is ",j);
	j++;
	for(i=0;i < 16;i++)
		LCD2x16_putchar(tmp[i]);
	delay_ms(1000);   
	}

return 0;
}

ATMega16-Pin-Diagram.png

F2CZ4TULEH47RIM.png