Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Created June 4, 2025 10:18
Show Gist options
  • Save yetimdasturchi/718d2b692fb9fce4025d9dd2386dbbee to your computer and use it in GitHub Desktop.
Save yetimdasturchi/718d2b692fb9fce4025d9dd2386dbbee to your computer and use it in GitHub Desktop.
example_avr.asm
; ===== Registerlarni belgilash =====
.equ DDRD = 0x2A
.equ DDRB = 0x24
.equ PORTB = 0x25
.equ PIND = 0x29
; ===== Asosiy dastur =====
.org 0x0000 ; Dasturning boshlang‘ich nuqtasi
rjmp RESET ; Portlarni sozlash uchn reset sektoriga o‘tish
RESET:
; 1. Kirish va chiqish portlarini sozlash
ldi r16, 0b00000000 ; PD2, PD3 kirish (boshqa bitlar ham 0)
out DDRD, r16
ldi r16, 0b00000011 ; PB0 va PB1 chiqish
out DDRB, r16
MAIN_LOOP:
; 2. Kirish holatini o‘qish
in r17, PIND ; PD2 = bit2, PD3 = bit3
; 3. Faqat PD2 va PD3 ni izolyatsiya qilish (bit mask)
andi r17, 0b00001100 ; faqat 3-chi va 2-chi bitlar
; 4. Chiqish qiymatini tayyorlash
clr r18 ; r18 = 0 → chiqish portga yuboriladi
; Agar PD2 (bit 2) = 1 bo‘lsa → PB0 = 1
sbrc r17, 2 ; tozalangan bitni o‘tkazish yuborish
ori r18, 0b00000001 ; PB0 = 1
; Agar PD3 (bit 3) = 1 bo‘lsa → PB1 = 1
sbrc r17, 3
ori r18, 0b00000010 ; PB1 = 1
; 5. PORTB ga natijani yuborish
out PORTB, r18
rjmp MAIN_LOOP ; takrorlash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment