Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; ToUpper_USART.asm
- ;
- ; Created: 24/04/2018 13:29:04
- ; Author : 1418
- ;
- ;*********************************************************************************************
- ;******************** Const Definitions, Precompiler sentences ******************************
- ;*********************************************************************************************
- .EQU lowercase_a = 97 ;ASCII for 'a'
- .EQU lowercase_z = 122 ;ASCII for 'z'
- .EQU TOUPPER = 32 ;to be subtracted from the lowercase to get the uppercase
- .EQU minus = 45 ;Letra guion "-"
- .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
- ;*********************************************************************************************
- ;******************** Main VARs **************************************************************
- ;*********************************************************************************************
- .DSEG
- ;*********************************************************************************************
- ;******************** Main Program ***********************************************************
- ;*********************************************************************************************
- .CSEG
- .ORG 0x00000 ;reset interrupt vector
- jmp Init
- .ORG 0x00032 ;interrupt vectors for USART0
- jmp USART0_reception_completed
- reti
- reti
- .ORG 0x00100 ;leave room for IRQ vectors
- Init:
- ;configure USART0
- RCALL init_USART0
- rcall InitBPort
- SEI ;enable interrupts globally
- clr r16
- Loop:
- out portb, r16
- rcall delay500ms
- com r16
- rjmp Loop
- ;*********************************************************************************************
- ;**************** End Main Program ***********************************************************
- ;*********************************************************************************************
- ;------- initialize USART0 as 9600baud, asynchronous, 8 data bits, 1 stop bit, no parity -----
- ;Especificaciones: https://appelsiini.net/2011/simple-usart-with-avr-libc/#registers
- ; http://microcontroladores-mrelberni.com/interrupcion-usart-avr/
- 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<<RXCIE0)
- 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
- CPI r16,lowercase_a ;'a'
- BRLT NotConvert ;not a lowercase letter
- CPI r16,lowercase_z+1 ;'z'+1
- BRGE NotConvert ;not an lowercase letter
- SUBI r16, TOUPPER ;change to Uppercase
- STS UDR0, r16 ;transmits the [modified] byte
- JMP USART0_reception_cont
- ; Non conver. not lowercase letter. send "-" character
- NotConvert:
- ;LDI r16, minus
- STS UDR0, r16 ;transmits the [modified] byte
- USART0_reception_cont:
- POP r16
- OUT SREG, r16 ;Recover SREG from the previous backup
- POP r16
- RETI ;RETI is MANDATORY when returning from an interrupt handling routine
- ;Funcion inicializar puerto B como salida
- InitBPort:
- push r31
- LDI r31, 0xff
- OUT DDRB, r31
- pop r31
- ret
- ; Delay 3 200 000 cycles
- ; 200ms at 16 MHz
- delay500ms:
- push r18
- push r19
- push r20
- ldi r18, 41
- ldi r19, 150
- ldi r20, 128
- L1: dec r20
- brne L1
- dec r19
- brne L1
- dec r18
- brne L1
- pop r20
- pop r19
- pop r18
- ret
- .EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement