MyTetra Share
Делитесь знаниями!
main.asm
Время создания: 11.12.2017 19:00
Раздел: Electronics - Microcontrollers - AVR8 - AVR ASM - ASM_PROJ - DS18B20 - DS18B20 v.5

.include "m8adef.inc"

;.include "m1281def.inc"


.equ HC595 = PORTB

.equ PIN_DS = 0

.equ PIN_SH = 1

.equ PIN_ST = 2

.equ PIN_MR = 7


.equ SEGM = PORTC

.equ INDICAT = PORTC

.equ INDICAT_MASK = 0xE1


.equ SENSOR_DDR = DDRD

.equ SENSOR_PORT = PORTD

.equ SENSOR_PIN = PIND

.equ SENSOR = 0

.equ SENSOR_MASK = 0x01


.include "macro.inc"


;INTERRUPT VECTORS

rjmp reset ;?????????? ?? RESET, ????????? ?? ?????????? ?????????? - initial

; rjmp 0 ;rjmp service_INT0 ;??????? ?????????? 0

; rjmp 0 ;rjmp service_INT1 ;??????? ?????????? 1

; rjmp 0 ;rjmp service_OC2 ;?????????? TCNT2 ? OCR2

; rjmp 0 ;rjmp service_OVF2 ;???????????? TCNT2

; rjmp 0 ;rjmp service_ICP1 ;?????? ? ICP1

; rjmp 0 ;rjmp service_OC1A ;?????????? TCNT1 ? OCR1A

; rjmp 0 ;rjmp service_OC1B ;?????????? TCNT1 ? OCR1B

; rjmp 0 ;rjmp service_OVF1 ;???????????? TCNT1

; rjmp 0 ;rjmp service_OVF0 ;???????????? TCNT0

; rjmp 0 ;rjmp service_SPI ;?????????? ?? ?????? SPI

; rjmp 0 ;rjmp service_URXC ;????????? ????? ?? USART

; rjmp 0 ;rjmp service_UDRE ;??????????? UDR ? USART

; rjmp 0 ;rjmp service_UTXC ;???????? ????? ?? USART

; rjmp 0 ;rjmp service_ADCC ;?????????? ?? ???

; rjmp 0 ;rjmp service_ERDY ;?????????? ?????? ? EEPROM

; rjmp 0 ;rjmp service_ACI ;?????????? ?? ???????????

; rjmp 0 ;rjmp service_TWI ;?????????? ?? ?????? TWI

; rjmp 0 ;rjmp service_SPMR ;?????????? ?????????? spm




.include "memory.asm"


.cseg

.org 0x20


;STACK INITIALISATION

reset:

ldi R16,low(RAMEND)

out SPL,R16

ldi R17,high(RAMEND)

out SPH,R17


;PERIPHERY INITIALISATION

SBI SENSOR_DDR, SENSOR

CBI SENSOR_PORT,SENSOR

LDI R16, 0x1E ; 0001.1110 for indicator

OUT DDRC, R16


;MAIN PROGRAM


// get temperature from sensor

CALL sensor_get_data

LDS R16, var_temperature

CBR R16, 7 ; clear bit of sign

CALL convert_HEX_to_DEC ; R23 - hundreds; R24 - decimals; R25 - units

LDI R21, 4 ; counter of indicator segment (1..4)


//* for test *

LDI R23, 1

LDI R24, 2

LDI R25, 3

//* for test *


mCLK_LOW ;

mLOCK_LOW ;

CALL indicator_clear_state


main:

// show temperature

CALL indicator_turn_off ; DISABLE ALL SEGMENTS


CPI R21, 4

BREQ main_indicat_segm_4

CPI R21, 3

BREQ main_indicat_segm_3

CPI R21, 2

BREQ main_indicat_segm_2


;segment #1 (MINUS SIGN)

LDS R22, var_temperature

SBRS R22, 7 ; skip next if bit 7 is set

CALL main_skip_indication ; go there if there is no sign

LDI R22, 0x40 ; sign of minus

SBI SEGM, 1

RJMP main_indicator_on


;segment #2 (HUNDREDS)

main_indicat_segm_2:

MOV R22, R23 ; take hundreds

SBI SEGM, 2

RJMP main_indicator_on


;segment #3 (DECIMALS)

main_indicat_segm_3:

MOV R22, R24 ; take decimals

SBI SEGM, 3

RJMP main_indicator_on


;segment #4 (UNITS)

main_indicat_segm_4:

MOV R22, R25 ; take units

SBI SEGM, 4


main_indicator_on:

CALL indicator_clear_state

CALL indicator_get_code

CALL indicator_send_data

mLOCK_HI

mLOCK_LOW


main_skip_indication:

DEC R21 ; --

BRNE main ; go to main if R21 != 0

LDI R21, 4 ; else R21 = 4


//------

rjmp main

#include "sensor_ds18b20.asm"

#include "indicator.asm"

#include "math.asm"


Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования