Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Only testing purposes!!!
- * It's tested on ATmega16A with 16MHz external crystal.
- * Serial channel connected to PC (Linux minicom) using MAX3232 converter IC.
- * Outputs always "Z" 0x5A, but after receive some characters (5 - 20) from PC it's stuck.
- * Really strange phenomen.
- */
- /* *********************************************************************
- * avr-uart.h
- * AVR uart handler for ATmega16
- * Common definitions
- * by tovis 2015
- **********************************************************************/
- #ifndef AVR_UART
- #define AVR_UART
- #endif
- #ifndef AVR_UART_ASM
- //---------------------------------------------------------------------
- void uart_put(void);
- void uart_get(void);
- void uart_setup(void);
- //---------------------------------------------------------------------
- // Helper routines
- extern void toggle_A0(void);
- extern void toggle_A1(void);
- extern void toggle_A2(void);
- extern void toggle_A7(void);
- #endif
- /* *********************************************************************
- * end avr-uart.h
- **********************************************************************/
- /* *********************************************************************
- * avr-uart-test.c
- * AVR uart handler for ATmega16
- * Test main program
- * by tovis 2015
- **********************************************************************/
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "avr-uart.h"
- //----------------------------------------------------------------------
- #define F_CPU 16000000UL // ATmega16A with external crystal 16MHz
- //**********************************************************************
- void main(void)
- {
- DDRA = 0xFF; // whole PORTA set as output
- uart_setup();
- sei();
- while ( 1 )
- {
- uart_put();
- uart_get();
- toggle_A0(); // ???
- }
- } // end main
- /* ********************************************************************
- * end avr-uart-test.c
- **********************************************************************/
- /* *********************************************************************
- * avr-uart-isr.S
- * AVR uart handler for ATmega16
- * ISR routine and helper utilities
- * by tovis 2015
- **********************************************************************/
- #define AVR_UART_ASM
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "avr-uart.h"
- //**********************************************************************
- .global BADISR_vect
- BADISR_vect:
- CALL toggle_A7
- RJMP BADISR_vect
- //**********************************************************************
- //----------------------------------------------------------------------
- .global uart_get
- uart_get:
- SBIS _SFR_IO_ADDR(UCSRA),RXC //; check if received data available
- RJMP uart_get_notready
- CALL toggle_A2 //; ???
- PUSH R16
- IN R16, _SFR_IO_ADDR(UDR) //; read data from receiver buffer
- POP R16
- uart_get_notready:
- RET
- //----------------------------------------------------------------------
- .global uart_put
- uart_put:
- SBIS _SFR_IO_ADDR(UCSRA), UDRE //; check if UDR is empty
- RJMP uart_put_notready
- CALL toggle_A1 //; ???
- PUSH R16
- //; LDI R16, 'o'
- IN R16, _SFR_IO_ADDR(SPL)
- OUT _SFR_IO_ADDR(UDR), R16
- POP R16
- uart_put_notready:
- RET
- //----------------------------------------------------------------------
- .global uart_setup
- uart_setup:
- PUSH R16
- EOR R16, R16 //; Clear R16
- OUT _SFR_IO_ADDR(UCSRB), R16 //; Disable USART interrupts
- //; Disable receive/transmit
- //; and UCSZ2 = 0 for 8 bit data
- LDI R16, lo8(103) //; Setup Baud rate 9600
- OUT _SFR_IO_ADDR(UBRRL), R16
- LDI R16, hi8(103)
- ANDI R16, 0x7F //; URSEL = 0 - access UBRRH
- OUT _SFR_IO_ADDR(UBRRH), R16
- OUT _SFR_IO_ADDR(UCSRA), R16 //; Clrear status and U2X, MPCM
- LDI R16, 0b10000110 //; Asynchronous 8n1
- OUT _SFR_IO_ADDR(UCSRC), R16 //; Set ssynchronous 8n1
- //---
- SBI _SFR_IO_ADDR(UCSRB), TXEN //; Transmitter enable
- SBI _SFR_IO_ADDR(UCSRB), RXEN //; Receiver enable
- POP R16
- RET
- //**********************************************************************
- .global toggle_A0
- toggle_A0:
- SBIC _SFR_IO_ADDR(PINA), 0
- CBI _SFR_IO_ADDR(PORTA), 0
- SBIS _SFR_IO_ADDR(PINA), 0
- SBI _SFR_IO_ADDR(PORTA), 0
- RET
- //----------------------------------------------------------------------
- .global toggle_A1
- toggle_A1:
- SBIC _SFR_IO_ADDR(PINA), 1
- CBI _SFR_IO_ADDR(PORTA), 1
- SBIS _SFR_IO_ADDR(PINA), 1
- SBI _SFR_IO_ADDR(PORTA), 1
- RET
- //----------------------------------------------------------------------
- .global toggle_A2
- toggle_A2:
- SBIC _SFR_IO_ADDR(PINA), 2
- CBI _SFR_IO_ADDR(PORTA), 2
- SBIS _SFR_IO_ADDR(PINA), 2
- SBI _SFR_IO_ADDR(PORTA), 2
- RET
- //----------------------------------------------------------------------
- .global toggle_A7
- toggle_A7:
- SBIC _SFR_IO_ADDR(PINA), 7
- CBI _SFR_IO_ADDR(PORTA), 7
- SBIS _SFR_IO_ADDR(PINA), 7
- SBI _SFR_IO_ADDR(PORTA), 7
- RET
- /***********************************************************************
- * end avr-uart-isr.S
- **********************************************************************/
- avr-uart-test.elf: file format elf32-avr
- Sections:
- Idx Name Size VMA LMA File off Algn
- 0 .text 000000f6 00000000 00000000 00000054 2**1
- CONTENTS, ALLOC, LOAD, READONLY, CODE
- 1 .stab 00000cc0 00000000 00000000 0000014c 2**2
- CONTENTS, READONLY, DEBUGGING
- 2 .stabstr 000007a2 00000000 00000000 00000e0c 2**0
- CONTENTS, READONLY, DEBUGGING
- 3 .comment 00000011 00000000 00000000 000015ae 2**0
- CONTENTS, READONLY
- Disassembly of section .text:
- 00000000 <__vectors>:
- 0: 0c 94 2a 00 jmp 0x54 ; 0x54 <__ctors_end>
- 4: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 8: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- c: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 10: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 14: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 18: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 1c: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 20: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 24: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 28: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 2c: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 30: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 34: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 38: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 3c: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 40: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 44: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 48: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 4c: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 50: 0c 94 34 00 jmp 0x68 ; 0x68 <__bad_interrupt>
- 00000054 <__ctors_end>:
- 54: 11 24 eor r1, r1
- 56: 1f be out 0x3f, r1 ; 63
- 58: cf e5 ldi r28, 0x5F ; 95
- 5a: d4 e0 ldi r29, 0x04 ; 4
- 5c: de bf out 0x3e, r29 ; 62
- 5e: cd bf out 0x3d, r28 ; 61
- 60: 0e 94 6d 00 call 0xda ; 0xda <main>
- 64: 0c 94 79 00 jmp 0xf2 ; 0xf2 <_exit>
- 00000068 <__bad_interrupt>:
- 68: 0c 94 36 00 jmp 0x6c ; 0x6c <__vector_default>
- 0000006c <__vector_default>:
- 6c: 0e 94 68 00 call 0xd0 ; 0xd0 <toggle_A7>
- 70: fd cf rjmp .-6 ; 0x6c <__vector_default>
- 00000072 <uart_get>:
- 72: 5f 9b sbis 0x0b, 7 ; 11
- 74: 05 c0 rjmp .+10 ; 0x80 <uart_get_notready>
- 76: 0e 94 63 00 call 0xc6 ; 0xc6 <toggle_A2>
- 7a: 0f 93 push r16
- 7c: 0c b1 in r16, 0x0c ; 12
- 7e: 0f 91 pop r16
- 00000080 <uart_get_notready>:
- 80: 08 95 ret
- 00000082 <uart_put>:
- 82: 5d 9b sbis 0x0b, 5 ; 11
- 84: 06 c0 rjmp .+12 ; 0x92 <uart_put_notready>
- 86: 0e 94 5e 00 call 0xbc ; 0xbc <toggle_A1>
- 8a: 0f 93 push r16
- 8c: 0d b7 in r16, 0x3d ; 61
- 8e: 0c b9 out 0x0c, r16 ; 12
- 90: 0f 91 pop r16
- 00000092 <uart_put_notready>:
- 92: 08 95 ret
- 00000094 <uart_setup>:
- 94: 0f 93 push r16
- 96: 00 27 eor r16, r16
- 98: 0a b9 out 0x0a, r16 ; 10
- 9a: 07 e6 ldi r16, 0x67 ; 103
- 9c: 09 b9 out 0x09, r16 ; 9
- 9e: 00 e0 ldi r16, 0x00 ; 0
- a0: 0f 77 andi r16, 0x7F ; 127
- a2: 00 bd out 0x20, r16 ; 32
- a4: 0b b9 out 0x0b, r16 ; 11
- a6: 06 e8 ldi r16, 0x86 ; 134
- a8: 00 bd out 0x20, r16 ; 32
- aa: 53 9a sbi 0x0a, 3 ; 10
- ac: 54 9a sbi 0x0a, 4 ; 10
- ae: 0f 91 pop r16
- b0: 08 95 ret
- 000000b2 <toggle_A0>:
- b2: c8 99 sbic 0x19, 0 ; 25
- b4: d8 98 cbi 0x1b, 0 ; 27
- b6: c8 9b sbis 0x19, 0 ; 25
- b8: d8 9a sbi 0x1b, 0 ; 27
- ba: 08 95 ret
- 000000bc <toggle_A1>:
- bc: c9 99 sbic 0x19, 1 ; 25
- be: d9 98 cbi 0x1b, 1 ; 27
- c0: c9 9b sbis 0x19, 1 ; 25
- c2: d9 9a sbi 0x1b, 1 ; 27
- c4: 08 95 ret
- 000000c6 <toggle_A2>:
- c6: ca 99 sbic 0x19, 2 ; 25
- c8: da 98 cbi 0x1b, 2 ; 27
- ca: ca 9b sbis 0x19, 2 ; 25
- cc: da 9a sbi 0x1b, 2 ; 27
- ce: 08 95 ret
- 000000d0 <toggle_A7>:
- d0: cf 99 sbic 0x19, 7 ; 25
- d2: df 98 cbi 0x1b, 7 ; 27
- d4: cf 9b sbis 0x19, 7 ; 25
- d6: df 9a sbi 0x1b, 7 ; 27
- d8: 08 95 ret
- 000000da <main>:
- #define F_CPU 16000000UL // ATmega16A with external crystal 16MHz
- //**********************************************************************
- void main(void)
- {
- DDRA = 0xFF; // whole PORTA set as output
- da: 8f ef ldi r24, 0xFF ; 255
- dc: 8a bb out 0x1a, r24 ; 26
- uart_setup();
- de: 0e 94 4a 00 call 0x94 ; 0x94 <uart_setup>
- sei();
- e2: 78 94 sei
- while ( 1 )
- {
- uart_put();
- e4: 0e 94 41 00 call 0x82 ; 0x82 <uart_put>
- uart_get();
- e8: 0e 94 39 00 call 0x72 ; 0x72 <uart_get>
- toggle_A0(); // ???
- ec: 0e 94 59 00 call 0xb2 ; 0xb2 <toggle_A0>
- f0: f9 cf rjmp .-14 ; 0xe4 <main+0xa>
- 000000f2 <_exit>:
- f2: f8 94 cli
- 000000f4 <__stop_program>:
- f4: ff cf rjmp .-2 ; 0xf4 <__stop_program>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement