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

#ifndef INDICATOR_ASM

#define INDICATOR_ASM


//-------------------------------------------------------

/*

#define SEGM_DDR DDRC

#define SEGM PORTC //PC1..PC4 - 1..4 segment cathodes

#define CATHODE_MASK 0xE1 //1110.0001 - mask for turning off pins [1..4]

#define SEC_DOTS 0x80 //'mask' for switching on central dots on indicator panel

#define SEGM1_ON SEGM |= (1<<1) //PORTC 1

#define SEGM2_ON SEGM |= (1<<2) //PORTC 2

#define SEGM3_ON SEGM |= (1<<3) //PORTC 3

#define SEGM4_ON SEGM |= (1<<4) //PORTC 4

#define SEGM_OFF SEGM &= CATHODE_MASK

//#define SEGM_DDR_OFF SEGM_DDR &= CATHODE_MASK


#define HC595 PORTB

#define DS 0 //data

#define ST 2 //locking

#define SH 1 //clock

#define DATA_HI HC595 |= (1<<DS)

#define DATA_LOW HC595 &= ~(1<<DS)

#define CLK_HI HC595 |= (1<<SH)

#define CLK_LOW HC595 &= ~(1<<SH)

#define LOCK_HI HC595 |= (1<<ST)

#define LOCK_LOW HC595 &= ~(1<<ST)

#define CLEAR_OFF PORTD |= (1<<MR)

#define CLEAR_ON PORTD &= ~(1<<MR)

*/

//-------------------------------------------------------


// IN: R22

indicator_send_data:

PUSH R16


LDI R16, 8


send_data_loop:

mDATA_LOW

mCLK_LOW

SBRC R22, 0 ; skip next if bit 0 is set

mDATA_HI

mCLK_HI


LSR R22 ; right shift for correct SBRC R22,0

DEC R16 ; dec counter

BRNE send_data_loop ; while counter > 0 do loop


mCLK_LOW

mDATA_LOW

POP R16

RET


/*

//for indicator with common cathode

//D0..D7 == A,B,C,D,F,G,DP

#define DIG1 0x06;

#define DIG2 0x5B;

#define DIG3 0x4F;

#define DIG4 0x66;

#define DIG5 0x6D;

#define DIG6 0x7D;

#define DIG7 0x07;

#define DIG8 0x7F;

#define DIG9 0x6F;

#define DIG0 0x3F;

IN: R22 - digit in DEC

OUT: R22 - code for indicator

*/

indicator_get_code:

CPI R22, 0

BREQ get_code_0

CPI R22, 1

BREQ get_code_1

CPI R22, 2

BREQ get_code_2

CPI R22, 3

BREQ get_code_3

CPI R22, 4

BREQ get_code_4

CPI R22, 5

BREQ get_code_5

CPI R22, 6

BREQ get_code_6

CPI R22, 7

BREQ get_code_7

CPI R22, 8

BREQ get_code_8

CPI R22, 9

BREQ get_code_9


get_code_0:

LDI R22, 0x3F

RET

get_code_1:

LDI R22, 0x06

RET

get_code_2:

LDI R22, 0x5B

RET

get_code_3:

LDI R22, 0x4F

RET

get_code_4:

LDI R22, 0x66

RET

get_code_5:

LDI R22, 0x6D

RET

get_code_6:

LDI R22, 0x7D

RET

get_code_7:

LDI R22, 0x07

RET

get_code_8:

LDI R22, 0x7F

RET

get_code_9:

LDI R22, 0x6F

RET


indicator_clear_state:

mCLEAR_ON ;

mLOCK_HI ;

mCLEAR_OFF ;

mLOCK_LOW ;

RET


indicator_turn_off:

PUSH R16

IN R16, INDICAT

ANDI R16, INDICAT_MASK

OUT INDICAT, R16

POP R16

RET


#endif


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