An object. Microcontroller ATmega16.
Thing. Temperature measurement
Goal. Temperature measurement by contact method.
Tasks. Temperature measurement by a contact method, processing the measurement signal using a microcontroller and outputting the temperature value to a 7-segment display.
Software:
1. Software development environment AVRStudio or AtmelStudio, for developing programs for MK AtmelAVR® (Atmel).
2. Standard Windows application - calculator (Microsoft).
3. Software package for computer-aided design of electronic circuits - Proteus DesignSuite CAD Software (Labcenter electronics).
The work progress provides for the consistent implementation of the recommendations and actions described further in this project point by point.
CONTENT
1. INTRODUCTION
2. HARDWARE IMPLEMENTATION OF THE PROJECT
2.1 Microcontroller ATmega16
2.2 Temperature sensor DS18B20
2.3 Four-digit seven-segment display
2.4 Simulation of the electronic circuit of the project
3. PROGRAM IMPLEMENTATION OF THE PROJECT
3.1 AtmelStudio Development Environment
3.2 Program development
CONCLUSIONS
1. Introduction
Temperature is a physical quantity that is a measure of the intensity of the thermal motion of atoms and molecules.
Contact method for measuring temperature is a method of measuring temperature at thermal contact between the objects of measurement and the sensitive element of the measuring equipment.
- - , , . , . , , , , , .
AVRATmega16.
AVR - Atmel.
AVR , RISC. AVR 32 8- . - 20 , .
Proteus DesignSuite CAD Software (Labcenterelectronics).
2.
AVR ATmega16.
AVR - , Atmel, Microchip.
AVR ( ) , RISC. AVR 32 8- , . «» RISC, .
AVR 90 133 . 1 (16 ). 1 .
. DS18B20. , , , . ; , , . . , - .
4- 7- .
2.1 ATmega16
ATmega16 - 8- AVR
.
:
|
AVRATmega |
|
AVR |
|
8-і |
|
16 |
/ |
32 |
|
16 (8k*16) |
|
Flash |
EEPROM |
512*8 |
SRAM |
1k*8 |
/ |
8*10b |
|
I2C, SPI, UART |
|
Brown-outdetect/reset, POR, PWM, WDT |
|
4.5…5.5 |
|
-40…+85 ºC |
:
RISC
130 ,
32 8-
16 MIPS ( 16 )
2-
1000 / Flash 100000 / EEPROM
/ (Read-While-Write)
,
JTAG ( IEEE 1149.1)
, JTAG
JTAG : Flash, EEPROM ,
16- /
PWM ()
8- 10- -
8- / ,
8
7 ( TQFP)
2 1, 10 200 ( TQFP)
- 2-
USART
SPI ( / )
RC-
: Idle, Power-save, Power-down, Standby, ExtendedStandby ADC
I / O
32 /
40- PDIP 44- TQFP
VCC -.
GND - .
Port A (PA7..PA0) A / D.
Port A 8- / , A / D .
Port B (PB7..PB0) 8- / ( ).
Port B ATmega16.
Port C (PC7..PC0) 8- / ( ).
Port C JTAG ATmega16.
Port D (PD7..PD0) 8- / ( ).
Port D ATmega16.
RESET - . .
XTAL1 - .
XTAL2 - .
AVCC - A A / D . VCC, . , VCC .
AREF- A / D-.
2.2 DS18B20
DS18B20 - , . , DS18B20 - , , ( ), , . , , , .
:
VDD – .
GND – .
DO– .
, , - . , VDD . DS18B20 ATmega16 .
:
|
3,0…5,5 |
|
1,5 ( ) 1 ( ) |
|
-55…+125 ºC |
|
9…12 і |
|
±0.5 ºC ( -10 +85 ºC) ±2ºC ( -55 +125 ºC) |
12- |
~750 |
|
1-Wire |
:
2 3 (VDD DO) 4,7 .
:
1-Wire®
64- ,
9 12
.
2.3
4- 7- LED .
- . , . .
, , (), . , . .
A G; - (decimalpoint, DP), .
4- :
4- 7- 12 . A-G , , decimal - , D1-D4 .
:
|
1,8 |
|
20 |
|
4 |
|
-35…+85 ºC |
2.4
ProteusDesignSuiteCADSoftware (Labcenterelectronics).
ProteusDesign - () . LabcenterElectronics ().
, , PSpice. ProteusDesign : , , DSP . Proteus , - «» . . PROTEUS VSM . Proteus , : ISIS - ARES - . .
VSM Studio, , , .
. , .
, ARES 3D- , .
(SPICE) (PICOLO, ARM-, AVR ..).
USBCONN COMPIM, USB- COM- .
ProteusDesignSuiteCADSoftware. Proteus.
. File → NewProject. , , DEFAULT, , Proteus AVR, ATmega16; AVRASM (Proteus) .
, Library → Pickpartsfromlibraries. PickDevices. DEVICES. , .
, , .
. ATMEGA, - ATMEGA16. , , , DEVICES.
DEVICES .
:
· ATMEGA16 – ATmega16
· DS18B20 –
· 7SEG-MPX4-CA –
· RES –
· OSCILLOSCOPE –
.
TerminalsMode, TERMINALS, POWER () GROUND (), .
, , . .
SelectionMode - :
Proteus.
3.
AVR . :
WinAVR- Windows, , , .
AlgorithmBuilder- AVR.
Code :: Blocks – .
Avrdude- .
AVR-Eclipse- Eclipse, / ++ , , (WinAVR, Atmel AVR Toolchain)
AtmelStudio- IDE Atmel
ArduinoIDE - Arduino AVR.
AVRStudio AtmelStudio, AtmelAVR® (Atmel).
AtmelStudio :
AVR Assembler
C / C ++
AVRAssembler.
3.1 AtmelStudio
AtmelStudio ( AVRStudio) - VisualStudio (IDE) 8- 32- AVR 32- ARM Atmel, Windows NT / 2000 / XP / Vista / 7/8/10. AtmelStudio GNU C / C ++ , .
AVR Studio, 6.0, 2012 , ARM, Atmel, AtmelStudio. (AtmelStudio 7) AVR, AVR32 ARM, Atmel.
AtmelStudio , , , C / C ++.
AVRStudio:
C / C ++;
;
GCC WinAVR;
Atmel, 8- AVR , AVR ONE !, JTAGICE mkI, JTAGICE mkII, AVR Dragon, AVRISP, AVR ISPmkII, AVR Butterfly, STK500 STK600;
AVR RTOS;
AT90PWM1 ATtiny40;
TPI.
3.2
, AtmelStudio AtmelAVR.
AtmelStudio. :
, Atmel AVR Assembler (AVR Assembler Project)
, AVRSimulator
, ATmega16
Finish
, * .ASM Project.
:
.include "m16def.inc" //
.deftemp = r16 //
.defrazr1 = r17
.defrazr2 = r18
.defrazr3 = r19
.defsys = r20
.deftry = r21
.defcount = r22
.equch0 = 0x03 // 0
.equFREQ = 8000000 //
.equW1_DDR = DDRA //
.equW1_PORT = PORTA //
.equW1_PIN = PINA //
.equW1_BIT = 0 //
.dseg //
Trm: // 2
.byte2
Visible: // 4
.byte4
Otobr: // 4
.byte4
.cseg //
.org0 // Reset
jmpReset // Reset
.org $ 012 // 0
jmpTIM0_OVF //
Reset: //
lditemp, 128
outMCUCSR, temp // JTAG, JTD MCUCSR = 1
lditemp, high (RAMEND) //
out sph, temp
lditemp, low (RAMEND)
out spl, temp
lditemp, 0xFF // DC ,
out DDRD, temp
out DDRC, temp
lditemp, 128
outMCUCSR, temp // JTAG, JTD = 1
lditemp, 0b00000010
outTCCR0, temp // , CS
lditemp, 1
outTIFR, temp // , TOV0 = 1
outTIMSK, temp
ldisys, 0b10000000 // sys
Proga_Pred:
rcallW1_Sbros //
cpir17 0 // , r17 1
breqProga_Pred // ,
rcallW1_Init_12bit // 9
sei //
Proga:
cli //
rcallW1_Sbros //
cpir17 0 // , r17 1
breqProga // ,
rcallW1_ConvTemp //
sei //
rcallDelay // ,
Proga 0:
cli //
rcallW1_Sbros //
cpir17 0
breqProga0 // ,
rcallW1_ReadMem //
sei //
lditemp, 0x00 // ,
stsOtobr + 1, temp
stsOtobr + 2, temp
stsOtobr + 3, temp
ldstemp, Trm //
sbrstemp, 7 //
rjmpProga_Plusovay // 7 , -
lditemp, 0b11111101 // Otobr G, "-"
stsOtobr, temp // 1
ldstemp, Trm // temp
anditemp, 0b00001111 // , 4
ldirazr1, 0x0F // 0x0F razr1
subrazr1, temp // 0x0F
ldstemp, Trm + 1 // temp
anditemp, 0b11110000 // , 4
ldirazr2, 0xF0 // 0xF0 razr2
subrazr2, temp // 0xF0
swaprazr2 //
incrazr2 // 1
swaprazr2 //
rcallRasch_Decimal //
rcallRasch_Otobr //
rcallOtobr_Visible//
rjmpProga // Proga
Proga_Plusovay: // , +
lditemp, 0b11111111 // Otobr "", "+"
stsOtobr, temp
ldsrazr1, Trm //
ldsrazr2, Trm + 1 //
andirazr2, 0b11110000 // , 4
//
rcallRasch_Decimal //
rcallRasch_Otobr //
rcallOtobr_Visible //
rjmpProga // Proga
Rasch_Decimal: //
swaprazr1 // razr1 ( )
swaprazr2 // razr2 ()
addrazr1, razr2 // , razr1
cpirazr1 0 // , 0
breqNULL_Temp // 0
Rasch_Decimal0:
ldiXH, High (Otobr + 3) // Otobr + 3 X
ldiXL, Low (Otobr + 3)
ldtemp, X // Otobr + 3
inctemp // 1
stX, temp // Otobr + 3
cpitemp, 10 // 10
brneRasch_Decimal1 //
lditemp 0 // = 10, Otobr + 3
stX, temp
ldtemp, -X // Otobr + 2
inctemp
stX, temp
cpitemp, 10
brneRasch_Decimal1
lditemp 0
stX, temp
ldtemp, -X
inctemp
stX, temp
Rasch_Decimal1:
decrazr1 // 1 razr1
brneRasch_Decimal0 // = 0
ret //
Rasch_Otobr: //
ldstemp, Otobr + 3 // temp Otobr + 3
rcallRasch_Otobr_Podp //
stsOtobr + 3, razr1 // Otobr + 3,
ldstemp, Otobr + 2
rcallRasch_Otobr_Podp
stsOtobr + 2, razr1
ldstemp, Otobr + 1
rcallRasch_Otobr_Podp
stsOtobr + 1, razr1ret
Rasch_Otobr_Podp: //
ldiZH, High (CH * 2) // Z
ldiZL, Low (CH * 2)
inctemp // temp 1
Rasch_Otobr_Podp0:
lpmrazr1, Z + // razr1
dectemp // temp
brneRasch_Otobr_Podp0 // temp = 0
ret // = 0, razr1
NULL_Temp: // .. Otobr 0,
ret
Otobr_Visible: // Otobr Visible
cli //
ldstemp, Otobr
stsVisible, temp
ldstemp, Otobr + 1
stsVisible + 1, temp
ldstemp, Otobr + 2
stsVisible + 2, temp
ldstemp, Otobr + 3
stsVisible + 3, temp
sei //
ret
TIM0_OVF: //
cli //
pushtemp // temp
intemp, SREG // SREG temp
pushtemp //
lsrsys //
cpisys, 0b00001000 //
brneTIM0_OVF_Vix //
ldiYH, High (Visible) // , Y
ldiYL, Low (Visible)
ldisys, 0b10000000 // 7 sys, .
TIM0_OVF_Vix:
ldtemp, Y + // Y
outPORTD, sys //
outPORTC, temp //
poptemp // SREG
outSREG, temp // SREG
poptemp // temp
sei //
reti //
//////////////////////////// 1-Wire
W1_Sbros: //
ldsr16, W1_BIT // r16
sbiW1_DDR, W1_BIT //
cbiW1_PORT, W1_BIT //
rcallW1_DelayH // 480 ,
cbiW1_DDR, W1_BIT //
rcallW1_DelayI // 70
sbisW1_PIN, W1_BIT // , 1
ldir17, 1 // 1
sbicW1_PIN, W1_BIT // , 0
ldir17 0 // 0
rcallW1_DelayJ // 410
ret // , r17 1, 0
W1_ReadMem: //
ldir16, 0xCC // 0xCC,
rcallds_byte_wr //
ldir16, 0xBE // ,
rcallds_byte_wr //
rcallds_byte_rd // , ()
stsTrm + 1, r16 // , Trm + 1
rcallds_byte_rd // ()
stsTrm, r16 // , Trm
ret
W1_ConvTemp: //
ldir16, 0xCC //
rcallds_byte_wr
ldir16, 0x44 // , 750
rcallds_byte_wr
ret
W1_Init_12bit: // 12
ldir16, 0xCC //
rcallds_byte_wr //
ldir16, 0x4E // RAM
rcallds_byte_wr //
ldir16, 0xFF // 0xFF 2 , ,
rcallds_byte_wr //
ldir16, 0xFF // 0xFF
rcallds_byte_wr //
ldir16, 0x1F // 12 - 7F, 1F - 9, 3F - 10 , 5F - 11
rcallds_byte_wr //
ret
ds_byte_rd: // r16 1 Wire
ldir17, 8 // r17 - 8, .. 8
clrr16 // r16,
ds_byte_rd_0:
sbiW1_DDR, W1_BIT //
cbiW1_PORT, W1_BIT //
rcallW1_DelayA // 6
cbiW1_DDR, W1_BIT //
rcallW1_DelayE // 9
sbisW1_PIN, W1_BIT
clc // C = 0
sbicW1_PIN, W1_BIT
sec // C = 1
rorr16 //
rcallW1_DelayF // 55
decr17 // 1 r17
brneds_byte_rd_0 // 0
ret
ds_byte_wr: // r16
ldir17, 8 // r17 - 8, .. 8
ds_byte_wr0:
sbiW1_DDR, W1_BIT //
cbiW1_PORT, W1_BIT //
sbrcr16 0 // , r16 0
rjmpds_byte_write_1 //
rjmpds_byte_write_0 //
ds_byte_wr1:
lsrr16 //
decr17 // r17 1
brneds_byte_wr0 // 0,
ret //
ds_byte_write_0: // 0
rcallW1_DelayC // 60
cbiW1_DDR, W1_BIT //
rcallW1_DelayD // 10
rjmpds_byte_wr1
ds_byte_write_1: // 1
rcallW1_DelayA // 6
cbiW1_DDR, W1_BIT //
rcallW1_DelayB // 64
rjmpds_byte_wr1
W1_DelayA: // 6 mcs
ldiXH, high (FREQ / 1000000)
ldiXL, low (FREQ / 1000000)
rcallW1_Delay
ret
W1_DelayB: // 64 mcs
ldiXH, high (FREQ / 65000)
ldiXL, low (FREQ / 65000)
rcallW1_Delay
ret
W1_DelayC: // 60 mcs
ldiXH, high (FREQ / 68000)
ldiXL, low (FREQ / 68000)
rcallW1_Delay
ret
W1_DelayD: // 10 mcs
ldiXH, high (FREQ / 500000)
ldiXL, low (FREQ / 500000)
rcallW1_Delay
ret
W1_DelayE: // 9 mcs
ldiXH, high (FREQ / 600000)
ldiXL, low (FREQ / 600000)
rcallW1_Delay
ret
W1_DelayF: // 55 mcs
ldiXH, high (FREQ / 75000)
ldiXL, low (FREQ / 75000)
rcallW1_Delay
ret
W1_DelayH: // 480 mcs
ldiXH, high (FREQ / 8332)
ldiXL, low (FREQ / 8332)
rcallW1_Delay
ret
W1_DelayI: // 70 mcs
ldiXH, high (FREQ / 58000)
ldiXL, low (FREQ / 58000)
rcallW1_Delay
ret
W1_DelayJ: // 410 mcs
ldiXH, high (FREQ / 9756)
ldiXL, low (FREQ / 9756)
rcallW1_Delay
ret
W1_Delay: //
sbiwXH: XL, 1 //
brneW1_Delay // 0
ret //
//////////////////////////// 1-Wire
Delay: //
ldirazr1, 255
ldirazr2, 255
ldirazr3, 10
Pdelay:
decrazr1
brnePdelay
decrazr2
brnePdelay
decrazr3
brnePdelay
ret
CH: // 0 9
.db0x03, 0x9F, 0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F, 0x01, 0x09
* .hex-.
4.
ProteusDesignSuiteCADSoftware.
Proteus .
ATmega16 . , ProgramFile * .hex- .
Runtimesimulation.
, -10 +85 ºC ≤ 0,5 ºC, .
DS18B20 ATmega16, , .
ProteusDesignSuiteCADSoftware, .
AtmelStudio, AVR. AVRAssembler, , C / C ++.
, , . , - .