Uživatel:Septaher

Z MAM wiki

Přejít na: navigace, hledání

This is my first page, Enjoy Microprocssor and Microcomputer Course!

Today (23/02/2012) we do some simple project with AVR Dragon Downloader Board and ATtiny 2313.

You can read some instruction for this experiment provide by the teacher on this link http://noel.feld.cvut.cz/vyu/a2m99mam/index.php/First_AVR_experiment

But here I wrote some step regarding this experiment that I have done.

Obsah

[editovat] AVR Dragon Board

The AVR Dragon sets a new standard for low cost development tools for 8-bit and 32-bit AVR devices with On Chip Debug (OCD) capability. It can perform a symbolic debug on all devices with OCD with SPI, JTAG, PDI (selected devices), high voltage serial programming, parallel programming, and aWire modes, and supports debugging using SPI, JTAG, PDI interfaces.

A development area lets designers build their own circuitry or add sockets for the desired device footprint. The debugger also supports NanoTrace, depending on the OCD module on the AVR devic, using the target device's memory.

You can read some information about this board from Atmel :

[editovat] ATtiny2313 Microcontroller

Picture below are ATtiny 2313 Pin Configuration.

Soubor:ATtiny2313.png

ATtiny 2313 are 8-bit Microcontroller with 2K Bytes In-System Programmable Flash from ATMEL.

The ATtiny2313 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny2313 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.

You can read the User Manual from Atmel here http://www.atmel.com/dyn/resources/prod_documents/doc2543S.pdf

That User Manual provide detail about ATtiny 2313 resources (Features, Pin Configuration, Block Diagram, Instruction Set, Packaging and etc)

[editovat] AVR Studio 4

The AVR Studio 4 is an Integrated Development Environment for debugging AVR software. The AVR Studio allows chip simulation and in-circuit emulation for the AVR family of microcontrollers. The user interface is specially designed to be easy to use and to give complete information overview. The AVR uses the same user interface for both simulation and emulation providing a fast learning curve.

Soubor:avrstudio4.png

You can find some usefull tutorial here :

Or you want to upgrade with new version AVR Studio 5

[editovat] Excercise 1 Blinking LED Experiment 23/02/2012

Today Experiment goal was made an Blinking LED with AVR Dragon Downloader Board and ATtiny 2313. Software that we used were AVR Studio 4.


Blinking LED Simulation with AVR Studio 4


1. Install your AVR Studio 4 and run the program

2. Create New Project, give the file name and klik next.

3. Select debug platform "AVR Simulator 2" and device ATtiny2313 and klik Finish

4. Used this code on your project :

	.EQU DDRB = $17		; DDRB address
	.EQU PORTB = $18	; PORTB address

	.EQU LED_X = 0		; LED_X is on PB0, pin 12 of ATtiny2313

; Pins connected to LED are outputs, DDRx=1 (set):

	SBI	DDRB, LED_X	; SBI - Set Bit in I/O Register
HOP:
	SBI	PORTB, LED_X
	CBI	PORTB, LED_X
	RJMP HOP

5. Build the Project, if there is no error klik Build and Run

6. Klik on the Port B

7. Klik Next step to see there is some bit change on the Port B


Blinking LED on real device AVR Studio 4 + ATtiny2313 + AVR Dragon



1. We need some another tools or material to make the electronic connection

2. Beside AVR Dragon KIT and ATtiny2313 we need Project Board, Resistor, LED, and cable.

3. Made electronic connection on project board to connect the LED, resistor, ATtiny2313,you can use this picture as guidelines

  Soubor:Avr-blink1.png‎

4. Then make connection between the them into the AVR Dragon kit, you can use this picture as guidelines

  Soubor:DW-Dragon-ATtiny2313.png

5. Connect the AVR Dragon to your computer with the interface, the red and green light must present

6. Run AVR Studio 4, make a New Project

7. Select debug platform "AVR Dragon" and device ATtiny2313 and klik Finish

8. Used this code on your project :

	.EQU DDRB = $17		; DDRB address
	.EQU PORTB = $18	; PORTB address

	.EQU LED_X = 0		; LED_X is on PB0, pin 12 of ATtiny2313

; Pins connected to LED are outputs, DDRx=1 (set):

	SBI	DDRB, LED_X	; SBI - Set Bit in I/O Register
HOP:
	SBI	PORTB, LED_X
        RCALL   WAIT
	CBI	PORTB, LED_X
        RCALL   WAIT
	RJMP HOP

WAIT:
	LDI	R16, 4			; LDI - Load Immediate
WAIT1:	INC	R1
	BRNE	WAIT1
	INC	R2
	BRNE	WAIT1
	DEC	R16
	BRNE	WAIT1
	RET

9. Build the Project, if there is no error klik Build and Run

  Soubor:Avr-blink2.png‎

10. See your LED, it must blinking now.

   Soubor:Blink_led.jpg‎ ‎


[editovat] Excercise 2 Color Change LED Experiment using Button 01/03/2012

Today we have done some experiment still using LED Circuit, ATtiny2313, AVR Dragon and also AVR Studio 4.

Color Change LED Simulation with AVR Studio 4


1. Run AVR Studio 4

2. Create New Project, give the file name and klik next.

3. Select debug platform "AVR Simulator 2" and device ATtiny2313 and klik Finish

4. This project still using previous LED electronic circuit with some added feature, the button.

5. Goal of this experiment are using the button to made some switching on the program to switch which of the LED are turned "ON" or "OFF"

6. Good way to test input is to read PINx via SBIS or SBIC instruction.

7. SBIS instruction tests a single bit in an I/O Register and skips the next instruction if the bit is set.

8. SBIC instruction tests a single bit in an I/O Register and skips the next instruction if the bit is cleared.

9. Use this source code in your work

        .EQU DDRB = $17		; DDRB address
	.EQU PORTB = $18	; PORTB address
	.EQU DDRD = $11		; DDRD address
	.EQU PIND = $10	        ; PORTB address
	.EQU PORTD = $12	; PORTB address

	.EQU LED_X = 0		; LED_X is on PB0, pin 12 of ATtiny2313
	.EQU LED_Y = 0		; LED_Y is on PB1, pin 13 of ATtiny2313
	.EQU BUT = 5		; WHERE BUTTON IS

; Pins connected to LED are outputs, DDRx=1 (set):

	SBI	DDRB, LED_X	; SBI - Set Bit in I/O Register
	SBI	DDRB, LED_Y	; SBI - Set Bit in I/O Register

	CBI DDRD, BUT           ; Input
	SBI PORTD, BUT          ; With Pull-UP Register

HOP :
	
	SBIS PIND, BUT          ; Read the PIND if it set
	RJMP A
	RCALL GREEN
	; ......
	RJMP B

A:
	RCALL RED
	; ......

B:

	RJMP HOP

	RED :
	SBI PORTB, LED_X
	CBI PORTB, LED_Y
	RET

	GREEN :
	SBI PORTB, LED_Y
	CBI PORTB, LED_X
	RET

10. Build the Project, if there is no error klik Build and Run

11. Run some step or shoose autostep

12. Klik on the Port B and Port D and see some bit change

13. Klik at the PIND to simulate when the button is pushed.

14. Again see some different bit change on PINB

Soubor:button.jpg


Color Change LED on real devices with AVR Studio 4


1. Make some LED circuit from our previous lab, read here

2. Read the button configuration on this page

3. Connect the AVR Dragon to your computer within the interface, the red and green light must present

4. Run AVR Studio 4, make a New Project

5. Select debug platform "AVR Dragon" and device ATtiny2313 and klik Finish

6. Use our previous code program.

7. Build and Run

8. Unfortunately I still have some error since the LED not working properly, if I found the problem I will post it again here.


[editovat] Excercise 3 Bit Manipulation 15/03/2012

On this exercise we will do simple bit manipulation to shift the bit to the right or left side.

Soubor:Bit.jpg

Here is the program :

START :
	IN R0, $18
	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	ROR R0
	ROL R1

	;SWAP R0
	OUT $17, R1
	
	RJMP START

Here is the result :

Soubor:Bit2.jpg

[editovat] Excercise 4 Convert C to Assembler 29/03/2012

On this exercise we tried to convert some simple program in C to assembler. Here is the C program :

main () {
int i = 5;
i++;
}

Its very simple program that contain increment function, with AVR GCC we will convert this program into assembler by write this command into command prompt.

command : avr-gcc –S filename.c /convert c file into assembler
cat filename.s  / read the file usány command prompt

The result will be like this :

in Assembler „

	.file	"test.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__CCP__  = 0x34
__tmp_reg__ = 0
__zero_reg__ = 1
	.text
.global	main
	.type	main, @function
main:
	push r29
	push r28
	rcall .
	rcall .
	in r28,__SP_L__
	in r29,__SP_H__
/* prologue: function */
/* frame size = 4 */
	ldi r24,lo8(5)  /store 5 (32) bit into 16 bit (first 8 bit)
	ldi r25,hi8(5)  / another 8 bit
/* X,Y,Z: Indirect Address Register (X=R27:R26, 
Y=R29:R28 and Z=R31:R30)*/

std Y+2,r25	    /Store from r25 to memory
	std Y+1,r24     /Store from r24 to memory
	ldd r24,Y+1	    /Load from memory to r25
	ldd r25,Y+2     /Load from memory to r24
	adiw r24,1     /add immediate word, increment by 1
	std Y+2,r25    /Store from r25 to memory
	std Y+1,r24    /Store from r24 to memory

/* epilogue start */
	pop __tmp_reg__
	pop __tmp_reg__
	pop __tmp_reg__
	pop __tmp_reg__
	pop r28
	pop r29
	ret
	.size	main, .-main

Soubor:Ctoasm.jpg


[editovat] SEMESTER PROJECT - INTERFACING ATMEGA16 WITH LCD

[editovat] Project Goal

My project goal is to make an interfacing between ATMEGA16 and LCD display. After that we used C language to display some letter on the LCD display.

Devices that we needed to built this project :

1. ATMEGA16, we can read the details here ATMEGA16 Datasheet

1. 16column x 2 lines LCD display (LM016L) LM16L datasheet

3. Variable resistor, to adjust the LCD brightness

4. Wires

5. Downloader like AVR Dragon if we built the circuit in real devices


Software that we need are :

1. AVR Studio 6, I used this version since another old version doesn't running well on Windows 7, you may download this version here. Becareful, it contain large data (over 500MB).

2. ISIS 7 Professional, I found this cool software so we can drawing our circuit and also simulating it. Unfortunately, this software was not free :(


Here is the goal of my project :

Soubor:Lcd-atmega16.jpg

[editovat] ATMega 16 PIN

We used port B as the data port output into the dataport in the LCD display and Port D as the communication port connected to the pin RS, RW and EN pin LCD display.


[editovat] LM016L LCD Display

Here it is some usefull information from LM016L LCD Display that we will use in our program.

Soubor:Lm016l.jpg

This LCD consists of 14 pins as show in figure above where the Vdd was used to supply +5V and the Vss terminal was connected to the ground while the VEE was used to control the contrast of the LCD.

The RS pin was used to allow the sending of commands to the LCDwhen it was set to 0/low (RS = 0) and also the sending of data to be shown on the LCD when RS is set to 1/high (RS =1).

The R/W (Read/Write) pin was used to allow the reading of information from the LCD when it set to 1/high (R/W = 1) and when set to 0/low (R/W = 0) allows the writing of information to LCD.

To latch information that is currently at the LCD’s data pins,a high-low pulse was sent to the EN pin. The 8-bit data pins of the LCD are basically used tosend information or read the content of the LCD.

[editovat] C Codes

Here it the C codes that we should build in AVR Studio :

#include<avr/io.h>
#include<util/delay.h>
#include<string.h>

#define dataport PORTB              //define port B ATMEGA16 as dataport
#define commport PORTD             //define port D ATMEGA16 as communication / control port

#define rs PD4                   //define Pin D4 (Pin no.18) ATMEGA16 as RS control
#define wr PD5                  //define Pin D5 (Pin no.19) ATMEGA16 as WR control
#define en PD6                 //define Pin D6 (Pin no.20) ATMEGA16 as EN control

//define the variables and its data type
int LCD_init(void);
int LCD_SendData(unsigned char *);
int wrcomm(void);
int wrdata(void);

int main (void)
{
	DDRB = 0xFF;                        //set Port B as output port
	DDRD = 0x70;                        // set port D pin D4,D5,D6 as output pins
	LCD_init();                         //to initialize LCD
	while (1)
	{
	LCD_SendData("**<AE2M99MAM>**");     // write first lcd line
	dataport = 0xC0;
	wrcomm();
	LCD_SendData("**HERY DIAN S**");   // write second lcd line
	dataport = 0x01;                   // command to clear the lcd
	wrcomm();                         // right the command byte to a command register
	}	
	return 1;
}

////LCD Initialization///
int LCD_init()
{
	dataport=0x38;    // initialize lcd 2 lines, 5x7 matrix
	wrcomm();        // right the command byte to a command register
	dataport = 0x01; // clear the lcd
	wrcomm();         // right the command byte to a command register
	dataport = 0x0E;  //display the blinking cursor
	wrcomm();         // right the command byte to a command register
	dataport = 0x80;  // cursor at line 1, position 1
	wrcomm();         // right the command byte to a command register
	dataport=0x1C;    //shift entire display to right
	wrcomm();         // right the command byte to a command register
	return 1;
}

/////sending data to lcd display////

int LCD_SendData(unsigned char *s)
{
	unsigned char *j=s;
	int i;
	for(i=0;i<strlen(j);i++)
	{
		dataport=j[i];
		wrdata();
	}
	return 1;
}

///righting the command byte to command register///
	int wrcomm(void)
	{
		commport &=~(1 << rs); //setting rs=0; selecting comand register
		commport &=~(1 << wr); //setting wr=0; selecting comand register
		commport |=(1 << en); // EN = 1
		commport &=~(1 <<en); //EN = 0, giving low pulse enable pin
		_delay_ms(10);
		return 1;
	}


///righting the databyte to data register///
	int wrdata(void)
	{
		commport |=(1 << rs); //setting rs=1; selecting command register
		commport &=~(1 << wr); //setting wr=0; selecting command register
		commport |=(1 << en); // EN = 1
		commport &=~(1 <<en); //EN = 0, giving low pulse enable pin
		_delay_ms(300);
		return 1;
	}

[editovat] Simulation with ISIS 7 Professional

With this software we can drawing our circuit faster since this software provide a alot of diagram from it's library. Draw the circuit that connected the ATMEGA16 and LM016L LCD Display. Here its some example of this software result :

Soubor:Isis.jpg

After drawing the circuit now we can load the program in C to control the text shown on the LCD that we made before. Right click on the ATMEGA16 symbol and choose edit preference. The software will open one dialog windows and we can browse the compiled program with .elf or .hex extensions. Look picture below for some hints :

Soubor:Isis2.jpg

After loading the program into the simulator, click on the animation controller menu and our program would simulated on the diagram. Se picture below for the result :

Soubor:Isis3.jpg

Offcourse in full version we can make our selves circuit design and load the program onto the circuit.

The END

Osobní nástroje