AVR Control: Full Serial Config

STATO: DISCONNESSO ❌

Codice ASM con UCSR0C (8N1)

Configurazione binaria per UCSR0C: 0b00000110


.org 0x0000
    jmp RESET

.org 0x0024        ; USART RX Complete Interrupt
    jmp costycnc
    
.org 0x0060
RESET:
    sbi 0x04, 5    ; DDRB: PB5 come uscita
    
    ; 1. Configura Baud Rate 9600 (per 16MHz)
    ldi r16, 103
    sts 0xC4, r16  ; UBRR0L
    
    ; 2. Configura UCSR0C: 8 bit, 1 stop, no parity
    ldi r16, 0b00000110 ; Bit 2 e 1 impostati (UCSZ01 e UCSZ00)
    sts 0xC2, r16      ; Scrivi in UCSR0C

    ; 3. Abilita Ricezione e Interrupt RX
    ldi r16, 0b10010000 
    sts 0xC1, r16      ; UCSR0B
    sei                ; Abilita interruzioni

loop:
    rjmp loop

costycnc:
    cbi 0x05, 5    ; Spegne LED (default)
    lds r18, 0xC6  ; Leggi UDR0
    cpi r18, 'A'   ; È una 'A'?
    brne jos
    sbi 0x05, 5    ; Accendi se è 'A'
jos:
    reti