avr控制應用與實務 - isu.edu.t · i-shou university 8 1-1 avr簡介 ‧atmel...
TRANSCRIPT
-
AVR
ATmega8515C
-
I-Shou University 2
0
A V RCode VisionAVR C CompilerAVRStudio Code VisionAVR C Compiler AVR Code Vision AVRfunction
ATmega8515 I/O PORTATmega8515 ATmega8515Watchdog Timer ATmega8515UART ATmega8515 SPI
-
0
-
I-Shou University 4
(SOC) IC
I/OCPUI/C PORT
A/DD/A
-
I-Shou University 5
8051IntelMCS-518BitCISC 40pin
PICMicrochipRISC
AVRRISCI/O8051XBOX
-
AVR
-
I-Shou University 8
1-1 AVR
ATMEL AVR8051AVR805124
AVRATMEL/AVR
ATMELhttp://www.atmel.com/
-
I-Shou University 9
1-1 AVR
IC Von Neuman(I/O)
Harvard
AVRCPUHarvard
-
I-Shou University 10
1-1 AVR
CISCRISC
CISCComplex Instruction Set ComputerMemoryCPU
RISCReduced Instruction Set ComputingCPU
-
I-Shou University 11
1-1 AVR
AVRICFLASHEEPROMRAM
FLASH8Kbyte
EEPROM512byte
RAM600byte
-
I-Shou University 12
1-2 AVR
20MHz50ns
CMOSuA~2.5mA
Flash ROM1000
I/O10~20mA
-
I-Shou University 13
1-2 AVR
Lock Bit
ISP JTAGICJTAG
10EEPROM
AVR 1650nS
32128~512SRAM
-
I-Shou University 14
1-2 AVR
CC
bit/16bit/ PWM
-
I-Shou University 15
1-3 AVRAT90S
AT90SRISC8-16bit
ROM
Masked ROMEEPROMFlash Memory- Masked ROM
- EEPROM
- Flash Memory
-
I-Shou University 16
1-3 AVRAT90S
AT90SCRC DES
AVR 8-Bit RISC8-Kbyte544 Byte64K byte SRAM 512 Byte EEPROM8MHz 8 MIPS35ATmega8515AT90S8515ATmega8515AT90S851516MHz 16 MIPS
AT90S8515
-
I-Shou University 17
1-4 ATmega8515
ATmega8515AT90S8515ATmega8515AT90S8515ATmega8515Program Fuse Bit(s)
-
I-Shou University 18
1-4-1 ATmega8515 Datasheets
ATmega851588 I / O 3.2
ATmega8515402018199ABCDEI/O PORT
-
I-Shou University 19
1-4-1 ATmega8515 Datasheets
ATmega8515
AVR -
AVR - 130CLOCK- 328- - 11600- 2
-
I-Shou University 20
1-4-1 ATmega8515 Datasheets
- 8K8000/10
- - - True Read-While-Write Operation - 512EEPROM/10- 512SRAM- 64K-
-
I-Shou University 21
1-4-1 ATmega8515 Datasheets
- 18- 116
- - - - (USART)- / (SPI)
-
I-Shou University 22
1-4-1 ATmega8515 Datasheets
- - RC- -
/- 35/- 40PDIP44PLCC TQFP44
MLF
-
I-Shou University 23
1-4-1 ATmega8515 Datasheets
PDIP PLCC TQFP MLF
-
I-Shou University 24
1-4-1 ATmega8515 Datasheets
()- ATmega8515L2.7 - 5.5V- ATmega85154.5 - 5.5V
()- ATmega8515L0 - 8MHz- ATmega85150 - 16MHz
-
I-Shou University 25
1-4-2 ATmega8515
ATmega85158CMOSAVRRISC
ATmega8515- 8K512EEPROM512SRAM
- - 35I/O32- /- - USART- - SPI-
-
I-Shou University 26ATmega8515
-
I-Shou University 27ATmega8515 RISC
-
swap(int v[], int k){int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;}
swap: muli $2, $5,4 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31
00000000101000010000000000011000000000000001100000011000001000011000110001100010000000000000000010001100111100100000000000000100101011001111001000000000000000001010110001100010000000000000010000000011111000000000000000001000
Assembler
Compiler
Binary machinelanguageprogram(for MIPS)
Assemblylanguageprogram(for MIPS)
High-levellanguageprogram(in C)
-
Instruction Fetch
Instruction Decode and Register Fetch
Execution, Memory Address Computation, or Branch Completion
Memory Access or R-type instruction completion
Write-back step
INSTRUCTIONS TAKE FROM 3 - 5 CYCLES!
Five Execution Steps
-
Data
Register #
Register #
Register #
PC Address Instruction
Instructionmemory
Registers ALU Address
Data
Datamemory
AddAdd
4
-
Building the Datapath Use multiplexors to stitch them together
Readregister 1
Readregister 2
Writeregister
Writedata
Writedata
Registers ALU
Add
Zero
RegWrite
MemRead
MemWrite
PCSrc
MemtoReg
Readdata 1
Readdata 2
ALU operation4
Signextend
16 32
Instruction ALUresult
Add
ALUresult
Mux
Mux
Mux
ALUSrc
Address
Datamemory
Readdata
Shiftleft 2
4
Readaddress
Instructionmemory
PC
-
2
Code VisionAVR C Compiler
-
I-Shou University 33
Code VisionAVR C CompilerAtmelAVR100
http://www.dontronics.com/cvavr_download.html
-
3
AVRStudio
-
I-Shou University 35
AVRStudio
AVRStudioC
AVRStudioCode VisionAVR C CompilerCode VisionAVR C CompilerAVRStudio
AVRStudioWindow 9x / NT / 2000 / XPAVRAVRStudio
-
I-Shou University 36
AVRStudio
-
4
Code VisionAVR C Compiler
-
I-Shou University 38
Code VisionAVR function
Code VisionAVR CC
Code VisionAVR Code VisionAVR
-
I-Shou University 39
Code VisionAVR
-
5
AVR
-
I-Shou University 41
-
I-Shou University 42
(specification)(schematic design)layout(PCB layout)(mask)(exposure)(development)(rinse)(etching)(drill)
-
I-Shou University 43
EDA
-
I-Shou University 44
(exposure)
-
I-Shou University 45
(development)
-
I-Shou University 46
(etching)
-
I-Shou University 47
-
6 Code VisionAVRfunction
-
I-Shou University 49
Library Function
Library Function#include
#include // ()
#include // ()
-
I-Shou University 50
Standard C Input/Output Functions
stdio.h#include #include #define xtal 4000000L // [Hz] #define baud 9600 //Baud ratevoid main(void) {char k;UBRR=xtal/16/baud-1; //UARTBaud rateUCR=0x18; //UARTRX & TX, , 8
while (1) { k=getchar(); //putchar(k); // };
}
-
I-Shou University 51
Character Type Functions ctype.h
unsigned char isalnum(char c)c1unsigned char isalpha(char c)c1unsigned char isascii(char c)c ASCII1unsigned char iscntrl(char c)c1unsigned char isdigit(char c)c1unsigned char islower(char c)c1unsigned char isprint(char c)c1unsigned char ispunct(char c)c1unsigned char isspace(char c)c1unsigned char isupper(char c)c1unsigned char isxdigit(char c)c1char toascii(char c)cASCIIunsigned char toint(char c)cchar tolower(char c)ccchar toupper(char c)cc
-
I-Shou University 52
Standard Library Functions
stdlib.h int atoi(char *str)long int atol(char *str)void itoa(int n, char *str)nvoid ltoa(long int n, char *str)nvoid ftoa(float n, unsigned char decimals, char *str)n
void ftoe(float n, unsigned char decimals, char *str) n
float atof(char *str)int rand (void)0-32767void srand(int seed)
-
I-Shou University 53
Mathematical Functions
math.h signed char sign(int x)x-101unsigned int abs(int x)xint min(int a, int b)abint max(int a, int b)abunsigned char isqrt(unsigned int x)xfloat fmod(float x, float y)x/yfloat modf(float x, float *ipart)xfloat pow(float x, float y)x**yfloat sin(float x)xsinfloat sinh(float x)xsinhfloat atan(float x)xtan-1
-
I-Shou University 54
Delay Functions
delay.h #include void main(void) {#asm("cli") /* */delay_us(100); /* 100ms *//* ............. */delay_ms(10); /* 10ms */#asm("sei") /* *//* ............. */}
-
I-Shou University 55
LCD Functions
lcd.h#asm.equ __lcd_port=0x15 ; // LCD PORTC #endasm#include // LCD void main(void){lcd_gotoxy(0,0); //lcd_putsf("User"); //while (1); /**/}
-
I-Shou University 56
I2C Bus Functions
I2Ci2c.h/* EEPROM */unsigned char eeprom_read(unsigned char address) {unsigned char data;i2c_start();i2c_write(EEPROM_BUS_ADDRESS);i2c_write(address);i2c_start();i2c_write(EEPROM_BUS_ADDRESS | 1);data=i2c_read(0);i2c_stop();return data;}
-
I-Shou University 57
1 Wire Protocol Functions
CodeVisionAVR
1 Wire1wire.h
#asm.equ __w1_port=0x18 //1 Wire PORTB .equ __w1_bit=2#endasm#include
1 Wire ProtocolProject|Configure|C Compiler
-
I-Shou University 58
SPI Functions
CSPI spi.h
#include // SPI
unsigned char spi(unsigned char data)