Lab 1: Introduction
description
Transcript of Lab 1: Introduction
![Page 1: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/1.jpg)
1
Lab 1: Introduction
![Page 2: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/2.jpg)
2
Lab1: Introduction• Configure ATMEL AVR Starter Kit 500 (STK500), a
prototyping/development board for Lab1. ATmega16 (4.5 -5.5 V) is the chip used on your board. Some may have ATmega16L (low voltage 2.7 – 5.5 V) .– Lab1 requires
• One UART port for programming, COM1• One UART port for communication, COM2• Connect a 6-wire cable between Target ISP Header and 6-
pin ISP Header.• Connect a 10-wire cable between Port and LEDs
• Become familiar with the C-compiler from CodeVision.– Lab1 requires writing 3 simple C programs to activate LEDs in
different patterns.– Lab1 requires writing 1 simple C program to talk to a terminal.
![Page 3: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/3.jpg)
3
AVR STK 500 Components
Atmeg16
Atmeg8515
![Page 4: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/4.jpg)
4
![Page 5: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/5.jpg)
5
COM1
To PC COM2 portor other available COM port
COM port connections:COM1 for programming your code onto AVRCOM2 for communication to display your program output
![Page 6: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/6.jpg)
6
Programming
Connecting LEDs and PORTB
Connecting Switches to PORTD
![Page 7: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/7.jpg)
7
RS232 connecting to PORTDRXD PD0TXD PD1
![Page 8: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/8.jpg)
8
Lab1: Introduction
• Pre-lab Assignments– Read Chapter 1 of the textbook: Embedded C
Programming and the Atmel AVR by Barnett, Cox, & O’Cull (BCO).
– Read STK500 user guide– Complete the Pre-lab Questions on page 1-4.
![Page 9: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/9.jpg)
9
Pre-Lab Questions for Lab 1
• When setting up a timer to generate an interrupt every half second, what value must the timer be initialized to (if counting down)?
• What is the clock frequency of the AVR mcu on the STK500 when shipped?
• On the average, how many clock cycles are required per instruction?
• Using your answers from questions 2) and 3) above, how long does a typical instruction take to run on the AVR mcu?
• Write pseudo c-code to toggle every other light to blink every ¼ of a second. Example: 01010101 -> 10101010 -> 01010101 ->…
![Page 10: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/10.jpg)
10
In-Lab Tasks
• Program 1 called led.c; almost a duplication of a program in the tutorial “Getting Started with the CodeVision AVR C Compiler.”
• Program 2 called led2.c; different patterns of LEDs
• Program 3 called led3.c; different patterns of LEDs and different delay
• Program 4 called HelloWorld.c; program COM2 to display program output on a terminal
![Page 11: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/11.jpg)
11
CodeVision Wizard
![Page 12: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/12.jpg)
12
CodeVision Wizard
Select the chip on your board
Select the right frequency
![Page 13: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/13.jpg)
13
CodeVision Wizard
Set Port A as Output Port
Need to set Ports as input orOutput depending on your programs
![Page 14: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/14.jpg)
14
CodeVision Wizard
Set USART parametersBaud rate, Data, Stop bitParity.
![Page 15: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/15.jpg)
15
Set the timer parameters
CodeVision Wizard
![Page 16: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/16.jpg)
16
CodeVision Wizard
CodeVision Wizardgenerates C code according tospecifications you selected, i.e.,I/O Ports, Timer, UART parametersetc.
![Page 17: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/17.jpg)
17
CodeVision Wizard#include <mega16.h>
// LED's are on PORTBunsigned char ledStatus = 0xFE;
// Timer 1 overflow interrupt service routineinterrupt [TIM1_OVF] void timer1_ovf_isr(void){// Reinitialize Timer 1 valueTCNT1H=0xF8;TCNT1L=0xFB;// Place your code here. . . . . .. . . . . .
}
![Page 18: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/18.jpg)
18
CodeVision Wizard// Declare your global variables here
void main(void){// Declare your local variables here
// Input/Output Ports initialization// Port A initialization// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTA=0x00;DDRA=0x00;
// Port B initialization// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out
Func7=Out // State0=1 State1=1 State2=1 State3=1 State4=1 State5=1 State6=1 State7=1 PORTB=0xFF;DDRB=0xFF;
![Page 19: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/19.jpg)
19
CodeVision Wizard// Port C initialization// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTC=0x00;DDRC=0x00;
// Port D initialization// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTD=0x00;DDRD=0x00;
// Timer/Counter 0 initialization// Clock source: System Clock// Clock value: Timer 0 StoppedTCCR0=0x00;TCNT0=0x00;
![Page 20: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/20.jpg)
20
CodeVision Wizard// Timer/Counter 1 initialization// Clock source: System Clock// Clock value: 3.594 kHz// Mode: Normal top=FFFFh// OC1A output: Discon.// OC1B output: Discon.// Noise Canceler: Off// Input Capture on Falling EdgeTCCR1A=0x00;TCCR1B=0x05;TCNT1H=0xF8;TCNT1L=0xFB;OCR1AH=0x00;OCR1AL=0x00;OCR1BH=0x00;OCR1BL=0x00;
![Page 21: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/21.jpg)
21
CodeVision Wizard// Timer/Counter 2 initialization// Clock source: System Clock// Clock value: Timer 2 Stopped// Mode: Normal top=FFh// OC2 output: DisconnectedTCCR2=0x00;ASSR=0x00;TCNT2=0x00;OCR2=0x00;
// External Interrupt(s) initialization// INT0: Off// INT1: OffGIMSK=0x00;MCUCR=0x00;
![Page 22: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/22.jpg)
22
CodeVision Wizard// Timer(s)/Counter(s) Interrupt(s) initializationTIMSK=0x04;
// Analog Comparator initialization// Analog Comparator: Off// Analog Comparator Input Capture by Timer/Counter 1: Off// Analog Comparator Output: OffACSR=0x80;
// Global enable interrupts#asm("sei")
while (1) { // Place your code here
};}
![Page 23: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/23.jpg)
CodeVision Wizard
23
from a student’s Lab1 Report
Results and Discussion:1.Following the “Getting Started” instructions as closely as possible actually worked as advertised and resulted in the AVR flashing the LEDs in order. I was pleased with how straight forward the process was and experimented some with changing the interrupt time and the order of the flashing lights.2.…
![Page 24: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/24.jpg)
24
Lab 1: Introduction• led.c; led2.c; led3.c;
– Different delays can be implemented by including delay.h; or you can write your own subroutine.
#include <delay.h> // delay_ms(125)• HelloWorld.c
– Needs I/O functions, the Wizard will add #include <stdio.h> into the generated C program after
specifying UART parameters.#include <mega16.h>
// Standard Input/Output functions#include <stdio.h>
![Page 25: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/25.jpg)
25
#include <mega16.h>#include <delay.h>// Standard Input/Output functions#include <stdio.h>void main(void){ …………………………….// UART initialization// Communication Parameters: 8 Data, 1 Stop, No Parity// UART Receiver: On// UART Transmitter: On// UART Baud rate: 9600UCR=0x18;UBRR=0x17;while (1){// Place your code heredelay_ms(500); //Use delay function to generate ½ second interval.printf(“Hello World “); //Output “Hello World”.};}
Part of HelloWorld.c
![Page 26: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/26.jpg)
26
Lab Report Format
1. Cover page (include date due, date turned in)2. Prelab questions and answers (typed)3. Summary of the lab tasks4. In-lab tasks, questions and solutions including software
and hardware 5. Results and Discussion6. Code listing for each task
All lab report should be typed and turned in a hard copy on time
![Page 27: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/27.jpg)
27
Check Out Sheet Box Number: Name:Date:
![Page 28: Lab 1: Introduction](https://reader035.fdocuments.us/reader035/viewer/2022070420/56815dfe550346895dcc3c69/html5/thumbnails/28.jpg)
28
In-lab demo (EN 229) Create project Configure peripherals Add C-code Hook up STK500 Compile and build Download and run