Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ToUpper_USART0.asm
- *
- * Created: 21/03/2014 15:51:30
- * Author: Administrador
- */
- .EQU restaAMinuscula = 'a'-'A' ;to be subtracted from the lowercase to get the uppercase
- .EQU Clock = 16000000 ;processor’s clock frequency, Hz
- .EQU Baud = 9600 ;desired serial port baud rate (bits per second)
- .EQU UBRRvalue = Clock/(Baud*16) -1 ;calculates value to be put in UBRR0H:L
- .DSEG
- ; Aqui las declaraciones de variables. tipo:
- caracter: .byte 1 ;esto es ejemplo, en este codigo no lo uso.
- .CSEG
- .ORG 0x00000 ;reset interrupt vector
- jmp MAIN
- .ORG URXCaddr ; 0x00024 -> interrupt vectors for USART0
- jmp USART0_reception_completed
- .ORG INT_VECTORS_SIZE ;leave room for IRQ vectors
- MAIN:
- ser r16
- out ddrb, r16
- clr r16
- out portb, r16
- ;configure USART0
- RCALL init_USART0
- SEI ;enable interrupts globally
- Loop:
- ;nothing to do here, just be alive
- NOP
- rjmp Loop
- ;------- initialize USART0 as 9600baud, asynchronous, 8 data bits, 1 stop bit, no parity -----
- init_USART0:
- PUSH R16
- LDI R16, LOW(UBRRvalue)
- STS UBRR0L, R16 ;load the low byte
- LDI R16, HIGH(UBRRvalue)
- STS UBRR0H, R16 ;load the low byte
- ; enable receive and transmit, enable USART0 interrupts (UDR empty, Tx finished, Rx finished)
- LDI R16, (1<<RXEN0)|(1<< TXEN0)|(0<<UDRIE0)|(0<< TXCIE0)|(1<< RXCIE0)
- STS UCSR0B, R16 ;set control register UCSR0B with the corresponding bits
- ; configure USART 0 as asynchronous, set frame format: 8 data bits, 1 stop bit, no parity
- LDI R16, (0<<UMSEL00) |(1<<UCSZ01)|(1<< UCSZ00) |(0<< USBS0)|(0<<UPM01)|(0<< UPM00)
- STS UCSR0C, R16 ;set control register UCSR0C with the corresponding bits
- POP R16
- RET
- ;----USART0_reception_completed handler --------------------------------------------------
- USART0_reception_completed:
- PUSH R16 ;this handler routine will be automatically called every 61msec (in this example)
- IN R16, SREG ;Backup SREG. MANDATORY in interrupt handler routines
- PUSH R16
- ;do the desired periodic task here
- LDS R16, UDR0 ;pick up the byte received and do anything with it
- push r16 ; r16 = pasaMayusculas(R16)
- call pasaMayusculas
- pop r16
- STS UDR0, R16
- POP R16
- OUT SREG, R16 ;Recover SREG from the previous backup
- POP R16
- RETI ;RETI is MANDATORY when returning from an interrupt handling routine
- ;=======================================================================
- pasaMayusculas:
- ;------------------------- Siempre igual
- push yh
- push yl
- in yh, sph
- in yl, spl
- ;punto2
- ;------------------------- Casi siempre ugual
- push r16
- ldd r16, y+5 ;el primer parametro es SIEMPRE y+5, el segundo y+6, etc.
- ;=========================
- ;if(r16 < 'a)
- cpi r16, 'a'
- brlo sataConversion
- ;if(r16 > 'z') => if(r16 >= 'z'+1)
- cpi r16, 'z'+1 ;cpi r16, 122+1 -> cpi r16, 123
- brsh sataConversion
- ;Codigo para pasar a minúsculas.
- subi r16, restaAMinuscula
- std y+5, r16
- ;Punto 3
- sataConversion:
- ;=========================
- pop r16
- ;punto 4
- ;-------------------------
- pop yl
- pop yh
- ;-------------------------
- ret
- .EXIT
Advertisement